Merge "Now we can add description for role creation in OSC"
This commit is contained in:
commit
fc12033f1d
@ -115,6 +115,10 @@ Create new role
|
||||
|
||||
New role name
|
||||
|
||||
.. option:: --description <description>
|
||||
|
||||
Add description about the role
|
||||
|
||||
role delete
|
||||
-----------
|
||||
|
||||
|
@ -176,6 +176,11 @@ class CreateRole(command.ShowOne):
|
||||
metavar='<role-name>',
|
||||
help=_('New role name'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_('Add description about the role'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--domain',
|
||||
metavar='<domain>',
|
||||
@ -198,7 +203,8 @@ class CreateRole(command.ShowOne):
|
||||
|
||||
try:
|
||||
role = identity_client.roles.create(
|
||||
name=parsed_args.name, domain=domain_id)
|
||||
name=parsed_args.name, domain=domain_id,
|
||||
description=parsed_args.description)
|
||||
|
||||
except ks_exc.Conflict:
|
||||
if parsed_args.or_show:
|
||||
@ -345,6 +351,11 @@ class SetRole(command.Command):
|
||||
metavar='<role>',
|
||||
help=_('Role to modify (name or ID)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_('Add description about the role'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--domain',
|
||||
metavar='<domain>',
|
||||
@ -369,7 +380,8 @@ class SetRole(command.Command):
|
||||
parsed_args.role,
|
||||
domain_id=domain_id)
|
||||
|
||||
identity_client.roles.update(role.id, name=parsed_args.name)
|
||||
identity_client.roles.update(role.id, name=parsed_args.name,
|
||||
description=parsed_args.description)
|
||||
|
||||
|
||||
class ShowRole(command.ShowOne):
|
||||
|
@ -33,7 +33,7 @@ class IdentityTests(base.TestCase):
|
||||
'password_expires_at']
|
||||
PROJECT_FIELDS = ['description', 'id', 'domain_id', 'is_domain',
|
||||
'enabled', 'name', 'parent_id']
|
||||
ROLE_FIELDS = ['id', 'name', 'domain_id']
|
||||
ROLE_FIELDS = ['id', 'name', 'domain_id', 'description']
|
||||
SERVICE_FIELDS = ['id', 'enabled', 'name', 'type', 'description']
|
||||
REGION_FIELDS = ['description', 'enabled', 'parent_region', 'region']
|
||||
ENDPOINT_FIELDS = ['id', 'region', 'region_id', 'service_id',
|
||||
|
@ -20,6 +20,21 @@ class RoleTests(common.IdentityTests):
|
||||
def test_role_create(self):
|
||||
self._create_dummy_role()
|
||||
|
||||
def test_role_create_with_description(self):
|
||||
role_name = data_utils.rand_name('TestRole')
|
||||
description = data_utils.rand_name('description')
|
||||
raw_output = self.openstack(
|
||||
'role create '
|
||||
'--description %(description)s '
|
||||
'%(name)s' % {'description': description,
|
||||
'name': role_name})
|
||||
role = self.parse_show_as_object(raw_output)
|
||||
self.addCleanup(self.openstack, 'role delete %s' % role['id'])
|
||||
items = self.parse_show(raw_output)
|
||||
self.assert_show_fields(items, self.ROLE_FIELDS)
|
||||
self.assertEqual(description, role['description'])
|
||||
return role_name
|
||||
|
||||
def test_role_delete(self):
|
||||
role_name = self._create_dummy_role(add_clean_up=False)
|
||||
raw_output = self.openstack('role delete %s' % role_name)
|
||||
@ -47,6 +62,16 @@ class RoleTests(common.IdentityTests):
|
||||
role = self.parse_show_as_object(raw_output)
|
||||
self.assertEqual(new_role_name, role['name'])
|
||||
|
||||
def test_role_set_description(self):
|
||||
role_name = self._create_dummy_role()
|
||||
description = data_utils.rand_name("NewDescription")
|
||||
raw_output = self.openstack('role set --description %s %s'
|
||||
% (description, role_name))
|
||||
self.assertEqual(0, len(raw_output))
|
||||
raw_output = self.openstack('role show %s' % role_name)
|
||||
role = self.parse_show_as_object(raw_output)
|
||||
self.assertEqual(description, role['description'])
|
||||
|
||||
def test_role_add(self):
|
||||
role_name = self._create_dummy_role()
|
||||
username = self._create_dummy_user()
|
||||
|
@ -176,6 +176,7 @@ ids_for_children = [PROJECT_WITH_GRANDPARENT['id']]
|
||||
|
||||
role_id = 'r1'
|
||||
role_name = 'roller'
|
||||
role_description = 'role description'
|
||||
|
||||
ROLE = {
|
||||
'id': role_id,
|
||||
|
@ -332,6 +332,7 @@ class TestRoleCreate(TestRole):
|
||||
kwargs = {
|
||||
'domain': None,
|
||||
'name': identity_fakes.role_name,
|
||||
'description': None,
|
||||
}
|
||||
|
||||
# RoleManager.create(name=, domain=)
|
||||
@ -375,6 +376,7 @@ class TestRoleCreate(TestRole):
|
||||
kwargs = {
|
||||
'domain': identity_fakes.domain_id,
|
||||
'name': identity_fakes.ROLE_2['name'],
|
||||
'description': None,
|
||||
}
|
||||
|
||||
# RoleManager.create(name=, domain=)
|
||||
@ -391,6 +393,49 @@ class TestRoleCreate(TestRole):
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
def test_role_create_with_description(self):
|
||||
|
||||
self.roles_mock.create.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE_2),
|
||||
loaded=True,
|
||||
)
|
||||
arglist = [
|
||||
'--description', identity_fakes.role_description,
|
||||
identity_fakes.ROLE_2['name'],
|
||||
]
|
||||
verifylist = [
|
||||
('description', identity_fakes.role_description),
|
||||
('name', identity_fakes.ROLE_2['name']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# In base command class ShowOne in cliff, abstract method take_action()
|
||||
# returns a two-part tuple with a tuple of column names and a tuple of
|
||||
# data to be shown.
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
# Set expected values
|
||||
kwargs = {
|
||||
'description': identity_fakes.role_description,
|
||||
'name': identity_fakes.ROLE_2['name'],
|
||||
'domain': None,
|
||||
}
|
||||
|
||||
# RoleManager.create(name=, domain=)
|
||||
self.roles_mock.create.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
|
||||
collist = ('domain', 'id', 'name')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
'd1',
|
||||
identity_fakes.ROLE_2['id'],
|
||||
identity_fakes.ROLE_2['name'],
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
|
||||
class TestRoleDelete(TestRole):
|
||||
|
||||
@ -825,6 +870,7 @@ class TestRoleSet(TestRole):
|
||||
# Set expected values
|
||||
kwargs = {
|
||||
'name': 'over',
|
||||
'description': None,
|
||||
}
|
||||
# RoleManager.update(role, name=)
|
||||
self.roles_mock.update.assert_called_with(
|
||||
@ -856,6 +902,39 @@ class TestRoleSet(TestRole):
|
||||
# Set expected values
|
||||
kwargs = {
|
||||
'name': 'over',
|
||||
'description': None,
|
||||
}
|
||||
# RoleManager.update(role, name=)
|
||||
self.roles_mock.update.assert_called_with(
|
||||
identity_fakes.ROLE_2['id'],
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_role_set_description(self):
|
||||
self.roles_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE_2),
|
||||
loaded=True,
|
||||
)
|
||||
arglist = [
|
||||
'--name', 'over',
|
||||
'--description', identity_fakes.role_description,
|
||||
identity_fakes.ROLE_2['name'],
|
||||
]
|
||||
verifylist = [
|
||||
('name', 'over'),
|
||||
('description', identity_fakes.role_description),
|
||||
('role', identity_fakes.ROLE_2['name']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
# Set expected values
|
||||
kwargs = {
|
||||
'name': 'over',
|
||||
'description': identity_fakes.role_description,
|
||||
}
|
||||
# RoleManager.update(role, name=)
|
||||
self.roles_mock.update.assert_called_with(
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Now user can add the description when user create's
|
||||
the role using OSC ``openstack role create`` command.
|
||||
User can add the description by adding
|
||||
`--description <Description>` to OSC
|
||||
``openstack role create`` command.
|
Loading…
Reference in New Issue
Block a user