From 1a302df23766f56d6cb84ede2730416391a08f4d Mon Sep 17 00:00:00 2001 From: fandeliang Date: Fri, 28 Nov 2014 00:10:05 -0800 Subject: [PATCH] Fix rally deployment check fails with https auth_url When create keystone client, rally will add admin_port(35357) to auth_url if auth_url doesn't contain an obvious port. And thus, causing the change of https auth_url. So we should ignore adding admin_port for https auth_url. Change-Id: If518687839c5e0734b85b69c680f7d124e135e94 Closes-bug: #1397160 --- rally/osclients.py | 3 ++- tests/unit/test_osclients.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/rally/osclients.py b/rally/osclients.py index 165e4a5578..2e22e35d8e 100644 --- a/rally/osclients.py +++ b/rally/osclients.py @@ -99,7 +99,8 @@ class Clients(object): kw = dict(self.endpoint.to_dict().items() + new_kw.items()) if kw["endpoint_type"] == consts.EndpointType.PUBLIC: mgmt_url = urlparse.urlparse(kw["auth_url"]) - if mgmt_url.port != kw["admin_port"]: + if (mgmt_url.port != kw["admin_port"] and + mgmt_url.scheme != "https"): kw["endpoint"] = "{0}://{1}:{2}{3}".format( mgmt_url.scheme, mgmt_url.hostname, diff --git a/tests/unit/test_osclients.py b/tests/unit/test_osclients.py index a5c5f01470..d31b54162d 100644 --- a/tests/unit/test_osclients.py +++ b/tests/unit/test_osclients.py @@ -33,7 +33,10 @@ class OSClientsTestCase(test.TestCase): super(OSClientsTestCase, self).setUp() self.endpoint = endpoint.Endpoint("http://auth_url", "use", "pass", "tenant") + self.endpoint_https = endpoint.Endpoint("https://auth_url/v2.0/admin", + "use", "pass", "tenant") self.clients = osclients.Clients(self.endpoint) + self.clients_https = osclients.Clients(self.endpoint_https) self.fake_keystone = fakes.FakeKeystoneClient() self.fake_keystone.auth_token = mock.MagicMock() @@ -64,6 +67,18 @@ class OSClientsTestCase(test.TestCase): self.mock_create_keystone_client.assert_called_once_with(kwargs) self.assertEqual(self.clients.cache["keystone"], self.fake_keystone) + def test_keystone_with_https_auth_url(self): + self.assertNotIn("keystone", self.clients_https.cache) + client = self.clients_https.keystone() + self.assertEqual(client, self.fake_keystone) + endpoint = {"timeout": cfg.CONF.openstack_client_http_timeout, + "insecure": False, "cacert": None, + "endpoint": self.endpoint_https.auth_url} + kwargs = dict(self.endpoint_https.to_dict().items() + endpoint.items()) + self.mock_create_keystone_client.assert_called_once_with(kwargs) + self.assertEqual(self.clients_https.cache["keystone"], + self.fake_keystone) + @mock.patch("rally.osclients.Clients.keystone") def test_verified_keystone_user_not_admin(self, mock_keystone): mock_keystone.return_value = fakes.FakeKeystoneClient()