From b2221c8a7020ac66197360f594ba58b27434cf7d Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Tue, 8 Sep 2015 20:13:39 -0500 Subject: [PATCH] Fix bugs with rackspace not all apis have the versions available Rackspace api does not open up for querying versions. This causes it to still break when using the rackspace-auth-plugin add tests for api_version Unauthorized make sure that the list can still run even if the api_version check is unauthorized. Closes-Bug: #1493974 Closes-Bug: #1491579 Change-Id: I038b84bad5b747a0688aef989f1337aee835b945 --- novaclient/tests/unit/v2/test_versions.py | 8 ++++++++ novaclient/v2/versions.py | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/novaclient/tests/unit/v2/test_versions.py b/novaclient/tests/unit/v2/test_versions.py index da348751f..aa8e84a6e 100644 --- a/novaclient/tests/unit/v2/test_versions.py +++ b/novaclient/tests/unit/v2/test_versions.py @@ -73,3 +73,11 @@ class VersionsTest(utils.TestCase): def test_get_current_with_rax_workaround(self, session, get): self.cs.callback = [] self.assertIsNone(self.cs.versions.get_current()) + + @mock.patch.object(versions.VersionManager, '_is_session_client', + return_value=False) + @mock.patch.object(versions.VersionManager, '_list', + side_effect=exc.Unauthorized("401 RAX")) + def test_get_current_with_rax_auth_plugin_workaround(self, session, _list): + self.cs.callback = [] + self.assertIsNone(self.cs.versions.get_current()) diff --git a/novaclient/v2/versions.py b/novaclient/v2/versions.py index 17a20df99..796ea7df5 100644 --- a/novaclient/v2/versions.py +++ b/novaclient/v2/versions.py @@ -37,7 +37,7 @@ class VersionManager(base.ManagerWithFind): def _is_session_client(self): return isinstance(self.api.client, client.SessionClient) - def get_current(self): + def _get_current(self): """Returns info about current version.""" if self._is_session_client(): url = self.api.client.get_endpoint().rsplit("/", 1)[0] @@ -46,15 +46,7 @@ class VersionManager(base.ManagerWithFind): # that's actually a 300 redirect to /v2/... because of how # paste works. So adding the end slash is really important. url = "%s/" % url - try: - return self._get(url, "version") - except exc.Unauthorized: - # NOTE(sdague): RAX's repose configuration blocks - # access to the versioned endpoint, which is - # definitely non-compliant behavior. However, there is - # no defcore test for this yet. Remove this code block - # once we land things in defcore. - return None + return self._get(url, "version") else: # NOTE(andreykurilin): HTTPClient doesn't have ability to send get # request without token in the url, so `self._get` doesn't work. @@ -65,6 +57,16 @@ class VersionManager(base.ManagerWithFind): if link["href"].rstrip('/') == url: return version + def get_current(self): + try: + return self._get_current() + except exc.Unauthorized: + # NOTE(sdague): RAX's repose configuration blocks access to the + # versioned endpoint, which is definitely non-compliant behavior. + # However, there is no defcore test for this yet. Remove this code + # block once we land things in defcore. + return None + def list(self): """List all versions."""