Add 'address_group' type support to rbac commands

Depends-On: https://review.opendev.org/c/openstack/neutron/+/772460
Change-Id: Icd5e96d180364b979d1e93fcb39f9133a41a06e5
This commit is contained in:
Miguel Lavalle 2021-02-10 17:40:39 -06:00
parent 01a53fa96f
commit e8509d81ee
3 changed files with 23 additions and 9 deletions

View File

@ -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="<type>",
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='<type>',
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',

View File

@ -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):

View File

@ -0,0 +1,4 @@
features:
- |
Add ``address_group`` as a valid ``--type`` value for the
``network rbac create`` and ``network rbac list`` commands.