summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorGuojian Shao <guojian@unitedstack.com>2015-07-15 12:37:30 +0800
committerGuojian Shao <guojian@unitedstack.com>2015-07-16 07:25:51 +0000
commit7829aca70459753d7df0e197f4bf6090542f9b7b (patch)
treef620d537780d45d0c980383d2031a6bcd0377738 /openstackclient
parent1af89f757c1edf44067de964cb6ca8dffbb1969e (diff)
downloadpython-openstackclient-7829aca70459753d7df0e197f4bf6090542f9b7b.tar.gz
only return endpoints that have url
Change-Id: I97a502252c0c377fce573e92b83c0122812f6f80 Closes-Bug: #1474656
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/identity/v2_0/catalog.py6
-rw-r--r--openstackclient/tests/identity/v2_0/test_catalog.py40
2 files changed, 44 insertions, 2 deletions
diff --git a/openstackclient/identity/v2_0/catalog.py b/openstackclient/identity/v2_0/catalog.py
index c10001d0..e166c855 100644
--- a/openstackclient/identity/v2_0/catalog.py
+++ b/openstackclient/identity/v2_0/catalog.py
@@ -30,8 +30,10 @@ def _format_endpoints(eps=None):
for index, ep in enumerate(eps):
region = eps[index].get('region', '<none>')
ret += region + '\n'
- for url in ['publicURL', 'internalURL', 'adminURL']:
- ret += " %s: %s\n" % (url, eps[index][url])
+ for endpoint_type in ['publicURL', 'internalURL', 'adminURL']:
+ url = eps[index].get(endpoint_type)
+ if url:
+ ret += " %s: %s\n" % (endpoint_type, url)
return ret
diff --git a/openstackclient/tests/identity/v2_0/test_catalog.py b/openstackclient/tests/identity/v2_0/test_catalog.py
index fe13d78d..7f1835d6 100644
--- a/openstackclient/tests/identity/v2_0/test_catalog.py
+++ b/openstackclient/tests/identity/v2_0/test_catalog.py
@@ -84,6 +84,46 @@ class TestCatalogList(TestCatalog):
), )
self.assertEqual(datalist, tuple(data))
+ def test_catalog_list_with_endpoint_url(self):
+ fake_service = {
+ 'id': 'qwertyuiop',
+ 'type': 'compute',
+ 'name': 'supernova',
+ 'endpoints': [
+ {
+ 'region': 'one',
+ 'publicURL': 'https://public.one.example.com',
+ },
+ {
+ 'region': 'two',
+ 'publicURL': 'https://public.two.example.com',
+ 'internalURL': 'https://internal.two.example.com',
+ },
+ ],
+ }
+ self.sc_mock.service_catalog.get_data.return_value = [
+ fake_service,
+ ]
+
+ arglist = []
+ verifylist = []
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+ self.sc_mock.service_catalog.get_data.assert_called_with()
+
+ collist = ('Name', 'Type', 'Endpoints')
+ self.assertEqual(collist, columns)
+ datalist = ((
+ 'supernova',
+ 'compute',
+ 'one\n publicURL: https://public.one.example.com\n'
+ 'two\n publicURL: https://public.two.example.com\n '
+ 'internalURL: https://internal.two.example.com\n'
+ ), )
+ self.assertEqual(datalist, tuple(data))
+
class TestCatalogShow(TestCatalog):