Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | from oslo_serialization import jsonutils as json |
| 14 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 15 | from tempest.lib.common import rest_client |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 16 | |
| 17 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 18 | class UsersClient(rest_client.RestClient): |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 19 | api_version = "v2.0" |
| 20 | |
| 21 | def create_user(self, name, password, tenant_id, email, **kwargs): |
| 22 | """Create a user.""" |
| 23 | post_body = { |
| 24 | 'name': name, |
| 25 | 'password': password, |
| 26 | 'email': email |
| 27 | } |
| 28 | if tenant_id is not None: |
| 29 | post_body['tenantId'] = tenant_id |
| 30 | if kwargs.get('enabled') is not None: |
| 31 | post_body['enabled'] = kwargs.get('enabled') |
| 32 | post_body = json.dumps({'user': post_body}) |
| 33 | resp, body = self.post('users', post_body) |
| 34 | self.expected_success(200, resp.status) |
| 35 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 36 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 37 | |
| 38 | def update_user(self, user_id, **kwargs): |
zhufl | 7daa31e | 2016-06-14 17:24:42 +0800 | [diff] [blame] | 39 | """Updates a user. |
| 40 | |
| 41 | Available params: see http://developer.openstack.org/ |
| 42 | api-ref-identity-admin-v2.html#admin-updateUser |
| 43 | """ |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 44 | put_body = json.dumps({'user': kwargs}) |
| 45 | resp, body = self.put('users/%s' % user_id, put_body) |
| 46 | self.expected_success(200, resp.status) |
| 47 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 48 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 49 | |
| 50 | def show_user(self, user_id): |
| 51 | """GET a user.""" |
| 52 | resp, body = self.get("users/%s" % user_id) |
| 53 | self.expected_success(200, resp.status) |
| 54 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 55 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 56 | |
| 57 | def delete_user(self, user_id): |
| 58 | """Delete a user.""" |
| 59 | resp, body = self.delete("users/%s" % user_id) |
| 60 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 61 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 62 | |
| 63 | def list_users(self): |
| 64 | """Get the list of users.""" |
| 65 | resp, body = self.get("users") |
| 66 | self.expected_success(200, resp.status) |
| 67 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 68 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 69 | |
| 70 | def enable_disable_user(self, user_id, **kwargs): |
| 71 | """Enables or disables a user. |
| 72 | |
| 73 | Available params: see http://developer.openstack.org/ |
| 74 | api-ref-identity-v2-ext.html#enableUser |
| 75 | """ |
| 76 | # NOTE: The URL (users/<id>/enabled) is different from the api-site |
| 77 | # one (users/<id>/OS-KSADM/enabled) , but they are the same API |
| 78 | # because of the fact that in keystone/contrib/admin_crud/core.py |
| 79 | # both api use same action='set_user_enabled' |
| 80 | put_body = json.dumps({'user': kwargs}) |
| 81 | resp, body = self.put('users/%s/enabled' % user_id, put_body) |
| 82 | self.expected_success(200, resp.status) |
| 83 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 84 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 85 | |
| 86 | def update_user_password(self, user_id, **kwargs): |
| 87 | """Update User Password.""" |
| 88 | # TODO(piyush): Current api-site doesn't contain this API description. |
| 89 | # After fixing the api-site, we need to fix here also for putting the |
| 90 | # link to api-site. |
| 91 | # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524147 |
| 92 | put_body = json.dumps({'user': kwargs}) |
| 93 | resp, body = self.put('users/%s/OS-KSADM/password' % user_id, put_body) |
| 94 | self.expected_success(200, resp.status) |
| 95 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 96 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 97 | |
| 98 | def update_user_own_password(self, user_id, **kwargs): |
| 99 | """User updates own password""" |
| 100 | # TODO(piyush): Current api-site doesn't contain this API description. |
| 101 | # After fixing the api-site, we need to fix here also for putting the |
| 102 | # link to api-site. |
| 103 | # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524153 |
| 104 | # NOTE: This API is used for updating user password by itself. |
| 105 | # Ref: http://lists.openstack.org/pipermail/openstack-dev/2015-December |
| 106 | # /081803.html |
| 107 | patch_body = json.dumps({'user': kwargs}) |
| 108 | resp, body = self.patch('OS-KSCRUD/users/%s' % user_id, patch_body) |
| 109 | self.expected_success(200, resp.status) |
| 110 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 111 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 112 | |
| 113 | def create_user_ec2_credentials(self, user_id, **kwargs): |
| 114 | # TODO(piyush): Current api-site doesn't contain this API description. |
| 115 | # After fixing the api-site, we need to fix here also for putting the |
| 116 | # link to api-site. |
| 117 | post_body = json.dumps(kwargs) |
| 118 | resp, body = self.post('/users/%s/credentials/OS-EC2' % user_id, |
| 119 | post_body) |
| 120 | self.expected_success(200, resp.status) |
| 121 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 122 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 123 | |
| 124 | def delete_user_ec2_credentials(self, user_id, access): |
| 125 | resp, body = self.delete('/users/%s/credentials/OS-EC2/%s' % |
| 126 | (user_id, access)) |
| 127 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 128 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 129 | |
| 130 | def list_user_ec2_credentials(self, user_id): |
| 131 | resp, body = self.get('/users/%s/credentials/OS-EC2' % user_id) |
| 132 | self.expected_success(200, resp.status) |
| 133 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 134 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 135 | |
| 136 | def show_user_ec2_credentials(self, user_id, access): |
| 137 | resp, body = self.get('/users/%s/credentials/OS-EC2/%s' % |
| 138 | (user_id, access)) |
| 139 | self.expected_success(200, resp.status) |
| 140 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 141 | return rest_client.ResponseBody(resp, body) |