From 72800e6b22cbdbbfb0c0cf3381075d2325021e3c Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 8 Jun 2017 07:26:25 -0400 Subject: [PATCH] Send global_request_id to nova/glance when calls are made This makes cinder add the global_request_id to the constructors for nova and glance clients, which will pass the global_request_id into those services on all API calls. Adjust unit tests when needed to support the new parameter. oslo spec I65de8261746b25d45e105394f4eeb95b9cb3bd42 (requirements bump) Depends-On: I5b247f75edeea9da50fe524eadf5f9a2c626d665 Change-Id: I6366ca6bd8286858093b76579571b35b062f97d7 --- cinder/compute/nova.py | 1 + cinder/image/glance.py | 1 + cinder/tests/unit/compute/test_nova.py | 5 +++++ cinder/tests/unit/image/test_glance.py | 13 ++++++++----- requirements.txt | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cinder/compute/nova.py b/cinder/compute/nova.py index 20ac576db17..959be43eb49 100644 --- a/cinder/compute/nova.py +++ b/cinder/compute/nova.py @@ -155,6 +155,7 @@ def novaclient(context, privileged_user=False, timeout=None): region_name=CONF[NOVA_GROUP].region_name, endpoint_type=CONF[NOVA_GROUP].interface, cacert=CONF[NOVA_GROUP].cafile, + global_request_id=context.global_id, extensions=nova_extensions) return c diff --git a/cinder/image/glance.py b/cinder/image/glance.py index 88ccb8aacf9..ee4b2cc2ace 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -100,6 +100,7 @@ def _create_glance_client(context, netloc, use_ssl, version=None): if CONF.glance_request_timeout is not None: params['timeout'] = CONF.glance_request_timeout endpoint = '%s://%s' % (scheme, netloc) + params['global_request_id'] = context.global_id return glanceclient.Client(str(version), endpoint, **params) diff --git a/cinder/tests/unit/compute/test_nova.py b/cinder/tests/unit/compute/test_nova.py index 5ed1f8c2bc7..99595348afe 100644 --- a/cinder/tests/unit/compute/test_nova.py +++ b/cinder/tests/unit/compute/test_nova.py @@ -78,6 +78,7 @@ class NovaClientTestCase(test.TestCase): p_api_version(nova.NOVA_API_VERSION), session=p_session.return_value, region_name=None, insecure=False, endpoint_type='public', cacert='my.ca', + global_request_id=self.ctx.request_id, timeout=None, extensions=nova.nova_extensions) @mock.patch('novaclient.api_versions.APIVersion') @@ -97,6 +98,7 @@ class NovaClientTestCase(test.TestCase): p_api_version(nova.NOVA_API_VERSION), session=p_session.return_value, region_name=None, insecure=False, endpoint_type='public', cacert='my.ca', + global_request_id=self.ctx.request_id, timeout=None, extensions=nova.nova_extensions) @mock.patch('novaclient.api_versions.APIVersion') @@ -119,6 +121,7 @@ class NovaClientTestCase(test.TestCase): p_api_version(nova.NOVA_API_VERSION), session=p_session.return_value, region_name=None, insecure=False, endpoint_type='public', cacert='my.ca', + global_request_id=self.ctx.request_id, timeout=None, extensions=nova.nova_extensions) @mock.patch('novaclient.api_versions.APIVersion') @@ -146,6 +149,7 @@ class NovaClientTestCase(test.TestCase): p_api_version(nova.NOVA_API_VERSION), session=p_session.return_value, region_name=None, insecure=False, endpoint_type='public', cacert='my.ca', + global_request_id=self.ctx.request_id, timeout=None, extensions=nova.nova_extensions) @mock.patch('novaclient.api_versions.APIVersion') @@ -169,6 +173,7 @@ class NovaClientTestCase(test.TestCase): p_api_version(nova.NOVA_API_VERSION), session=p_session.return_value, region_name='farfaraway', insecure=False, endpoint_type='public', cacert='my.ca', + global_request_id=self.ctx.request_id, timeout=None, extensions=nova.nova_extensions) def test_novaclient_exceptions(self): diff --git a/cinder/tests/unit/image/test_glance.py b/cinder/tests/unit/image/test_glance.py index a6ca74cd782..0724450a659 100644 --- a/cinder/tests/unit/image/test_glance.py +++ b/cinder/tests/unit/image/test_glance.py @@ -843,19 +843,21 @@ class TestGlanceClientVersion(test.TestCase): @mock.patch('cinder.image.glance.glanceclient.Client') def test_glance_version_by_flag(self, _mockglanceclient): """Test glance version set by flag is honoured.""" - glance.GlanceClientWrapper('fake', 'fake_host', 9292) + ctx = mock.MagicMock() + glance.GlanceClientWrapper(ctx, 'fake_host', 9292) self.assertEqual('2', _mockglanceclient.call_args[0][0]) self.flags(glance_api_version=1) - glance.GlanceClientWrapper('fake', 'fake_host', 9292) + glance.GlanceClientWrapper(ctx, 'fake_host', 9292) self.assertEqual('1', _mockglanceclient.call_args[0][0]) CONF.reset() @mock.patch('cinder.image.glance.glanceclient.Client') def test_glance_version_by_arg(self, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" - glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=1) + ctx = mock.MagicMock() + glance.GlanceClientWrapper(ctx, 'fake_host', 9292, version=1) self.assertEqual('1', _mockglanceclient.call_args[0][0]) - glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=2) + glance.GlanceClientWrapper(ctx, 'fake_host', 9292, version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0]) @mock.patch('cinder.image.glance.glanceclient.Client') @@ -864,7 +866,8 @@ class TestGlanceClientVersion(test.TestCase): def test_call_glance_version_by_arg(self, api_servers, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" glance_wrapper = glance.GlanceClientWrapper() - glance_wrapper.call('fake_context', 'method', version=2) + ctx = mock.MagicMock() + glance_wrapper.call(ctx, 'method', version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0]) diff --git a/requirements.txt b/requirements.txt index 683c6262236..620495b5853 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,7 +39,7 @@ pyparsing>=2.1.0 # MIT python-barbicanclient>=4.0.0 # Apache-2.0 python-glanceclient>=2.7.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 -python-novaclient>=7.1.0 # Apache-2.0 +python-novaclient>=9.0.0 # Apache-2.0 python-swiftclient>=3.2.0 # Apache-2.0 pytz>=2013.6 # MIT requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0