blob: e039dc654faaf20900f43a7df573e41155bfb48f [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
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000018from tempest.common import service_client
harika-vakadia92dd742013-02-19 20:41:22 +053019
20
ghanshyamd26b5cd2015-02-09 14:48:58 +090021class ServiceClientJSON(service_client.ServiceClient):
22 api_version = "v3"
harika-vakadia92dd742013-02-19 20:41:22 +053023
24 def update_service(self, service_id, **kwargs):
25 """Updates a service."""
David Kranzd8ccb792014-12-29 11:32:05 -050026 body = self.get_service(service_id)
harika-vakadia92dd742013-02-19 20:41:22 +053027 name = kwargs.get('name', body['name'])
28 type = kwargs.get('type', body['type'])
29 desc = kwargs.get('description', body['description'])
30 patch_body = {
31 'description': desc,
32 'type': type,
33 'name': name
34 }
35 patch_body = json.dumps({'service': patch_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020036 resp, body = self.patch('services/%s' % service_id, patch_body)
David Kranze9d2f422014-07-02 13:57:41 -040037 self.expected_success(200, resp.status)
harika-vakadia92dd742013-02-19 20:41:22 +053038 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000039 return service_client.ResponseBody(resp, body['service'])
harika-vakadia92dd742013-02-19 20:41:22 +053040
41 def get_service(self, service_id):
42 """Get Service."""
43 url = 'services/%s' % service_id
44 resp, body = self.get(url)
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)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000047 return service_client.ResponseBody(resp, body['service'])
Matthew Treinishdb2c5972014-01-31 22:18:59 +000048
49 def create_service(self, serv_type, name=None, description=None,
50 enabled=True):
51 body_dict = {
nayna-patel54b0fb52014-04-25 13:19:16 +000052 'name': name,
Matthew Treinishdb2c5972014-01-31 22:18:59 +000053 'type': serv_type,
54 'enabled': enabled,
nayna-patel54b0fb52014-04-25 13:19:16 +000055 'description': description,
Matthew Treinishdb2c5972014-01-31 22:18:59 +000056 }
57 body = json.dumps({'service': body_dict})
vponomaryovf4c27f92014-02-18 10:56:42 +020058 resp, body = self.post("services", body)
David Kranze9d2f422014-07-02 13:57:41 -040059 self.expected_success(201, resp.status)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000060 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000061 return service_client.ResponseBody(resp, body["service"])
Matthew Treinishdb2c5972014-01-31 22:18:59 +000062
63 def delete_service(self, serv_id):
64 url = "services/" + serv_id
vponomaryovf4c27f92014-02-18 10:56:42 +020065 resp, body = self.delete(url)
David Kranze9d2f422014-07-02 13:57:41 -040066 self.expected_success(204, resp.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000067 return service_client.ResponseBody(resp, body)
nayna-patel54b0fb52014-04-25 13:19:16 +000068
69 def list_services(self):
70 resp, body = self.get('services')
71 self.expected_success(200, resp.status)
72 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000073 return service_client.ResponseBodyList(resp, body['services'])