1 # Copyright 2013 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 from oslo_serialization import jsonutils as json
18 from neutron.tests.tempest.common import service_client
21 class ServiceClientJSON(service_client.ServiceClient):
24 def update_service(self, service_id, **kwargs):
25 """Updates a service."""
26 body = self.get_service(service_id)
27 name = kwargs.get('name', body['name'])
28 type = kwargs.get('type', body['type'])
29 desc = kwargs.get('description', body['description'])
35 patch_body = json.dumps({'service': patch_body})
36 resp, body = self.patch('services/%s' % service_id, patch_body)
37 self.expected_success(200, resp.status)
38 body = json.loads(body)
39 return service_client.ResponseBody(resp, body['service'])
41 def get_service(self, service_id):
43 url = 'services/%s' % service_id
44 resp, body = self.get(url)
45 self.expected_success(200, resp.status)
46 body = json.loads(body)
47 return service_client.ResponseBody(resp, body['service'])
49 def create_service(self, serv_type, name=None, description=None,
55 'description': description,
57 body = json.dumps({'service': body_dict})
58 resp, body = self.post("services", body)
59 self.expected_success(201, resp.status)
60 body = json.loads(body)
61 return service_client.ResponseBody(resp, body["service"])
63 def delete_service(self, serv_id):
64 url = "services/" + serv_id
65 resp, body = self.delete(url)
66 self.expected_success(204, resp.status)
67 return service_client.ResponseBody(resp, body)
69 def list_services(self):
70 resp, body = self.get('services')
71 self.expected_success(200, resp.status)
72 body = json.loads(body)
73 return service_client.ResponseBodyList(resp, body['services'])