summaryrefslogtreecommitdiff
path: root/nova/tests/unit/test_rpc.py
diff options
context:
space:
mode:
authorDina Belova <dbelova@mirantis.com>2015-12-08 14:32:10 +0300
committerTovin Seven <vinhnt@vn.fujitsu.com>2017-01-18 15:00:14 +0700
commitecc8de8d6cccb06d7f4c8ecc144d37612ae1e9cc (patch)
tree03345e2b6d7afd801b78aab134473698fdf8fa1d /nova/tests/unit/test_rpc.py
parent045f08ab8a57b90b00e4777ca71a20b5603c296c (diff)
downloadnova-ecc8de8d6cccb06d7f4c8ecc144d37612ae1e9cc.tar.gz
Integrate OSProfiler and Nova
* Add osprofiler wsgi middleware. This middleware is used for 2 things: 1) It checks that person who want to trace is trusted and knows secret HMAC key. 2) It starts tracing in case of proper trace headers and adds the first wsgi trace point with info about the HTTP request * Add initialization of osprofiler on start of a service Currently that includes oslo.messaging notifier instance creation to send Ceilometer backend notifications. oslo-spec: https://review.openstack.org/#/c/103825/ python-novaclient change: https://review.openstack.org/#/c/254699/ based on: https://review.openstack.org/#/c/105096/ Co-Authored-By: Boris Pavlovic <boris@pavlovic.me> Co-Authored-By: Munoz, Obed N <obed.n.munoz@intel.com> Co-Authored-By: Roman Podoliaka <rpodolyaka@mirantis.com> Co-Authored-By: Tovin Seven <vinhnt@vn.fujitsu.com> Implements: blueprint osprofiler-support-in-nova Change-Id: I82d2badc8c1fcec27c3fce7c3c20e0f3b76414f1
Diffstat (limited to 'nova/tests/unit/test_rpc.py')
-rw-r--r--nova/tests/unit/test_rpc.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/nova/tests/unit/test_rpc.py b/nova/tests/unit/test_rpc.py
index c71551193f..3f50efec21 100644
--- a/nova/tests/unit/test_rpc.py
+++ b/nova/tests/unit/test_rpc.py
@@ -182,6 +182,7 @@ class TestRPC(testtools.TestCase):
mock_url.parse.assert_called_once_with(conf, None,
rpc.TRANSPORT_ALIASES)
+ @mock.patch.object(rpc, 'profiler', None)
@mock.patch.object(rpc, 'RequestContextSerializer')
@mock.patch.object(messaging, 'RPCClient')
def test_get_client(self, mock_client, mock_ser):
@@ -199,6 +200,7 @@ class TestRPC(testtools.TestCase):
serializer=ser)
self.assertEqual('client', client)
+ @mock.patch.object(rpc, 'profiler', None)
@mock.patch.object(rpc, 'RequestContextSerializer')
@mock.patch.object(messaging, 'get_rpc_server')
def test_get_server(self, mock_get, mock_ser):
@@ -216,6 +218,42 @@ class TestRPC(testtools.TestCase):
executor='eventlet', serializer=ser)
self.assertEqual('server', server)
+ @mock.patch.object(rpc, 'profiler', mock.Mock())
+ @mock.patch.object(rpc, 'ProfilerRequestContextSerializer')
+ @mock.patch.object(messaging, 'RPCClient')
+ def test_get_client_profiler_enabled(self, mock_client, mock_ser):
+ rpc.TRANSPORT = mock.Mock()
+ tgt = mock.Mock()
+ ser = mock.Mock()
+ mock_client.return_value = 'client'
+ mock_ser.return_value = ser
+
+ client = rpc.get_client(tgt, version_cap='1.0', serializer='foo')
+
+ mock_ser.assert_called_once_with('foo')
+ mock_client.assert_called_once_with(rpc.TRANSPORT,
+ tgt, version_cap='1.0',
+ serializer=ser)
+ self.assertEqual('client', client)
+
+ @mock.patch.object(rpc, 'profiler', mock.Mock())
+ @mock.patch.object(rpc, 'ProfilerRequestContextSerializer')
+ @mock.patch.object(messaging, 'get_rpc_server')
+ def test_get_server_profiler_enabled(self, mock_get, mock_ser):
+ rpc.TRANSPORT = mock.Mock()
+ ser = mock.Mock()
+ tgt = mock.Mock()
+ ends = mock.Mock()
+ mock_ser.return_value = ser
+ mock_get.return_value = 'server'
+
+ server = rpc.get_server(tgt, ends, serializer='foo')
+
+ mock_ser.assert_called_once_with('foo')
+ mock_get.assert_called_once_with(rpc.TRANSPORT, tgt, ends,
+ executor='eventlet', serializer=ser)
+ self.assertEqual('server', server)
+
def test_get_notifier(self):
rpc.LEGACY_NOTIFIER = mock.Mock()
mock_prep = mock.Mock()
@@ -364,6 +402,43 @@ class TestRequestContextSerializer(test.NoDBTestCase):
mock_req.from_dict.assert_called_once_with('context')
+class TestProfilerRequestContextSerializer(test.NoDBTestCase):
+ def setUp(self):
+ super(TestProfilerRequestContextSerializer, self).setUp()
+ self.ser = rpc.ProfilerRequestContextSerializer(mock.Mock())
+
+ @mock.patch('nova.rpc.profiler')
+ def test_serialize_context(self, mock_profiler):
+ prof = mock_profiler.get.return_value
+ prof.hmac_key = 'swordfish'
+ prof.get_base_id.return_value = 'baseid'
+ prof.get_id.return_value = 'parentid'
+
+ context = mock.Mock()
+ context.to_dict.return_value = {'project_id': 'test'}
+
+ self.assertEqual({'project_id': 'test',
+ 'trace_info': {
+ 'hmac_key': 'swordfish',
+ 'base_id': 'baseid',
+ 'parent_id': 'parentid'}},
+ self.ser.serialize_context(context))
+
+ @mock.patch('nova.rpc.profiler')
+ def test_deserialize_context(self, mock_profiler):
+ serialized = {'project_id': 'test',
+ 'trace_info': {
+ 'hmac_key': 'swordfish',
+ 'base_id': 'baseid',
+ 'parent_id': 'parentid'}}
+
+ context = self.ser.deserialize_context(serialized)
+
+ self.assertEqual('test', context.project_id)
+ mock_profiler.init.assert_called_once_with(
+ hmac_key='swordfish', base_id='baseid', parent_id='parentid')
+
+
class TestClientRouter(test.NoDBTestCase):
@mock.patch('nova.objects.InstanceMapping.get_by_instance_uuid')
@mock.patch('nova.rpc.create_transport')