blob: 6ed85cf2c8b79665889aa5c04fe7cf75f1058183 [file] [log] [blame]
Yaroslav Lobankov997a1452015-11-19 17:11:37 +03001# 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 Lobankov45025c02015-11-19 17:55:15 +030016"""
17http://developer.openstack.org/api-ref-identity-v3.html#groups-v3
18"""
19
Yaroslav Lobankov997a1452015-11-19 17:11:37 +030020from oslo_serialization import jsonutils as json
21
22from tempest.common import service_client
23
24
25class GroupsClient(service_client.ServiceClient):
26 api_version = "v3"
27
Yaroslav Lobankov45025c02015-11-19 17:55:15 +030028 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 Lobankov997a1452015-11-19 17:11:37 +030035 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 Lobankov937438c2015-11-20 11:21:11 +030040 def show_group(self, group_id):
Yaroslav Lobankov997a1452015-11-19 17:11:37 +030041 """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 Lobankov45025c02015-11-19 17:55:15 +030055 """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 Lobankov997a1452015-11-19 17:11:37 +030061 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 Koshiyab6fa2e42015-12-07 16:52:53 +090091
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)