From ca0103a0a2e4f2772895f904b52e02cd6cd2ccc4 Mon Sep 17 00:00:00 2001 From: Samuel de Medeiros Queiroz Date: Wed, 30 Aug 2017 16:56:06 -0300 Subject: [PATCH] De-client-ify User Update Change-Id: I2f0917eed4464944b4552972baca838be8e6866e --- shade/_tasks.py | 10 ---------- shade/openstackcloud.py | 30 ++++++++++++++++++------------ shade/tests/unit/test_caching.py | 4 ---- shade/tests/unit/test_users.py | 4 +--- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/shade/_tasks.py b/shade/_tasks.py index 6c5e962dc..2334c032b 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -17,16 +17,6 @@ from shade import task_manager -class UserCreate(task_manager.Task): - def main(self, client): - return client.keystone_client.users.create(**self.args) - - -class UserUpdate(task_manager.Task): - def main(self, client): - return client.keystone_client.users.update(**self.args) - - class UserPasswordUpdate(task_manager.Task): def main(self, client): return client.keystone_client.users.update_password(**self.args) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 9fd9be757..20ab4a0fd 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -1046,13 +1046,11 @@ class OpenStackCloud( if 'domain_id' in kwargs and kwargs['domain_id']: user_kwargs['domain_id'] = kwargs['domain_id'] user = self.get_user(name_or_id, **user_kwargs) - # normalized dict won't work - kwargs['user'] = self.get_user_by_id(user['id'], normalize=False) # TODO(mordred) When this changes to REST, force interface=admin # in the adapter call if it's an admin force call (and figure out how # to make that disctinction) - if not self._is_client_version('identity', 3): + if self._is_client_version('identity', 2): # Do not pass v3 args to a v2 keystone. kwargs.pop('domain_id', None) kwargs.pop('description', None) @@ -1062,17 +1060,25 @@ class OpenStackCloud( with _utils.shade_exceptions( "Error updating password for {user}".format( user=name_or_id)): + # normalized dict won't work user = self.manager.submit_task(_tasks.UserPasswordUpdate( - user=kwargs['user'], password=password)) - elif 'domain_id' in kwargs: - # The incoming parameter is domain_id in order to match the - # parameter name in create_user(), but UserUpdate() needs it - # to be domain. - kwargs['domain'] = kwargs.pop('domain_id') + user=self.get_user_by_id(user['id'], normalize=False), + password=password)) - with _utils.shade_exceptions("Error in updating user {user}".format( - user=name_or_id)): - user = self.manager.submit_task(_tasks.UserUpdate(**kwargs)) + # Identity v2.0 implements PUT. v3 PATCH. Both work as PATCH. + data = self._identity_client.put( + '/users/{user}'.format(user=user['id']), json={'user': kwargs}, + error_message="Error in updating user {}".format(name_or_id)) + else: + # NOTE(samueldmq): now this is a REST call and domain_id is dropped + # if None. keystoneclient drops keys with None values. + if 'domain_id' in kwargs and kwargs['domain_id'] is None: + del kwargs['domain_id'] + data = self._identity_client.patch( + '/users/{user}'.format(user=user['id']), json={'user': kwargs}, + error_message="Error in updating user {}".format(name_or_id)) + + user = self._get_and_munchify('user', data) self.list_users.invalidate(self) return _utils.normalize_users([user])[0] diff --git a/shade/tests/unit/test_caching.py b/shade/tests/unit/test_caching.py index 11c01f5c1..97fe4bb10 100644 --- a/shade/tests/unit/test_caching.py +++ b/shade/tests/unit/test_caching.py @@ -376,12 +376,8 @@ class TestMemoryCache(base.RequestsMockTestCase): # Get updated user dict(method='GET', uri=mock_users_url, status_code=200, json=users_list_resp), - dict(method='GET', uri=mock_user_resource_url, status_code=200, - json=user_data.json_response), dict(method='PUT', uri=mock_user_resource_url, status_code=200, json=new_resp, validate=dict(json=new_req)), - dict(method='GET', uri=mock_user_resource_url, status_code=200, - json=new_resp), # List Users Call dict(method='GET', uri=mock_users_url, status_code=200, json=updated_users_list_resp), diff --git a/shade/tests/unit/test_users.py b/shade/tests/unit/test_users.py index e1da45625..4923946a6 100644 --- a/shade/tests/unit/test_users.py +++ b/shade/tests/unit/test_users.py @@ -119,9 +119,7 @@ class TestUsers(base.RequestsMockTestCase): json=user_data.json_response), dict(method='PUT', uri=mock_user_resource_uri, status_code=200, json=user_data.json_response, - validate=dict(json={'user': {}})), - dict(method='GET', uri=mock_user_resource_uri, status_code=200, - json=user_data.json_response)]) + validate=dict(json={'user': {}}))]) user = self.op_cloud.update_user( user_data.user_id, password=user_data.password)