From 61598d05e86142ddb44507ff77d898ea2e4c5452 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Sat, 10 Feb 2018 17:42:37 +0200 Subject: [PATCH] [env][openstack] Change format of info method The info method of existing@openstack returns a dict with information about available services. The key isservice types, the value is service name. It is convenient for code usage, but not obvious for the users, as much as "__unknown__" service name. This patch changes the format to be a list of dicts. Each dict is a representation of available service. The service type is represented via "type" field and name (if available) is represented via "name" field. Also, the new format allows to provide more info about services in future. Change-Id: I4be4468d4a78ceb43e1bfa97c35c396606aa4da2 --- rally/plugins/openstack/platforms/existing.py | 11 +++++++++-- .../unit/plugins/openstack/platforms/test_existing.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rally/plugins/openstack/platforms/existing.py b/rally/plugins/openstack/platforms/existing.py index 592e2b05..e96c4260 100644 --- a/rally/plugins/openstack/platforms/existing.py +++ b/rally/plugins/openstack/platforms/existing.py @@ -176,10 +176,17 @@ 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() + services = [] + for stype, name in osclients.Clients(active_user).services().items(): + if name == "__unknown__": + # `__unknown__` name misleads, let's just not include it... + services.append({"type": stype}) + else: + services.append({"type": stype, "name": name}) + return { "info": { - "services": services + "services": sorted(services, key=lambda x: x["type"]) } } diff --git a/tests/unit/plugins/openstack/platforms/test_existing.py b/tests/unit/plugins/openstack/platforms/test_existing.py index e2bfaad0..3034fdcd 100644 --- a/tests/unit/plugins/openstack/platforms/test_existing.py +++ b/tests/unit/plugins/openstack/platforms/test_existing.py @@ -194,7 +194,9 @@ class ExistingPlatformTestCase(test_platform.PlatformBaseTestCase): @mock.patch("rally.plugins.openstack.osclients.Clients") def test_info(self, mock_clients): - mock_clients.return_value.services.return_value = ["a", "b"] + mock_clients.return_value.services.return_value = { + "foo": "bar", + "volumev4": "__unknown__"} platform_data = { "admin": None, "users": [{"username": "u1", "password": "123"}] @@ -204,5 +206,10 @@ class ExistingPlatformTestCase(test_platform.PlatformBaseTestCase): result = p.info() 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.assertEqual( + { + "info": { + "services": [{"type": "foo", "name": "bar"}, + {"type": "volumev4"}]}}, + result) self._check_info_schema(result)