Merge "Protect against endpoint_data not existing"

This commit is contained in:
Zuul 2018-09-12 05:29:29 +00:00 committed by Gerrit Code Review
commit 58ac4c059a
2 changed files with 26 additions and 1 deletions

View File

@ -149,7 +149,9 @@ class BaseAuthPlugin(object):
endpoint_data = self.get_endpoint_data(
session, endpoint_override=endpoint_override,
discover_versions=False, **kwargs)
return endpoint_data.api_version
if endpoint_data:
return endpoint_data.api_version
return None
def get_endpoint(self, session, **kwargs):
"""Return an endpoint for the client.

View File

@ -560,6 +560,29 @@ class VersionDataTests(utils.TestCase):
self.assertTrue(mock.called_once)
def test_version_data_legacy_ironic_no_override(self):
"""Validate detection of legacy Ironic microversion ranges."""
ironic_url = 'https://bare-metal.example.com/v1/'
self.requests_mock.get(
ironic_url, status_code=200,
json={
'id': 'v1',
'links': [{
"href": ironic_url,
"rel": "self"}]},
headers={
'X-OpenStack-Ironic-API-Minimum-Version': '1.3',
'X-OpenStack-Ironic-API-Maximum-Version': '1.21',
})
plugin = noauth.NoAuth()
a = adapter.Adapter(
self.session,
auth=plugin,
service_type='baremetal')
self.assertIsNone(a.get_api_major_version())
def test_version_data_ironic_microversions(self):
"""Validate detection of Ironic microversion ranges."""
ironic_url = 'https://bare-metal.example.com/v1/'