summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Pilla <sp516w@att.com>2017-01-25 10:40:49 -0600
committerSteve Martinelli <s.martinelli@gmail.com>2017-01-25 22:16:22 +0000
commit4cb56269ad30d0bd59f7685040ab0585f38c3b0f (patch)
tree50c8d3b27fe32e36a2f85c8079442178b6fd190c
parentb69b539a422860bfb402093ff9d93a1b6e338b26 (diff)
downloadpython-openstackclient-4cb56269ad30d0bd59f7685040ab0585f38c3b0f.tar.gz
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
-rw-r--r--doc/source/command-objects/user.rst7
-rw-r--r--openstackclient/identity/v3/user.py23
-rw-r--r--openstackclient/tests/unit/identity/v3/test_user.py36
-rw-r--r--releasenotes/notes/bug-1658147-9de9ae222f9db9ae.yaml6
4 files changed, 68 insertions, 4 deletions
diff --git a/doc/source/command-objects/user.rst b/doc/source/command-objects/user.rst
index 7e0ee21b..632d0e25 100644
--- a/doc/source/command-objects/user.rst
+++ b/doc/source/command-objects/user.rst
@@ -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)
diff --git a/openstackclient/identity/v3/user.py b/openstackclient/identity/v3/user.py
index 19a4c298..9c289a6d 100644
--- a/openstackclient/identity/v3/user.py
+++ b/openstackclient/identity/v3/user.py
@@ -302,6 +302,12 @@ class SetUser(command.Command):
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>',
help=_('Set default project (name or ID)'),
@@ -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
diff --git a/openstackclient/tests/unit/identity/v3/test_user.py b/openstackclient/tests/unit/identity/v3/test_user.py
index 3c1f49a6..2ce66e94 100644
--- a/openstackclient/tests/unit/identity/v3/test_user.py
+++ b/openstackclient/tests/unit/identity/v3/test_user.py
@@ -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',
diff --git a/releasenotes/notes/bug-1658147-9de9ae222f9db9ae.yaml b/releasenotes/notes/bug-1658147-9de9ae222f9db9ae.yaml
new file mode 100644
index 00000000..f46305ab
--- /dev/null
+++ b/releasenotes/notes/bug-1658147-9de9ae222f9db9ae.yaml
@@ -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>`_]