From 486da4305d607b32b03709c6b0f26430776a37cf Mon Sep 17 00:00:00 2001 From: Anton Arefiev Date: Wed, 1 Apr 2015 19:14:26 +0300 Subject: [PATCH] Fix always false condition in glance wrapper If statement's condition in GlanceClientWrapper's method 'call' always false, because 'version' key passed through kwargs is string, and variable chacked in 'call' is None or int. Change-Id: Ief1e8d2c41aaa774666bc59d63cdea68f80f308a Closes-Bug: #1439275 --- cinder/image/glance.py | 5 ++--- cinder/tests/image/test_glance.py | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cinder/image/glance.py b/cinder/image/glance.py index 5b9c85ed1..3c1edb47f 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -74,8 +74,7 @@ def _parse_image_ref(image_href): return (image_id, netloc, use_ssl) -def _create_glance_client(context, netloc, use_ssl, - version=CONF.glance_api_version): +def _create_glance_client(context, netloc, use_ssl, version=None): """Instantiate a new glanceclient.Client object.""" if version is None: version = CONF.glance_api_version @@ -161,7 +160,7 @@ class GlanceClientWrapper(object): retry the request according to CONF.glance_num_retries. """ version = self.version - if version in kwargs: + if 'version' in kwargs: version = kwargs['version'] retry_excs = (glanceclient.exc.ServiceUnavailable, diff --git a/cinder/tests/image/test_glance.py b/cinder/tests/image/test_glance.py index f4f9ee150..f7f8ea45b 100644 --- a/cinder/tests/image/test_glance.py +++ b/cinder/tests/image/test_glance.py @@ -606,6 +606,14 @@ class TestGlanceClientVersion(test.TestCase): glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0]) + @mock.patch('cinder.image.glance.glanceclient.Client') + def test_call_glance_version_by_arg(self, _mockglanceclient): + """Test glance version set by arg to GlanceClientWrapper""" + glance_wrapper = glance.GlanceClientWrapper() + glance_wrapper.call('fake_context', 'method', version=2) + + self.assertEqual('2', _mockglanceclient.call_args[0][0]) + def _create_failing_glance_client(info): class MyGlanceStubClient(glance_stubs.StubGlanceClient): -- 2.45.2