summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--novaclient/tests/unit/test_api_versions.py12
-rw-r--r--novaclient/tests/unit/v2/test_versions.py9
-rw-r--r--novaclient/v2/versions.py11
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.