From 03e041a3cd6cbeb51e49076e575b90c29cd0a87c Mon Sep 17 00:00:00 2001
From: Qiu Yu <qiuyu@ebaysf.com>
Date: Wed, 26 Aug 2015 02:56:21 +0800
Subject: [PATCH] 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
---
 cinderclient/client.py                 |  4 ++--
 cinderclient/tests/unit/test_client.py | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

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(