Now we can add description for role creation in OSC

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.

Co-Authored-By: Deepak Mourya<deepakmoriya7@gmail.com>
Change-Id: I858e004c3b29c687b6a39c8a1ed5fb029eb19c67
Depends-on: I230af9cc833af13064636b5d9a7ce6334c3f6e9a
Closes-Bug: #1669080
This commit is contained in:
M V P Nitesh 2017-07-17 18:08:58 +05:30 committed by deepak_mourya
parent 1b66ad9067
commit eb001733fd
7 changed files with 132 additions and 3 deletions

View File

@ -115,6 +115,10 @@ Create new role
New role name
.. option:: --description <description>
Add description about the role
role delete
-----------

View File

@ -177,6 +177,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>',
@ -199,7 +204,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:
@ -449,6 +455,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>',
@ -473,7 +484,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):

View File

@ -32,7 +32,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',

View File

@ -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)
@ -88,6 +103,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()

View File

@ -175,6 +175,7 @@ ids_for_children = [PROJECT_WITH_GRANDPARENT['id']]
role_id = 'r1'
role_name = 'roller'
role_description = 'role description'
ROLE = {
'id': role_id,

View File

@ -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):
@ -1057,6 +1102,7 @@ class TestRoleSet(TestRole):
# Set expected values
kwargs = {
'name': 'over',
'description': None,
}
# RoleManager.update(role, name=)
self.roles_mock.update.assert_called_with(
@ -1088,6 +1134,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(

View File

@ -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.