blob: b66fb4a5a9c3649f90e9a2b8ae4dd78b072b3230 [file] [log] [blame]
harika-vakadia92dd742013-02-19 20:41:22 +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-vakadia92dd742013-02-19 20:41:22 +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-vakadia92dd742013-02-19 20:41:22 +053022
23
Haiwei Xuaad85db2014-03-05 05:17:39 +090024class ServiceClientJSON(rest_client.RestClient):
harika-vakadia92dd742013-02-19 20:41:22 +053025
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(ServiceClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.identity.catalog_type
harika-vakadia92dd742013-02-19 20:41:22 +053029 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000030 self.api_version = "v3"
harika-vakadia92dd742013-02-19 20:41:22 +053031
32 def update_service(self, service_id, **kwargs):
33 """Updates a service."""
34 resp, body = self.get_service(service_id)
35 name = kwargs.get('name', body['name'])
36 type = kwargs.get('type', body['type'])
37 desc = kwargs.get('description', body['description'])
38 patch_body = {
39 'description': desc,
40 'type': type,
41 'name': name
42 }
43 patch_body = json.dumps({'service': patch_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020044 resp, body = self.patch('services/%s' % service_id, patch_body)
harika-vakadia92dd742013-02-19 20:41:22 +053045 body = json.loads(body)
46 return resp, body['service']
47
48 def get_service(self, service_id):
49 """Get Service."""
50 url = 'services/%s' % service_id
51 resp, body = self.get(url)
52 body = json.loads(body)
53 return resp, body['service']
Matthew Treinishdb2c5972014-01-31 22:18:59 +000054
55 def create_service(self, serv_type, name=None, description=None,
56 enabled=True):
57 body_dict = {
58 "name": name,
59 'type': serv_type,
60 'enabled': enabled,
61 "description": description,
62 }
63 body = json.dumps({'service': body_dict})
vponomaryovf4c27f92014-02-18 10:56:42 +020064 resp, body = self.post("services", body)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000065 body = json.loads(body)
66 return resp, body["service"]
67
68 def delete_service(self, serv_id):
69 url = "services/" + serv_id
vponomaryovf4c27f92014-02-18 10:56:42 +020070 resp, body = self.delete(url)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000071 return resp, body