ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
| 2 | # Copyright 2013 IBM Corp. |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import json |
| 18 | import urllib |
| 19 | |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 20 | from tempest.api_schema.compute import services as schema |
Haiwei Xu | 16ee2c8 | 2014-03-05 04:59:18 +0900 | [diff] [blame] | 21 | from tempest.common import rest_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 22 | from tempest import config |
| 23 | |
| 24 | CONF = config.CONF |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 25 | |
| 26 | |
Haiwei Xu | 16ee2c8 | 2014-03-05 04:59:18 +0900 | [diff] [blame] | 27 | class ServicesV3ClientJSON(rest_client.RestClient): |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 28 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 29 | def __init__(self, auth_provider): |
| 30 | super(ServicesV3ClientJSON, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 31 | self.service = CONF.compute.catalog_v3_type |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 32 | |
| 33 | def list_services(self, params=None): |
| 34 | url = 'os-services' |
| 35 | if params: |
| 36 | url += '?%s' % urllib.urlencode(params) |
| 37 | |
| 38 | resp, body = self.get(url) |
| 39 | body = json.loads(body) |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 40 | self.validate_response(schema.list_services, resp, body) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 41 | return resp, body['services'] |
| 42 | |
| 43 | def enable_service(self, host_name, binary): |
| 44 | """ |
| 45 | Enable service on a host |
| 46 | host_name: Name of host |
| 47 | binary: Service binary |
| 48 | """ |
ivan-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 49 | post_body = json.dumps({ |
| 50 | 'service': { |
| 51 | 'binary': binary, |
| 52 | 'host': host_name |
| 53 | } |
| 54 | }) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 55 | resp, body = self.put('os-services/enable', post_body) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 56 | body = json.loads(body) |
Ken'ichi Ohmichi | 26bcee6 | 2014-03-19 14:30:38 +0900 | [diff] [blame^] | 57 | self.validate_response(schema.enable_service, resp, body) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 58 | return resp, body['service'] |
| 59 | |
| 60 | def disable_service(self, host_name, binary): |
| 61 | """ |
| 62 | Disable service on a host |
| 63 | host_name: Name of host |
| 64 | binary: Service binary |
| 65 | """ |
ivan-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 66 | post_body = json.dumps({ |
| 67 | 'service': { |
| 68 | 'binary': binary, |
| 69 | 'host': host_name |
| 70 | } |
| 71 | }) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 72 | resp, body = self.put('os-services/disable', post_body) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 73 | body = json.loads(body) |
| 74 | return resp, body['service'] |