Add 'subnetpool' type support to rbac commands

Change-Id: Id6e528ebd1bf21ca142e60052d28371f97f629ac
Partial-Bug: #1862032
Depends-On: https://review.opendev.org/710755
This commit is contained in:
Igor Malinovskiy 2020-02-27 17:50:48 +02:00
parent f03cb68ad8
commit 557e65d8eb
3 changed files with 18 additions and 5 deletions

View File

@ -62,6 +62,11 @@ def _get_attrs(client_manager, parsed_args):
object_id = network_client.find_address_scope(
parsed_args.rbac_object,
ignore_missing=False).id
if parsed_args.type == 'subnetpool':
object_id = network_client.find_subnet_pool(
parsed_args.rbac_object,
ignore_missing=False).id
attrs['object_id'] = object_id
identity_client = client_manager.identity
@ -101,11 +106,11 @@ class CreateNetworkRBAC(command.ShowOne):
'--type',
metavar="<type>",
required=True,
choices=['address_scope', 'security_group',
choices=['address_scope', 'security_group', 'subnetpool',
'qos_policy', 'network'],
help=_('Type of the object that RBAC policy '
'affects ("address_scope", "security_group", '
'"qos_policy" or "network")')
'affects ("address_scope", "security_group", "subnetpool",'
' "qos_policy" or "network")')
)
parser.add_argument(
'--action',
@ -194,11 +199,11 @@ class ListNetworkRBAC(command.Lister):
parser.add_argument(
'--type',
metavar='<type>',
choices=['address_scope', 'security_group',
choices=['address_scope', 'security_group', 'subnetpool',
'qos_policy', 'network'],
help=_('List network RBAC policies according to '
'given object type ("address_scope", "security_group", '
'"qos_policy" or "network")')
'"subnetpool", "qos_policy" or "network")')
)
parser.add_argument(
'--action',

View File

@ -41,6 +41,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
qos_object = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
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()
project = identity_fakes_v3.FakeProject.create_one_project()
rbac_policy = network_fakes.FakeNetworkRBAC.create_one_network_rbac(
attrs={'tenant_id': project.id,
@ -82,6 +83,8 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
return_value=self.sg_object)
self.network.find_address_scope = mock.Mock(
return_value=self.as_object)
self.network.find_subnet_pool = mock.Mock(
return_value=self.snp_object)
self.projects_mock.get.return_value = self.project
def test_network_rbac_create_no_type(self):
@ -232,6 +235,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
@ddt.data(
('qos_policy', "qos_object"),
('security_group', "sg_object"),
('subnetpool', "snp_object"),
('address_scope', "as_object")
)
@ddt.unpack

View File

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