diff --git a/rally/plugins/openstack/platforms/existing.py b/rally/plugins/openstack/platforms/existing.py index bb5336ed..592e2b05 100644 --- a/rally/plugins/openstack/platforms/existing.py +++ b/rally/plugins/openstack/platforms/existing.py @@ -13,7 +13,8 @@ # under the License. import copy -import sys +import json +import traceback from rally.common import logging from rally.env import platform @@ -145,21 +146,28 @@ class OpenStack(platform.Platform): osclients.Clients( self.platform_data["admin"]).verified_keystone() except Exception: + d = copy.deepcopy(self.platform_data["admin"]) + d["password"] = "***" return { "available": False, - "message": ("Bad admin creds: %s" - % self.platform_data["admin"]), - "traceback": list(sys.exc_info()) + "message": ( + "Bad admin creds: \n%s" + % json.dumps(d, indent=2, sort_keys=True)), + "traceback": traceback.format_exc() } for user in self.platform_data["users"]: try: osclients.Clients(user).keystone() except Exception: + d = copy.deepcopy(user) + d["password"] = "***" return { "available": False, - "message": ("Bad user creds: %s" % user), - "traceback": list(sys.exc_info()) + "message": ( + "Bad user creds: \n%s" + % json.dumps(d, indent=2, sort_keys=True)), + "traceback": traceback.format_exc() } return {"available": True} @@ -168,9 +176,10 @@ class OpenStack(platform.Platform): """Return information about cloud as dict.""" active_user = (self.platform_data["admin"] or self.platform_data["users"][0]) + services = osclients.Clients(active_user).services() return { "info": { - "services": osclients.Clients(active_user).list_services() + "services": services } } diff --git a/tests/unit/plugins/openstack/platforms/test_existing.py b/tests/unit/plugins/openstack/platforms/test_existing.py index 4adb915e..e2bfaad0 100644 --- a/tests/unit/plugins/openstack/platforms/test_existing.py +++ b/tests/unit/plugins/openstack/platforms/test_existing.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import json + import mock from rally.env import platform @@ -160,35 +162,47 @@ class ExistingPlatformTestCase(test_platform.PlatformBaseTestCase): @mock.patch("rally.plugins.openstack.osclients.Clients") def test_check_failed_admin(self, mock_clients): mock_clients.return_value.verified_keystone.side_effect = Exception - pdata = {"admin": mock.MagicMock()} + pdata = {"admin": {"username": "balbab", "password": "12345"}} result = existing.OpenStack({}, platform_data=pdata).check_health() self._check_health_schema(result) self.assertEqual( {"available": False, - "message": "Bad admin creds: %s" % pdata["admin"], - "traceback": [Exception, mock.ANY, mock.ANY]}, + "message": + "Bad admin creds: \n%s" + % json.dumps({"username": "balbab", "password": "***"}, + indent=2, sort_keys=True), + "traceback": mock.ANY}, result) + self.assertIn("Traceback (most recent call last)", result["traceback"]) @mock.patch("rally.plugins.openstack.osclients.Clients") def test_check_failed_users(self, mock_clients): mock_clients.return_value.keystone.side_effect = Exception - pdata = {"admin": None, "users": [mock.MagicMock()]} + pdata = {"admin": None, + "users": [{"username": "balbab", "password": "12345"}]} result = existing.OpenStack({}, platform_data=pdata).check_health() self._check_health_schema(result) self.assertEqual( {"available": False, - "message": "Bad user creds: %s" % pdata["users"][0], - "traceback": [Exception, mock.ANY, mock.ANY]}, + "message": + "Bad user creds: \n%s" + % json.dumps({"username": "balbab", "password": "***"}, + indent=2, sort_keys=True), + "traceback": mock.ANY}, result) + self.assertIn("Traceback (most recent call last)", result["traceback"]) @mock.patch("rally.plugins.openstack.osclients.Clients") def test_info(self, mock_clients): - mock_clients.return_value.list_services.return_value = ["a", "b"] - p = existing.OpenStack({}, - platform_data={"admin": None, "users": ["u1"]}) + mock_clients.return_value.services.return_value = ["a", "b"] + platform_data = { + "admin": None, + "users": [{"username": "u1", "password": "123"}] + } + p = existing.OpenStack({}, platform_data=platform_data) result = p.info() - mock_clients.assert_called_once_with("u1") - mock_clients.return_value.list_services.assert_called_once_with() + mock_clients.assert_called_once_with(platform_data["users"][0]) + mock_clients.return_value.services.assert_called_once_with() self.assertEqual({"info": {"services": ["a", "b"]}}, result) self._check_info_schema(result)