network: Add tenant project filter for RBAC list

Implements a new parser argument "--target-project" to
list RBAC policies for a specific tenant project only.
This uses the already existing server-side query
parameter "target_tenant".

Story: 2009937
Task: 44824
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/834442
Change-Id: I83ff07041a022e8795e3c5550c6a7aabb0c0d8c8
Signed-off-by: Jan Hartkopf <jhartkopf@inovex.de>
This commit is contained in:
Jan Hartkopf 2022-03-15 15:49:12 +01:00
parent 7df94c9f82
commit 4d7d7e627e
3 changed files with 39 additions and 0 deletions

View File

@ -217,6 +217,11 @@ class ListNetworkRBAC(command.Lister):
help=_('List network RBAC policies according to given '
'action ("access_as_external" or "access_as_shared")')
)
parser.add_argument(
'--target-project',
metavar='<target-project>',
help=_('List network RBAC policies for a specific target project')
)
parser.add_argument(
'--long',
action='store_true',
@ -247,6 +252,16 @@ class ListNetworkRBAC(command.Lister):
query['object_type'] = parsed_args.type
if parsed_args.action is not None:
query['action'] = parsed_args.action
if parsed_args.target_project is not None:
project_id = "*"
if parsed_args.target_project != "*":
identity_client = self.app.client_manager.identity
project_id = identity_common.find_project(
identity_client,
parsed_args.target_project,
).id
query['target_project_id'] = project_id
data = client.rbac_policies(**query)

View File

@ -405,6 +405,9 @@ class TestListNetworkRABC(TestNetworkRBAC):
self.network.rbac_policies = mock.Mock(return_value=self.rbac_policies)
self.project = identity_fakes_v3.FakeProject.create_one_project()
self.projects_mock.get.return_value = self.project
def test_network_rbac_list(self):
arglist = []
verifylist = []
@ -466,6 +469,22 @@ class TestListNetworkRABC(TestNetworkRBAC):
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
def test_network_rbac_list_target_project_opt(self):
arglist = [
'--target-project', self.rbac_policies[0].target_project_id, ]
verifylist = [
('target_project', self.rbac_policies[0].target_project_id)]
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(**{
'target_project_id': self.project.id
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
class TestSetNetworkRBAC(TestNetworkRBAC):

View File

@ -0,0 +1,5 @@
---
features:
- |
Add a new argument ``--target-project`` to the ``network rbac list``
command to filter for a specific target project.