From e44bb009d36bddc0fdfb6e949ddc293de291dcca Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 24 May 2016 15:56:27 +0200 Subject: [PATCH] keystone: fix catalog output when region is unset If no region is set in Keystone, null is deserialized as None and the region has None has value, which triggers a type error when building the output string. This patch fixes that. Change-Id: I7637dc2595655cf452f38308f99fe66ac782e16d --- openstackclient/identity/v2_0/catalog.py | 4 +++- openstackclient/identity/v3/catalog.py | 2 +- .../tests/identity/v2_0/test_catalog.py | 16 ++++++++++++++-- .../tests/identity/v3/test_catalog.py | 11 +++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/openstackclient/identity/v2_0/catalog.py b/openstackclient/identity/v2_0/catalog.py index 669b04f31a..53a6fe3451 100644 --- a/openstackclient/identity/v2_0/catalog.py +++ b/openstackclient/identity/v2_0/catalog.py @@ -25,7 +25,9 @@ def _format_endpoints(eps=None): return "" ret = '' for index, ep in enumerate(eps): - region = eps[index].get('region', '') + region = eps[index].get('region') + if region is None: + region = '' ret += region + '\n' for endpoint_type in ['publicURL', 'internalURL', 'adminURL']: url = eps[index].get(endpoint_type) diff --git a/openstackclient/identity/v3/catalog.py b/openstackclient/identity/v3/catalog.py index 38a57d900e..78d71f59ab 100644 --- a/openstackclient/identity/v3/catalog.py +++ b/openstackclient/identity/v3/catalog.py @@ -25,7 +25,7 @@ def _format_endpoints(eps=None): return "" ret = '' for ep in eps: - region = ep.get('region_id') or ep.get('region', '') + region = ep.get('region_id') or ep.get('region') or '' ret += region + '\n' ret += " %s: %s\n" % (ep['interface'], ep['url']) return ret diff --git a/openstackclient/tests/identity/v2_0/test_catalog.py b/openstackclient/tests/identity/v2_0/test_catalog.py index 1e27bb3cfc..d9ae6a80b6 100644 --- a/openstackclient/tests/identity/v2_0/test_catalog.py +++ b/openstackclient/tests/identity/v2_0/test_catalog.py @@ -36,6 +36,12 @@ class TestCatalog(utils.TestCommand): 'internalURL': 'https://internal.two.example.com', 'adminURL': 'https://admin.two.example.com', }, + { + 'region': None, + 'publicURL': 'https://public.none.example.com', + 'internalURL': 'https://internal.none.example.com', + 'adminURL': 'https://admin.none.example.com', + }, ], } @@ -87,7 +93,10 @@ class TestCatalogList(TestCatalog): 'adminURL: https://admin.one.example.com\n' 'two\n publicURL: https://public.two.example.com\n ' 'internalURL: https://internal.two.example.com\n ' - 'adminURL: https://admin.two.example.com\n', + 'adminURL: https://admin.two.example.com\n' + '\n publicURL: https://public.none.example.com\n ' + 'internalURL: https://internal.none.example.com\n ' + 'adminURL: https://admin.none.example.com\n', ), ) self.assertEqual(datalist, tuple(data)) @@ -164,7 +173,10 @@ class TestCatalogShow(TestCatalog): 'adminURL: https://admin.one.example.com\n' 'two\n publicURL: https://public.two.example.com\n ' 'internalURL: https://internal.two.example.com\n ' - 'adminURL: https://admin.two.example.com\n', + 'adminURL: https://admin.two.example.com\n' + '\n publicURL: https://public.none.example.com\n ' + 'internalURL: https://internal.none.example.com\n ' + 'adminURL: https://admin.none.example.com\n', 'qwertyuiop', 'supernova', 'compute', diff --git a/openstackclient/tests/identity/v3/test_catalog.py b/openstackclient/tests/identity/v3/test_catalog.py index a03c9d3ead..1b8fa08586 100644 --- a/openstackclient/tests/identity/v3/test_catalog.py +++ b/openstackclient/tests/identity/v3/test_catalog.py @@ -38,6 +38,11 @@ class TestCatalog(utils.TestCommand): 'url': 'https://internal.example.com', 'interface': 'internal', }, + { + 'region': None, + 'url': 'https://none.example.com', + 'interface': 'none', + }, ], } @@ -81,7 +86,8 @@ class TestCatalogList(TestCatalog): 'compute', 'onlyone\n public: https://public.example.com\n' 'onlyone\n admin: https://admin.example.com\n' - '\n internal: https://internal.example.com\n', + '\n internal: https://internal.example.com\n' + '\n none: https://none.example.com\n', ), ) self.assertEqual(datalist, tuple(data)) @@ -114,7 +120,8 @@ class TestCatalogShow(TestCatalog): datalist = ( 'onlyone\n public: https://public.example.com\nonlyone\n' ' admin: https://admin.example.com\n' - '\n internal: https://internal.example.com\n', + '\n internal: https://internal.example.com\n' + '\n none: https://none.example.com\n', 'qwertyuiop', 'supernova', 'compute',