workaround for RAX repose configuration

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
This commit is contained in:
Sean Dague 2015-09-03 11:13:21 -04:00
parent c915757ed5
commit e4b0d46c4b
3 changed files with 31 additions and 1 deletions

View File

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

View File

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

View File

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