Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 1 | # Copyright 2013 OpenStack Foundation |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 16 | """ |
| 17 | http://developer.openstack.org/api-ref-identity-v3.html#groups-v3 |
| 18 | """ |
| 19 | |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 20 | from oslo_serialization import jsonutils as json |
| 21 | |
| 22 | from tempest.common import service_client |
| 23 | |
| 24 | |
| 25 | class GroupsClient(service_client.ServiceClient): |
| 26 | api_version = "v3" |
| 27 | |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 28 | def create_group(self, **kwargs): |
| 29 | """Creates a group. |
| 30 | |
| 31 | Available params: see http://developer.openstack.org/ |
| 32 | api-ref-identity-v3.html#createGroup |
| 33 | """ |
| 34 | post_body = json.dumps({'group': kwargs}) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 35 | resp, body = self.post('groups', post_body) |
| 36 | self.expected_success(201, resp.status) |
| 37 | body = json.loads(body) |
| 38 | return service_client.ResponseBody(resp, body) |
| 39 | |
Yaroslav Lobankov | 937438c | 2015-11-20 11:21:11 +0300 | [diff] [blame] | 40 | def show_group(self, group_id): |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 41 | """Get group details.""" |
| 42 | resp, body = self.get('groups/%s' % group_id) |
| 43 | self.expected_success(200, resp.status) |
| 44 | body = json.loads(body) |
| 45 | return service_client.ResponseBody(resp, body) |
| 46 | |
| 47 | def list_groups(self): |
| 48 | """Lists the groups.""" |
| 49 | resp, body = self.get('groups') |
| 50 | self.expected_success(200, resp.status) |
| 51 | body = json.loads(body) |
| 52 | return service_client.ResponseBody(resp, body) |
| 53 | |
| 54 | def update_group(self, group_id, **kwargs): |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 55 | """Updates a group. |
| 56 | |
| 57 | Available params: see http://developer.openstack.org/ |
| 58 | api-ref-identity-v3.html#updateGroup |
| 59 | """ |
| 60 | post_body = json.dumps({'group': kwargs}) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 61 | resp, body = self.patch('groups/%s' % group_id, post_body) |
| 62 | self.expected_success(200, resp.status) |
| 63 | body = json.loads(body) |
| 64 | return service_client.ResponseBody(resp, body) |
| 65 | |
| 66 | def delete_group(self, group_id): |
| 67 | """Delete a group.""" |
| 68 | resp, body = self.delete('groups/%s' % str(group_id)) |
| 69 | self.expected_success(204, resp.status) |
| 70 | return service_client.ResponseBody(resp, body) |
| 71 | |
| 72 | def add_group_user(self, group_id, user_id): |
| 73 | """Add user into group.""" |
| 74 | resp, body = self.put('groups/%s/users/%s' % (group_id, user_id), |
| 75 | None) |
| 76 | self.expected_success(204, resp.status) |
| 77 | return service_client.ResponseBody(resp, body) |
| 78 | |
| 79 | def list_group_users(self, group_id): |
| 80 | """List users in group.""" |
| 81 | resp, body = self.get('groups/%s/users' % group_id) |
| 82 | self.expected_success(200, resp.status) |
| 83 | body = json.loads(body) |
| 84 | return service_client.ResponseBody(resp, body) |
| 85 | |
| 86 | def delete_group_user(self, group_id, user_id): |
| 87 | """Delete user in group.""" |
| 88 | resp, body = self.delete('groups/%s/users/%s' % (group_id, user_id)) |
| 89 | self.expected_success(204, resp.status) |
| 90 | return service_client.ResponseBody(resp, body) |
Maho Koshiya | b6fa2e4 | 2015-12-07 16:52:53 +0900 | [diff] [blame] | 91 | |
| 92 | def check_group_user_existence(self, group_id, user_id): |
| 93 | """Check user in group.""" |
| 94 | resp, body = self.head('groups/%s/users/%s' % (group_id, user_id)) |
| 95 | self.expected_success(204, resp.status) |
| 96 | return service_client.ResponseBody(resp) |