diff options
author | Sean Dague <sean@dague.net> | 2015-09-03 11:13:21 -0400 |
---|---|---|
committer | Sean Dague <sean@dague.net> | 2015-09-03 14:13:33 -0400 |
commit | e4b0d46c4b5b99973a7f65c294a9b73c8adfefb7 (patch) | |
tree | 1cf234cfed3ad1dc88646b5903c50baf5a3b17e9 | |
parent | c915757ed5e7ce3714eb9f0682d24530112f735e (diff) | |
download | python-novaclient-e4b0d46c4b5b99973a7f65c294a9b73c8adfefb7.tar.gz |
workaround for RAX repose configuration2.28.0
The RAX Repose environment is blocking access to the API version
information by local policy, returning a 401 before we even get to
Nova itself. While this in clearly incorrect behavior, it is behavior
in the field, and we should not break all our users on that cloud.
This catches the 401 and translates that so that it's the equivalent
of only supporting v2.0. We will be taking these API calls to defcore,
and intend to remove this work around once that is done.
Change-Id: I2072095c24b41efcfd58d6f25205bcc94f1174da
Related-Bug: #1491579
-rw-r--r-- | novaclient/tests/unit/test_api_versions.py | 12 | ||||
-rw-r--r-- | novaclient/tests/unit/v2/test_versions.py | 9 | ||||
-rw-r--r-- | novaclient/v2/versions.py | 11 |
3 files changed, 31 insertions, 1 deletions
diff --git a/novaclient/tests/unit/test_api_versions.py b/novaclient/tests/unit/test_api_versions.py index 02df69a4..0159d198 100644 --- a/novaclient/tests/unit/test_api_versions.py +++ b/novaclient/tests/unit/test_api_versions.py @@ -357,3 +357,15 @@ class DiscoverVersionTestCase(utils.TestCase): api_versions.discover_version( fake_client, api_versions.APIVersion('2.latest')).get_string()) + + def test_server_without_microversion_rax_workaround(self): + fake_client = mock.MagicMock() + fake_client.versions.get_current.return_value = None + novaclient.API_MAX_VERSION = api_versions.APIVersion("2.11") + novaclient.API_MIN_VERSION = api_versions.APIVersion("2.1") + + self.assertEqual( + "2.0", + api_versions.discover_version( + fake_client, + api_versions.APIVersion('2.latest')).get_string()) diff --git a/novaclient/tests/unit/v2/test_versions.py b/novaclient/tests/unit/v2/test_versions.py index 2d46472d..da348751 100644 --- a/novaclient/tests/unit/v2/test_versions.py +++ b/novaclient/tests/unit/v2/test_versions.py @@ -14,6 +14,7 @@ import mock +from novaclient import exceptions as exc from novaclient.tests.unit import utils from novaclient.tests.unit.v2 import fakes from novaclient.v2 import versions @@ -64,3 +65,11 @@ class VersionsTest(utils.TestCase): self.cs.callback = [] self.cs.versions.get_current() self.cs.assert_called('GET', 'http://nova-api:8774/v2.1/') + + @mock.patch.object(versions.VersionManager, '_is_session_client', + return_value=True) + @mock.patch.object(versions.VersionManager, '_get', + side_effect=exc.Unauthorized("401 RAX")) + def test_get_current_with_rax_workaround(self, session, get): + self.cs.callback = [] + self.assertIsNone(self.cs.versions.get_current()) diff --git a/novaclient/v2/versions.py b/novaclient/v2/versions.py index 09fd25f0..17a20df9 100644 --- a/novaclient/v2/versions.py +++ b/novaclient/v2/versions.py @@ -20,6 +20,7 @@ from six.moves import urllib from novaclient import base from novaclient import client +from novaclient import exceptions as exc class Version(base.Resource): @@ -45,7 +46,15 @@ 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 - return self._get(url, "version") + 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 else: # NOTE(andreykurilin): HTTPClient doesn't have ability to send get # request without token in the url, so `self._get` doesn't work. |