De-client-ify User Update

Change-Id: I2f0917eed4464944b4552972baca838be8e6866e
This commit is contained in:
Samuel de Medeiros Queiroz 2017-08-30 16:56:06 -03:00
parent 78a1aa3b93
commit ca0103a0a2
4 changed files with 19 additions and 29 deletions

View File

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

View File

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

View File

@ -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),

View File

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