blob: 3231bb0f1705b37ad75b1cc7b539cdaf1f9ecded [file] [log] [blame]
harika-vakadi40e10112013-02-08 14:38:09 +05301# 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
Matthew Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
harika-vakadi40e10112013-02-08 14:38:09 +053017
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000018from tempest.common import service_client
harika-vakadi40e10112013-02-08 14:38:09 +053019
20
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000021class PolicyClient(service_client.ServiceClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090022 api_version = "v3"
harika-vakadi40e10112013-02-08 14:38:09 +053023
24 def create_policy(self, blob, type):
25 """Creates a Policy."""
26 post_body = {
27 "blob": blob,
28 "type": type
29 }
30 post_body = json.dumps({'policy': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020031 resp, body = self.post('policies', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040032 self.expected_success(201, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053033 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000034 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053035
36 def list_policies(self):
37 """Lists the policies."""
38 resp, body = self.get('policies')
David Kranz2aaf5312014-08-29 09:22:10 -040039 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053040 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000041 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053042
43 def get_policy(self, policy_id):
44 """Lists out the given policy."""
45 url = 'policies/%s' % policy_id
46 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040047 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053048 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000049 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053050
51 def update_policy(self, policy_id, **kwargs):
52 """Updates a policy."""
harika-vakadi40e10112013-02-08 14:38:09 +053053 type = kwargs.get('type')
54 post_body = {
55 'type': type
56 }
57 post_body = json.dumps({'policy': post_body})
58 url = 'policies/%s' % policy_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020059 resp, body = self.patch(url, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040060 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053061 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000062 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053063
64 def delete_policy(self, policy_id):
65 """Deletes the policy."""
66 url = "policies/%s" % policy_id
David Kranz2aaf5312014-08-29 09:22:10 -040067 resp, body = self.delete(url)
68 self.expected_success(204, resp.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000069 return service_client.ResponseBody(resp, body)