Make sure --bypass-url honored if specified

Currently SessionClient ignored --bypass-url which is only used with
HTTPClient. This change force to use HTTPClient if bypass-url specified.

Change-Id: I03d1eec8cfda81efce409399b8d6ca91b779840b
Closes-Bug: #1467577
This commit is contained in:
Qiu Yu 2015-08-26 02:56:21 +08:00 committed by Sean McGinnis
parent 3d06d358ad
commit 03e041a3cd
2 changed files with 15 additions and 2 deletions
cinderclient

@ -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,

@ -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(