Adds domain specification for SetUser

This patch adds the ability to specify the domain context for making
changes to a user with `--domain` flag.

Example:
$ openstack user set test_user --domain test_domain --enable

Change-Id: I2b3241785c22e72e19181394acff650422299b0e
Closes-Bug: #1658147
This commit is contained in:
Samuel Pilla 2017-01-25 10:40:49 -06:00 committed by Steve Martinelli
parent b69b539a42
commit 4cb56269ad
4 changed files with 68 additions and 4 deletions

View File

@ -153,6 +153,13 @@ Set user properties
Set user name
.. option:: --domain <domain>
Domain the user belongs to (name or ID).
This can be used in case collisions between user names exist.
.. versionadded:: 3
.. option:: --project <project>
Set default project (name or ID)

View File

@ -301,6 +301,12 @@ class SetUser(command.Command):
metavar='<name>',
help=_('Set user name'),
)
parser.add_argument(
'--domain',
metavar='<domain>',
help=_('Domain the user belongs to (name or ID). This can be '
'used in case collisions between user names exist.'),
)
parser.add_argument(
'--project',
metavar='<project>',
@ -351,10 +357,19 @@ class SetUser(command.Command):
LOG.warning(_("No password was supplied, authentication will fail "
"when a user does not have a password."))
user = utils.find_resource(
identity_client.users,
parsed_args.user,
)
user_str = common._get_token_resource(identity_client, 'user',
parsed_args.user)
if parsed_args.domain:
domain = common.find_domain(identity_client, parsed_args.domain)
user = utils.find_resource(identity_client.users,
user_str,
domain_id=domain.id)
else:
user = utils.find_resource(
identity_client.users,
parsed_args.user,
)
kwargs = {}
if parsed_args.name:
kwargs['name'] = parsed_args.name

View File

@ -684,9 +684,14 @@ class TestUserList(TestUser):
class TestUserSet(TestUser):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
user = identity_fakes.FakeUser.create_one_user(
attrs={'default_project_id': project.id}
)
user2 = identity_fakes.FakeUser.create_one_user(
attrs={'default_project_id': project.id,
'domain_id': domain.id}
)
def setUp(self):
super(TestUserSet, self).setUp()
@ -748,6 +753,37 @@ class TestUserSet(TestUser):
)
self.assertIsNone(result)
def test_user_set_specify_domain(self):
arglist = [
'--name', 'qwerty',
'--domain', self.domain.id,
self.user2.name
]
verifylist = [
('name', 'qwerty'),
('password', None),
('domain', self.domain.id),
('email', None),
('project', None),
('enable', False),
('disable', False),
('user', self.user2.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
kwargs = {
'enabled': True,
'name': 'qwerty'
}
self.users_mock.update.assert_called_with(
self.user.id,
**kwargs
)
self.assertIsNone(result)
def test_user_set_password(self):
arglist = [
'--password', 'secret',

View File

@ -0,0 +1,6 @@
---
features:
- |
Add ``--domain`` options to the ``user set`` command.
Allows specification of domain context when changing users.
[Bug `1658147 <https://bugs.launchpad.net/bugs/1658147>`_]