Merge "Fix TypeError when using endpoint_override with SessionClient"

This commit is contained in:
Zuul 2019-09-23 17:05:43 +00:00 committed by Gerrit Code Review
commit afce87ae8c
4 changed files with 25 additions and 11 deletions

View File

@ -383,7 +383,11 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter):
super(SessionClient, self).__init__(**kwargs)
endpoint_filter = self._get_endpoint_filter()
endpoint = self.session.get_endpoint(**endpoint_filter)
endpoint = self.get_endpoint(**endpoint_filter)
if endpoint is None:
raise exc.EndpointNotFound(
_('The Bare Metal API endpoint cannot be detected and was '
'not provided explicitly'))
self.endpoint_trimmed = _trim_endpoint_api_version(endpoint)
def _parse_version_headers(self, resp):

View File

@ -403,6 +403,13 @@ class SessionClientTest(utils.BaseTestCase):
user_agent=http.USER_AGENT)
self.assertEqual(res, session.request.return_value)
@mock.patch.object(http.SessionClient, 'get_endpoint', autospec=True)
def test_endpoint_not_found(self, mock_get_endpoint):
mock_get_endpoint.return_value = None
self.assertRaises(exc.EndpointNotFound, _session_client,
session=utils.mockSession({}))
@mock.patch.object(time, 'sleep', lambda *_: None)
class RetriesTestCase(utils.BaseTestCase):

View File

@ -57,14 +57,11 @@ class ClientTest(utils.BaseTestCase):
interface=expected_interface,
region_name=kwargs.get('region_name'))
if not {'endpoint'}.intersection(kwargs):
calls = [get_endpoint_call,
mock.call(interface=client.http_client.interface,
service_type=client.http_client.service_type,
region_name=client.http_client.region_name)]
self.assertEqual(calls, session.get_endpoint.call_args_list)
else:
self.assertEqual([get_endpoint_call],
session.get_endpoint.call_args_list)
else:
# we use adaper.get_endpoint instead of session.get_endpoint
self.assertFalse(session.get_endpoint.called)
if 'os_ironic_api_version' in kwargs:
# NOTE(TheJulia): This does not test the negotiation logic
# as a request must be triggered in order for any version
@ -256,10 +253,9 @@ class ClientTest(utils.BaseTestCase):
'session': session,
}
iroclient.get_client('1', **kwargs)
endpoint_calls = 2 * [mock.call(service_type='baremetal',
interface=None,
region_name=None)]
self.assertEqual(endpoint_calls, session.get_endpoint.call_args_list)
session.get_endpoint.assert_called_once_with(service_type='baremetal',
interface=None,
region_name=None)
def test_get_client_incorrect_session_passed(self):
session = mock.Mock()

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes ``TypeError`` when the bare metal endpoint cannot be detected from
a session. A proper ``EndpointNotFound`` exception is raised now.
- |
Fixes using ``endpoint_override`` with the ``SessionClient``.