Merge "Allow input the QoS policy name in network rbac create command"

This commit is contained in:
Jenkins 2016-11-10 18:09:00 +00:00 committed by Gerrit Code Review
commit f3d3813522
4 changed files with 49 additions and 6 deletions

View File

@ -52,7 +52,7 @@ Create network RBAC policy
.. _network_rbac_create-rbac-policy:
.. describe:: <rbac-object>
The object to which this RBAC policy affects (name or ID for network objects, ID only for QoS policy objects)
The object to which this RBAC policy affects (name or ID)
network rbac delete
-------------------

View File

@ -47,9 +47,9 @@ def _get_attrs(client_manager, parsed_args):
object_id = network_client.find_network(
parsed_args.rbac_object, ignore_missing=False).id
if parsed_args.type == 'qos_policy':
# TODO(Huanxuan Ao): Support finding a object ID by obejct name
# after qos policy finding supported in SDK.
object_id = parsed_args.rbac_object
object_id = network_client.find_qos_policy(
parsed_args.rbac_object,
ignore_missing=False).id
attrs['object_id'] = object_id
identity_client = client_manager.identity
@ -78,8 +78,7 @@ class CreateNetworkRBAC(command.ShowOne):
parser.add_argument(
'rbac_object',
metavar="<rbac-object>",
help=_("The object to which this RBAC policy affects (name or "
"ID for network objects, ID only for QoS policy objects)")
help=_("The object to which this RBAC policy affects (name or ID)")
)
parser.add_argument(
'--type',

View File

@ -36,6 +36,7 @@ class TestNetworkRBAC(network_fakes.TestNetworkV2):
class TestCreateNetworkRBAC(TestNetworkRBAC):
network_object = network_fakes.FakeNetwork.create_one_network()
qos_object = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
project = identity_fakes_v3.FakeProject.create_one_project()
rbac_policy = network_fakes.FakeNetworkRBAC.create_one_network_rbac(
attrs={'tenant_id': project.id,
@ -71,6 +72,8 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
return_value=self.rbac_policy)
self.network.find_network = mock.Mock(
return_value=self.network_object)
self.network.find_qos_policy = mock.Mock(
return_value=self.qos_object)
self.projects_mock.get.return_value = self.project
def test_network_rbac_create_no_type(self):
@ -194,6 +197,43 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_network_rbac_create_qos_object(self):
self.rbac_policy.object_type = 'qos_policy'
self.rbac_policy.object_id = self.qos_object.id
arglist = [
'--type', 'qos_policy',
'--action', self.rbac_policy.action,
'--target-project', self.rbac_policy.target_tenant,
self.qos_object.name,
]
verifylist = [
('type', 'qos_policy'),
('action', self.rbac_policy.action),
('target_project', self.rbac_policy.target_tenant),
('rbac_object', self.qos_object.name),
]
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.create_rbac_policy.assert_called_with(**{
'object_id': self.qos_object.id,
'object_type': 'qos_policy',
'action': self.rbac_policy.action,
'target_tenant': self.rbac_policy.target_tenant,
})
self.data = [
self.rbac_policy.action,
self.rbac_policy.id,
self.qos_object.id,
'qos_policy',
self.rbac_policy.tenant_id,
self.rbac_policy.target_tenant,
]
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
class TestDeleteNetworkRBAC(TestNetworkRBAC):

View File

@ -0,0 +1,4 @@
---
features:
- |
``rbac_object`` parameter in ``network rbac create`` command now can be a QoS policy name.