Skip to content

Commit 7829aca

Browse files
author
Guojian Shao
committed
only return endpoints that have url
Change-Id: I97a502252c0c377fce573e92b83c0122812f6f80 Closes-Bug: #1474656
1 parent 1af89f7 commit 7829aca

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

openstackclient/identity/v2_0/catalog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ def _format_endpoints(eps=None):
3030
for index, ep in enumerate(eps):
3131
region = eps[index].get('region', '<none>')
3232
ret += region + '\n'
33-
for url in ['publicURL', 'internalURL', 'adminURL']:
34-
ret += " %s: %s\n" % (url, eps[index][url])
33+
for endpoint_type in ['publicURL', 'internalURL', 'adminURL']:
34+
url = eps[index].get(endpoint_type)
35+
if url:
36+
ret += " %s: %s\n" % (endpoint_type, url)
3537
return ret
3638

3739

openstackclient/tests/identity/v2_0/test_catalog.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,46 @@ def test_catalog_list(self):
8484
), )
8585
self.assertEqual(datalist, tuple(data))
8686

87+
def test_catalog_list_with_endpoint_url(self):
88+
fake_service = {
89+
'id': 'qwertyuiop',
90+
'type': 'compute',
91+
'name': 'supernova',
92+
'endpoints': [
93+
{
94+
'region': 'one',
95+
'publicURL': 'https://public.one.example.com',
96+
},
97+
{
98+
'region': 'two',
99+
'publicURL': 'https://public.two.example.com',
100+
'internalURL': 'https://internal.two.example.com',
101+
},
102+
],
103+
}
104+
self.sc_mock.service_catalog.get_data.return_value = [
105+
fake_service,
106+
]
107+
108+
arglist = []
109+
verifylist = []
110+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
111+
112+
# DisplayCommandBase.take_action() returns two tuples
113+
columns, data = self.cmd.take_action(parsed_args)
114+
self.sc_mock.service_catalog.get_data.assert_called_with()
115+
116+
collist = ('Name', 'Type', 'Endpoints')
117+
self.assertEqual(collist, columns)
118+
datalist = ((
119+
'supernova',
120+
'compute',
121+
'one\n publicURL: https://public.one.example.com\n'
122+
'two\n publicURL: https://public.two.example.com\n '
123+
'internalURL: https://internal.two.example.com\n'
124+
), )
125+
self.assertEqual(datalist, tuple(data))
126+
87127

88128
class TestCatalogShow(TestCatalog):
89129

0 commit comments

Comments
 (0)