blob: 82e8aad193ff3a84e0428d1983e7291b70c3bf83 [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)
David Kranze9d2f422014-07-02 13:57:41 -040045 self.expected_success(200, resp.status)
harika-vakadia92dd742013-02-19 20:41:22 +053046 body = json.loads(body)
47 return resp, body['service']
48
49 def get_service(self, service_id):
50 """Get Service."""
51 url = 'services/%s' % service_id
52 resp, body = self.get(url)
David Kranze9d2f422014-07-02 13:57:41 -040053 self.expected_success(200, resp.status)
harika-vakadia92dd742013-02-19 20:41:22 +053054 body = json.loads(body)
55 return resp, body['service']
Matthew Treinishdb2c5972014-01-31 22:18:59 +000056
57 def create_service(self, serv_type, name=None, description=None,
58 enabled=True):
59 body_dict = {
60 "name": name,
61 'type': serv_type,
62 'enabled': enabled,
63 "description": description,
64 }
65 body = json.dumps({'service': body_dict})
vponomaryovf4c27f92014-02-18 10:56:42 +020066 resp, body = self.post("services", body)
David Kranze9d2f422014-07-02 13:57:41 -040067 self.expected_success(201, resp.status)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000068 body = json.loads(body)
69 return resp, body["service"]
70
71 def delete_service(self, serv_id):
72 url = "services/" + serv_id
vponomaryovf4c27f92014-02-18 10:56:42 +020073 resp, body = self.delete(url)
David Kranze9d2f422014-07-02 13:57:41 -040074 self.expected_success(204, resp.status)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000075 return resp, body