From 534810fd038e99ecf295d67860e87b79f195547e Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 24 Oct 2017 15:35:25 +0200 Subject: [PATCH] Pass missing arguments to session in SessionClient._make_session_request If a server does not return API version headers, this will make the fallback to /v1 work correctly. Change-Id: I42b66daea1f4397273a3f4eb1638abafb3bb28ce Closes-Bug: #1726870 --- ironicclient/common/http.py | 10 +++++++++- ironicclient/tests/unit/common/test_http.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ironicclient/common/http.py b/ironicclient/common/http.py index 3a425f861..2a62a46c3 100644 --- a/ironicclient/common/http.py +++ b/ironicclient/common/http.py @@ -504,8 +504,16 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter): return self._generic_parse_version_headers(resp.headers.get) def _make_simple_request(self, conn, method, url): + endpoint_filter = { + 'interface': self.interface, + 'service_type': self.service_type, + 'region_name': self.region_name + } + # NOTE: conn is self.session for this class - return conn.request(url, method, raise_exc=False) + return conn.request(url, method, raise_exc=False, + user_agent=USER_AGENT, + endpoint_filter=endpoint_filter) @with_retries def _http_request(self, url, method, **kwargs): diff --git a/ironicclient/tests/unit/common/test_http.py b/ironicclient/tests/unit/common/test_http.py index 7d4575951..0da706aae 100644 --- a/ironicclient/tests/unit/common/test_http.py +++ b/ironicclient/tests/unit/common/test_http.py @@ -539,6 +539,23 @@ class SessionClientTest(utils.BaseTestCase): def test_endpoint_override_not_valid(self): self._test_endpoint_override(True) + def test_make_simple_request(self): + session = mock.Mock(spec=['request']) + + client = _session_client(session=session, + endpoint_override='http://127.0.0.1') + res = client._make_simple_request(session, 'GET', 'url') + + session.request.assert_called_once_with( + 'url', 'GET', raise_exc=False, + endpoint_filter={ + 'interface': 'publicURL', + 'service_type': 'baremetal', + 'region_name': '' + }, + user_agent=http.USER_AGENT) + self.assertEqual(res, session.request.return_value) + @mock.patch.object(time, 'sleep', lambda *_: None) class RetriesTestCase(utils.BaseTestCase):