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
This commit is contained in:
Daniel Wallace 2015-09-08 20:13:39 -05:00
parent e612205ab8
commit b2221c8a70
2 changed files with 20 additions and 10 deletions

View File

@ -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())

View File

@ -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."""