blob: 579243c5864737b6da2087125c9286a694360d6c [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
16import json
harika-vakadi40e10112013-02-08 14:38:09 +053017
Haiwei Xuaad85db2014-03-05 05:17:39 +090018from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
harika-vakadi40e10112013-02-08 14:38:09 +053022
23
Haiwei Xuaad85db2014-03-05 05:17:39 +090024class PolicyClientJSON(rest_client.RestClient):
harika-vakadi40e10112013-02-08 14:38:09 +053025
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(PolicyClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.identity.catalog_type
harika-vakadi40e10112013-02-08 14:38:09 +053029 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000030 self.api_version = "v3"
harika-vakadi40e10112013-02-08 14:38:09 +053031
32 def create_policy(self, blob, type):
33 """Creates a Policy."""
34 post_body = {
35 "blob": blob,
36 "type": type
37 }
38 post_body = json.dumps({'policy': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020039 resp, body = self.post('policies', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040040 self.expected_success(201, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053041 body = json.loads(body)
David Kranz70f137c2014-10-23 17:57:18 -040042 return rest_client.ResponseBody(resp, body['policy'])
harika-vakadi40e10112013-02-08 14:38:09 +053043
44 def list_policies(self):
45 """Lists the policies."""
46 resp, body = self.get('policies')
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)
David Kranz291bf792014-12-02 10:31:40 -050049 return rest_client.ResponseBodyList(resp, body['policies'])
harika-vakadi40e10112013-02-08 14:38:09 +053050
51 def get_policy(self, policy_id):
52 """Lists out the given policy."""
53 url = 'policies/%s' % policy_id
54 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040055 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053056 body = json.loads(body)
David Kranz291bf792014-12-02 10:31:40 -050057 return rest_client.ResponseBody(resp, body['policy'])
harika-vakadi40e10112013-02-08 14:38:09 +053058
59 def update_policy(self, policy_id, **kwargs):
60 """Updates a policy."""
harika-vakadi40e10112013-02-08 14:38:09 +053061 type = kwargs.get('type')
62 post_body = {
63 'type': type
64 }
65 post_body = json.dumps({'policy': post_body})
66 url = 'policies/%s' % policy_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020067 resp, body = self.patch(url, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040068 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053069 body = json.loads(body)
David Kranz291bf792014-12-02 10:31:40 -050070 return rest_client.ResponseBody(resp, body['policy'])
harika-vakadi40e10112013-02-08 14:38:09 +053071
72 def delete_policy(self, policy_id):
73 """Deletes the policy."""
74 url = "policies/%s" % policy_id
David Kranz2aaf5312014-08-29 09:22:10 -040075 resp, body = self.delete(url)
76 self.expected_success(204, resp.status)
David Kranz291bf792014-12-02 10:31:40 -050077 return rest_client.ResponseBody(resp, body)