Merge "[env][openstack] Change format of info method"

This commit is contained in:
Zuul 2018-02-12 05:05:14 +00:00 committed by Gerrit Code Review
commit aa357407cd
2 changed files with 18 additions and 4 deletions

View File

@ -180,10 +180,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"])
}
}

View File

@ -196,7 +196,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"}]
@ -206,5 +208,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)