Add '--type'and other options to network rbac list
This patch adds '--type','--action','--long' filtering options to network rbac list command Change-Id: I21846820ab223bb7832e89eb2d7658bbec271aec Closes-Bug: #1648307 Partially-Implements: blueprint network-commands-options
This commit is contained in:
parent
1b3f953715
commit
af7129cda3
@ -79,6 +79,21 @@ List network RBAC policies
|
||||
.. code:: bash
|
||||
|
||||
openstack network rbac list
|
||||
[--type <type>]
|
||||
[--action <action>]
|
||||
[--long]
|
||||
|
||||
.. option:: --type <type>
|
||||
|
||||
List network RBAC policies according to given object type ("qos_policy" or "network")
|
||||
|
||||
.. option:: --action <action>
|
||||
|
||||
List network RBAC policies according to given action ("access_as_external" or "access_as_shared")
|
||||
|
||||
.. option:: --long
|
||||
|
||||
List additional fields in output
|
||||
|
||||
network rbac set
|
||||
----------------
|
||||
|
@ -164,6 +164,30 @@ class DeleteNetworkRBAC(command.Command):
|
||||
class ListNetworkRBAC(command.Lister):
|
||||
_description = _("List network RBAC policies")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListNetworkRBAC, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--type',
|
||||
metavar='<type>',
|
||||
choices=['qos_policy', 'network'],
|
||||
help=_('List network RBAC policies according to '
|
||||
'given object type ("qos_policy" or "network")')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--action',
|
||||
metavar='<action>',
|
||||
choices=['access_as_external', 'access_as_shared'],
|
||||
help=_('List network RBAC policies according to given '
|
||||
'action ("access_as_external" or "access_as_shared")')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("List additional fields in output")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
|
||||
@ -178,7 +202,17 @@ class ListNetworkRBAC(command.Lister):
|
||||
'Object ID',
|
||||
)
|
||||
|
||||
data = client.rbac_policies()
|
||||
query = {}
|
||||
if parsed_args.long:
|
||||
columns += ('action',)
|
||||
column_headers += ('Action',)
|
||||
if parsed_args.type is not None:
|
||||
query['object_type'] = parsed_args.type
|
||||
if parsed_args.action is not None:
|
||||
query['action'] = parsed_args.action
|
||||
|
||||
data = client.rbac_policies(**query)
|
||||
|
||||
return (column_headers,
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
|
@ -327,7 +327,12 @@ class TestListNetworkRABC(TestNetworkRBAC):
|
||||
'Object Type',
|
||||
'Object ID',
|
||||
)
|
||||
|
||||
columns_long = (
|
||||
'ID',
|
||||
'Object Type',
|
||||
'Object ID',
|
||||
'Action',
|
||||
)
|
||||
data = []
|
||||
for r in rbac_policies:
|
||||
data.append((
|
||||
@ -335,6 +340,14 @@ class TestListNetworkRABC(TestNetworkRBAC):
|
||||
r.object_type,
|
||||
r.object_id,
|
||||
))
|
||||
data_long = []
|
||||
for r in rbac_policies:
|
||||
data_long.append((
|
||||
r.id,
|
||||
r.object_type,
|
||||
r.object_id,
|
||||
r.action,
|
||||
))
|
||||
|
||||
def setUp(self):
|
||||
super(TestListNetworkRABC, self).setUp()
|
||||
@ -356,6 +369,55 @@ class TestListNetworkRABC(TestNetworkRBAC):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_network_rbac_list_type_opt(self):
|
||||
arglist = [
|
||||
'--type', self.rbac_policies[0].object_type, ]
|
||||
verifylist = [
|
||||
('type', self.rbac_policies[0].object_type)]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.rbac_policies.assert_called_with(**{
|
||||
'object_type': self.rbac_policies[0].object_type
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_network_rbac_list_action_opt(self):
|
||||
arglist = [
|
||||
'--action', self.rbac_policies[0].action, ]
|
||||
verifylist = [
|
||||
('action', self.rbac_policies[0].action)]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.rbac_policies.assert_called_with(**{
|
||||
'action': self.rbac_policies[0].action
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_network_rbac_list_with_long(self):
|
||||
arglist = [
|
||||
'--long',
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('long', True),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.rbac_policies.assert_called_with()
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
self.assertEqual(self.data_long, list(data))
|
||||
|
||||
|
||||
class TestSetNetworkRBAC(TestNetworkRBAC):
|
||||
|
||||
|
6
releasenotes/notes/bug-1648307-a2c6d7698e927449.yaml
Normal file
6
releasenotes/notes/bug-1648307-a2c6d7698e927449.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--type``, ``--action``, ``--long`` options
|
||||
to ``network rbac list`` command
|
||||
[Bug `1648307 <https://bugs.launchpad.net/bugs/1648307>`_]
|
Loading…
Reference in New Issue
Block a user