Protect against endpoint_data not existing
It's possible in get_api_major_version that the endpoint in question is not found at all. In that case, we are documented to return None, but what we do instead is throw an exception trying to get data off of the None object. Change-Id: I06ad497854f4e95a1a2a4a93241b244fc476b139
This commit is contained in:
parent
c40eb2951d
commit
2585047ffc
@ -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.
|
||||
|
@ -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/'
|
||||
|
Loading…
Reference in New Issue
Block a user