Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 1 | # Copyright 2015 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import copy |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 16 | |
| 17 | from tempest.services.compute.json import services_client |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 18 | from tempest.tests import fake_auth_provider |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 19 | from tempest.tests.services.compute import base |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 20 | |
| 21 | |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 22 | class TestServicesClient(base.BaseComputeServiceTest): |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 23 | |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 24 | FAKE_SERVICES = { |
| 25 | "services": |
| 26 | [{ |
| 27 | "status": "enabled", |
| 28 | "binary": "nova-conductor", |
| 29 | "zone": "internal", |
| 30 | "state": "up", |
| 31 | "updated_at": "2015-08-19T06:50:55.000000", |
| 32 | "host": "controller", |
| 33 | "disabled_reason": None, |
| 34 | "id": 1 |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 35 | }] |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 36 | } |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 37 | |
| 38 | FAKE_SERVICE = { |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 39 | "service": |
| 40 | { |
| 41 | "status": "enabled", |
| 42 | "binary": "nova-conductor", |
| 43 | "host": "controller" |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 44 | } |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 45 | } |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 46 | |
| 47 | def setUp(self): |
| 48 | super(TestServicesClient, self).setUp() |
| 49 | fake_auth = fake_auth_provider.FakeAuthProvider() |
| 50 | self.client = services_client.ServicesClient( |
| 51 | fake_auth, 'compute', 'regionOne') |
| 52 | |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 53 | def test_list_services_with_str_body(self): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 54 | self.check_service_client_function( |
| 55 | self.client.list_services, |
| 56 | 'tempest.common.service_client.ServiceClient.get', |
| 57 | self.FAKE_SERVICES) |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 58 | |
| 59 | def test_list_services_with_bytes_body(self): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 60 | self.check_service_client_function( |
| 61 | self.client.list_services, |
| 62 | 'tempest.common.service_client.ServiceClient.get', |
| 63 | self.FAKE_SERVICES, to_utf=True) |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 64 | |
| 65 | def _test_enable_service(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 66 | self.check_service_client_function( |
| 67 | self.client.enable_service, |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 68 | 'tempest.common.service_client.ServiceClient.put', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 69 | self.FAKE_SERVICE, |
| 70 | bytes_body, |
| 71 | host_name="nova-conductor", binary="controller") |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 72 | |
| 73 | def test_enable_service_with_str_body(self): |
| 74 | self._test_enable_service() |
| 75 | |
| 76 | def test_enable_service_with_bytes_body(self): |
| 77 | self._test_enable_service(bytes_body=True) |
| 78 | |
| 79 | def _test_disable_service(self, bytes_body=False): |
| 80 | fake_service = copy.deepcopy(self.FAKE_SERVICE) |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 81 | fake_service["service"]["status"] = "disable" |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 82 | |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 83 | self.check_service_client_function( |
| 84 | self.client.enable_service, |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 85 | 'tempest.common.service_client.ServiceClient.put', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame^] | 86 | fake_service, |
| 87 | bytes_body, |
| 88 | host_name="nova-conductor", binary="controller") |
Kenji Yasui | 2983079 | 2015-08-19 08:03:11 +0000 | [diff] [blame] | 89 | |
| 90 | def test_disable_service_with_str_body(self): |
| 91 | self._test_enable_service() |
| 92 | |
| 93 | def test_disable_service_with_bytes_body(self): |
| 94 | self._test_enable_service(bytes_body=True) |