Skip to content

Commit 8db3933

Browse files
committed
Don't display router's is_ha and is_distributed attributes always
In case when is_ha or is_distributed attribute of Neutron's router is set to None, it means that it wasn't returned from server and should not be displayed. Otherwise it might be confusing for user is making openstack router show <router_name> call as an admin will return e.g. is_ha=True but same call done as regular user will return False or None. It might happen like that because returning of those attributes is forbidden for regular users in Neutron's policy.json Depends-On: https://review.openstack.org/567606/ Change-Id: I626b5193d9ecb308baad7b27939f9673c32b4182 Closes-Bug: #1689510 Task: 19789 Story: 2002110
1 parent f7e4d31 commit 8db3933

2 files changed

Lines changed: 60 additions & 7 deletions

File tree

openstackclient/network/v2/router.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ def _get_columns(item):
7171
}
7272
if hasattr(item, 'interfaces_info'):
7373
column_map['interfaces_info'] = 'interfaces_info'
74-
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
74+
invisible_columns = []
75+
if item.is_ha is None:
76+
invisible_columns.append('is_ha')
77+
column_map.pop('is_ha')
78+
if item.is_distributed is None:
79+
invisible_columns.append('is_distributed')
80+
column_map.pop('is_distributed')
81+
return sdk_utils.get_osc_show_columns_for_sdk_resource(
82+
item, column_map, invisible_columns)
7583

7684

7785
def _get_attrs(client_manager, parsed_args):
@@ -330,17 +338,13 @@ def take_action(self, parsed_args):
330338
'name',
331339
'status',
332340
'is_admin_state_up',
333-
'is_distributed',
334-
'is_ha',
335341
'project_id',
336342
)
337343
column_headers = (
338344
'ID',
339345
'Name',
340346
'Status',
341347
'State',
342-
'Distributed',
343-
'HA',
344348
'Project',
345349
)
346350

@@ -376,6 +380,16 @@ def take_action(self, parsed_args):
376380
else:
377381
data = client.routers(**args)
378382

383+
# check if "HA" and "Distributed" columns should be displayed also
384+
data = list(data)
385+
for d in data:
386+
if (d.is_distributed is not None and
387+
'is_distributed' not in columns):
388+
columns = columns + ('is_distributed',)
389+
column_headers = column_headers + ('Distributed',)
390+
if d.is_ha is not None and 'is_ha' not in columns:
391+
columns = columns + ('is_ha',)
392+
column_headers = column_headers + ('HA',)
379393
if parsed_args.long:
380394
columns = columns + (
381395
'routes',

openstackclient/tests/unit/network/v2/test_router.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ class TestListRouter(TestRouter):
400400
'Name',
401401
'Status',
402402
'State',
403+
'Project',
403404
'Distributed',
404405
'HA',
405-
'Project',
406406
)
407407
columns_long = columns + (
408408
'Routes',
@@ -423,9 +423,9 @@ class TestListRouter(TestRouter):
423423
r.name,
424424
r.status,
425425
router._format_admin_state(r.admin_state_up),
426+
r.tenant_id,
426427
r.distributed,
427428
r.ha,
428-
r.tenant_id,
429429
))
430430

431431
router_agent_data = []
@@ -496,6 +496,25 @@ def test_router_list_no_options(self):
496496
self.assertEqual(self.columns, columns)
497497
self.assertEqual(self.data, list(data))
498498

499+
def test_router_list_no_ha_no_distributed(self):
500+
_routers = network_fakes.FakeRouter.create_routers({
501+
'ha': None,
502+
'distributed': None},
503+
count=3)
504+
505+
arglist = []
506+
verifylist = [
507+
('long', False),
508+
]
509+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
510+
511+
with mock.patch.object(
512+
self.network, "routers", return_value=_routers):
513+
columns, data = self.cmd.take_action(parsed_args)
514+
515+
self.assertNotIn("is_distributed", columns)
516+
self.assertNotIn("is_ha", columns)
517+
499518
def test_router_list_long(self):
500519
arglist = [
501520
'--long',
@@ -1196,6 +1215,26 @@ def test_show_all_options(self):
11961215
self.assertEqual(self.columns, columns)
11971216
self.assertEqual(self.data, data)
11981217

1218+
def test_show_no_ha_no_distributed(self):
1219+
_router = network_fakes.FakeRouter.create_one_router({
1220+
'ha': None,
1221+
'distributed': None})
1222+
1223+
arglist = [
1224+
_router.name,
1225+
]
1226+
verifylist = [
1227+
('router', _router.name),
1228+
]
1229+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1230+
1231+
with mock.patch.object(
1232+
self.network, "find_router", return_value=_router):
1233+
columns, data = self.cmd.take_action(parsed_args)
1234+
1235+
self.assertNotIn("is_distributed", columns)
1236+
self.assertNotIn("is_ha", columns)
1237+
11991238

12001239
class TestUnsetRouter(TestRouter):
12011240

0 commit comments

Comments
 (0)