diff options
-rw-r--r-- | doc/source/command-objects/user.rst | 7 | ||||
-rw-r--r-- | openstackclient/identity/v3/user.py | 23 | ||||
-rw-r--r-- | openstackclient/tests/unit/identity/v3/test_user.py | 36 | ||||
-rw-r--r-- | releasenotes/notes/bug-1658147-9de9ae222f9db9ae.yaml | 6 |
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>`_] |