diff --git a/cinderclient/client.py b/cinderclient/client.py index 59d4cd038..168a75471 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -547,8 +547,8 @@ def _construct_http_client(username=None, password=None, project_id=None, auth=None, api_version=None, **kwargs): - # Don't use sessions if third party plugin is used - if session and not auth_plugin: + # Don't use sessions if third party plugin or bypass_url being used + if session and not auth_plugin and not bypass_url: kwargs.setdefault('user_agent', 'python-cinderclient') kwargs.setdefault('interface', endpoint_type) return SessionClient(session=session, diff --git a/cinderclient/tests/unit/test_client.py b/cinderclient/tests/unit/test_client.py index fbb15cc4a..6285aad86 100644 --- a/cinderclient/tests/unit/test_client.py +++ b/cinderclient/tests/unit/test_client.py @@ -40,6 +40,19 @@ class ClientTest(utils.TestCase): self.assertRaises(cinderclient.exceptions.UnsupportedVersion, cinderclient.client.get_client_class, '0') + @mock.patch.object(cinderclient.client.HTTPClient, '__init__') + @mock.patch('cinderclient.client.SessionClient') + def test_construct_http_client_bypass_url( + self, session_mock, httpclient_mock): + bypass_url = 'http://example.com/' + httpclient_mock.return_value = None + cinderclient.client._construct_http_client( + bypass_url=bypass_url) + self.assertTrue(httpclient_mock.called) + self.assertEqual(bypass_url, + httpclient_mock.call_args[1].get('bypass_url')) + session_mock.assert_not_called() + def test_log_req(self): self.logger = self.useFixture( fixtures.FakeLogger(