Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / tests / tempest / services / identity / v3 / json / service_client.py
1 # 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
16 from oslo_serialization import jsonutils as json
17
18 from neutron.tests.tempest.common import service_client
19
20
21 class ServiceClientJSON(service_client.ServiceClient):
22     api_version = "v3"
23
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'])
30         patch_body = {
31             'description': desc,
32             'type': type,
33             'name': name
34         }
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'])
40
41     def get_service(self, service_id):
42         """Get Service."""
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'])
48
49     def create_service(self, serv_type, name=None, description=None,
50                        enabled=True):
51         body_dict = {
52             'name': name,
53             'type': serv_type,
54             'enabled': enabled,
55             'description': description,
56         }
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"])
62
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)
68
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'])