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 |
ghanshyam | 83e94d4 | 2016-08-01 16:48:06 +0900 | [diff] [blame] | 21 | from six.moves.urllib import parse as urllib |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 22 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 23 | from tempest.lib.common import rest_client |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 24 | |
| 25 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 26 | class GroupsClient(rest_client.RestClient): |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 27 | api_version = "v3" |
| 28 | |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 29 | def create_group(self, **kwargs): |
| 30 | """Creates a group. |
| 31 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 32 | For a full list of available parameters, please refer to the official |
| 33 | API reference: |
| 34 | http://developer.openstack.org/api-ref/identity/v3/index.html#create-group |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 35 | """ |
| 36 | post_body = json.dumps({'group': kwargs}) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 37 | resp, body = self.post('groups', post_body) |
| 38 | self.expected_success(201, resp.status) |
| 39 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 40 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 41 | |
Yaroslav Lobankov | 937438c | 2015-11-20 11:21:11 +0300 | [diff] [blame] | 42 | def show_group(self, group_id): |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 43 | """Get group details.""" |
| 44 | resp, body = self.get('groups/%s' % group_id) |
| 45 | self.expected_success(200, resp.status) |
| 46 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 47 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 48 | |
ghanshyam | 83e94d4 | 2016-08-01 16:48:06 +0900 | [diff] [blame] | 49 | def list_groups(self, **params): |
| 50 | """Lists the groups. |
| 51 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 52 | For a full list of available parameters, please refer to the official |
| 53 | API reference: |
| 54 | http://developer.openstack.org/api-ref/identity/v3/#list-groups |
ghanshyam | 83e94d4 | 2016-08-01 16:48:06 +0900 | [diff] [blame] | 55 | """ |
| 56 | url = 'groups' |
| 57 | if params: |
| 58 | url += '?%s' % urllib.urlencode(params) |
| 59 | resp, body = self.get(url) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 60 | self.expected_success(200, resp.status) |
| 61 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 62 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 63 | |
| 64 | def update_group(self, group_id, **kwargs): |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 65 | """Updates a group. |
| 66 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 67 | For a full list of available parameters, please refer to the official |
| 68 | API reference: |
| 69 | http://developer.openstack.org/api-ref/identity/v3/index.html#update-group |
Yaroslav Lobankov | 45025c0 | 2015-11-19 17:55:15 +0300 | [diff] [blame] | 70 | """ |
| 71 | post_body = json.dumps({'group': kwargs}) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 72 | resp, body = self.patch('groups/%s' % group_id, post_body) |
| 73 | self.expected_success(200, resp.status) |
| 74 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 75 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 76 | |
| 77 | def delete_group(self, group_id): |
| 78 | """Delete a group.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 79 | resp, body = self.delete('groups/%s' % group_id) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 80 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 81 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 82 | |
| 83 | def add_group_user(self, group_id, user_id): |
| 84 | """Add user into group.""" |
| 85 | resp, body = self.put('groups/%s/users/%s' % (group_id, user_id), |
| 86 | None) |
| 87 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 88 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 89 | |
ghanshyam | 83e94d4 | 2016-08-01 16:48:06 +0900 | [diff] [blame] | 90 | def list_group_users(self, group_id, **params): |
| 91 | """List users in group. |
| 92 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 93 | For a full list of available parameters, please refer to the official |
| 94 | API reference: |
| 95 | http://developer.openstack.org/api-ref/identity/v3/#list-users-in-group |
ghanshyam | 83e94d4 | 2016-08-01 16:48:06 +0900 | [diff] [blame] | 96 | """ |
| 97 | url = 'groups/%s/users' % group_id |
| 98 | if params: |
| 99 | url += '?%s' % urllib.urlencode(params) |
| 100 | resp, body = self.get(url) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 101 | self.expected_success(200, resp.status) |
| 102 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 103 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 104 | |
| 105 | def delete_group_user(self, group_id, user_id): |
| 106 | """Delete user in group.""" |
| 107 | resp, body = self.delete('groups/%s/users/%s' % (group_id, user_id)) |
| 108 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 109 | return rest_client.ResponseBody(resp, body) |
Maho Koshiya | b6fa2e4 | 2015-12-07 16:52:53 +0900 | [diff] [blame] | 110 | |
| 111 | def check_group_user_existence(self, group_id, user_id): |
| 112 | """Check user in group.""" |
| 113 | resp, body = self.head('groups/%s/users/%s' % (group_id, user_id)) |
| 114 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 115 | return rest_client.ResponseBody(resp) |