From e8509d81ee0b541033411e744f633e769073530b Mon Sep 17 00:00:00 2001 From: Miguel Lavalle Date: Wed, 10 Feb 2021 17:40:39 -0600 Subject: [PATCH] Add 'address_group' type support to rbac commands Depends-On: https://review.opendev.org/c/openstack/neutron/+/772460 Change-Id: Icd5e96d180364b979d1e93fcb39f9133a41a06e5 --- openstackclient/network/v2/network_rbac.py | 22 ++++++++++++------- .../unit/network/v2/test_network_rbac.py | 6 ++++- ...ac-add-address-group-f9bb83238b5a7c1f.yaml | 4 ++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/rbac-add-address-group-f9bb83238b5a7c1f.yaml diff --git a/openstackclient/network/v2/network_rbac.py b/openstackclient/network/v2/network_rbac.py index b88ef019e0..4984e89d56 100644 --- a/openstackclient/network/v2/network_rbac.py +++ b/openstackclient/network/v2/network_rbac.py @@ -60,6 +60,10 @@ def _get_attrs(client_manager, parsed_args): object_id = network_client.find_subnet_pool( parsed_args.rbac_object, ignore_missing=False).id + if parsed_args.type == 'address_group': + object_id = network_client.find_address_group( + parsed_args.rbac_object, + ignore_missing=False).id attrs['object_id'] = object_id @@ -100,11 +104,12 @@ class CreateNetworkRBAC(command.ShowOne): '--type', metavar="", required=True, - choices=['address_scope', 'security_group', 'subnetpool', - 'qos_policy', 'network'], + choices=['address_group', 'address_scope', 'security_group', + 'subnetpool', 'qos_policy', 'network'], help=_('Type of the object that RBAC policy ' - 'affects ("address_scope", "security_group", "subnetpool",' - ' "qos_policy" or "network")') + 'affects ("address_group", "address_scope", ' + '"security_group", "subnetpool", "qos_policy" or ' + '"network")') ) parser.add_argument( '--action', @@ -193,11 +198,12 @@ class ListNetworkRBAC(command.Lister): parser.add_argument( '--type', metavar='', - choices=['address_scope', 'security_group', 'subnetpool', - 'qos_policy', 'network'], + choices=['address_group', 'address_scope', 'security_group', + 'subnetpool', 'qos_policy', 'network'], help=_('List network RBAC policies according to ' - 'given object type ("address_scope", "security_group", ' - '"subnetpool", "qos_policy" or "network")') + 'given object type ("address_group", "address_scope", ' + '"security_group", "subnetpool", "qos_policy" or ' + '"network")') ) parser.add_argument( '--action', diff --git a/openstackclient/tests/unit/network/v2/test_network_rbac.py b/openstackclient/tests/unit/network/v2/test_network_rbac.py index d7c71ea7d0..08be64c516 100644 --- a/openstackclient/tests/unit/network/v2/test_network_rbac.py +++ b/openstackclient/tests/unit/network/v2/test_network_rbac.py @@ -42,6 +42,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC): sg_object = network_fakes.FakeNetworkSecGroup.create_one_security_group() as_object = network_fakes.FakeAddressScope.create_one_address_scope() snp_object = network_fakes.FakeSubnetPool.create_one_subnet_pool() + ag_object = network_fakes.FakeAddressGroup.create_one_address_group() project = identity_fakes_v3.FakeProject.create_one_project() rbac_policy = network_fakes.FakeNetworkRBAC.create_one_network_rbac( attrs={'tenant_id': project.id, @@ -85,6 +86,8 @@ class TestCreateNetworkRBAC(TestNetworkRBAC): return_value=self.as_object) self.network.find_subnet_pool = mock.Mock( return_value=self.snp_object) + self.network.find_address_group = mock.Mock( + return_value=self.ag_object) self.projects_mock.get.return_value = self.project def test_network_rbac_create_no_type(self): @@ -236,7 +239,8 @@ class TestCreateNetworkRBAC(TestNetworkRBAC): ('qos_policy', "qos_object"), ('security_group', "sg_object"), ('subnetpool', "snp_object"), - ('address_scope', "as_object") + ('address_scope', "as_object"), + ('address_group', "ag_object") ) @ddt.unpack def test_network_rbac_create_object(self, obj_type, obj_fake_attr): diff --git a/releasenotes/notes/rbac-add-address-group-f9bb83238b5a7c1f.yaml b/releasenotes/notes/rbac-add-address-group-f9bb83238b5a7c1f.yaml new file mode 100644 index 0000000000..d25da2f005 --- /dev/null +++ b/releasenotes/notes/rbac-add-address-group-f9bb83238b5a7c1f.yaml @@ -0,0 +1,4 @@ +features: + - | + Add ``address_group`` as a valid ``--type`` value for the + ``network rbac create`` and ``network rbac list`` commands.