blob: fe63de9ce78af769a0c47bb3ef7953b59de42332 [file] [log] [blame]
Kenji Yasui29830792015-08-19 08:03:11 +00001# 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
15import copy
Kenji Yasui29830792015-08-19 08:03:11 +000016
17from tempest.services.compute.json import services_client
Kenji Yasui29830792015-08-19 08:03:11 +000018from tempest.tests import fake_auth_provider
Marc Kodererdb19acd2015-09-03 16:03:58 +020019from tempest.tests.services.compute import base
Kenji Yasui29830792015-08-19 08:03:11 +000020
21
Marc Kodererdb19acd2015-09-03 16:03:58 +020022class TestServicesClient(base.BaseComputeServiceTest):
Kenji Yasui29830792015-08-19 08:03:11 +000023
Marc Kodererdb19acd2015-09-03 16:03:58 +020024 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 Yasui29830792015-08-19 08:03:11 +000035 }]
Marc Kodererdb19acd2015-09-03 16:03:58 +020036 }
Kenji Yasui29830792015-08-19 08:03:11 +000037
38 FAKE_SERVICE = {
Marc Kodererdb19acd2015-09-03 16:03:58 +020039 "service":
40 {
41 "status": "enabled",
42 "binary": "nova-conductor",
43 "host": "controller"
Kenji Yasui29830792015-08-19 08:03:11 +000044 }
Marc Kodererdb19acd2015-09-03 16:03:58 +020045 }
Kenji Yasui29830792015-08-19 08:03:11 +000046
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 Yasui29830792015-08-19 08:03:11 +000053 def test_list_services_with_str_body(self):
Marc Kodererdb19acd2015-09-03 16:03:58 +020054 self.check_service_client_function(
55 self.client.list_services,
56 'tempest.common.service_client.ServiceClient.get',
57 self.FAKE_SERVICES)
Kenji Yasui29830792015-08-19 08:03:11 +000058
59 def test_list_services_with_bytes_body(self):
Marc Kodererdb19acd2015-09-03 16:03:58 +020060 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 Yasui29830792015-08-19 08:03:11 +000064
65 def _test_enable_service(self, bytes_body=False):
Marc Kodererdb19acd2015-09-03 16:03:58 +020066 self.check_service_client_function(
67 self.client.enable_service,
Kenji Yasui29830792015-08-19 08:03:11 +000068 'tempest.common.service_client.ServiceClient.put',
Marc Kodererdb19acd2015-09-03 16:03:58 +020069 self.FAKE_SERVICE,
70 bytes_body,
71 host_name="nova-conductor", binary="controller")
Kenji Yasui29830792015-08-19 08:03:11 +000072
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 Kodererdb19acd2015-09-03 16:03:58 +020081 fake_service["service"]["status"] = "disable"
Kenji Yasui29830792015-08-19 08:03:11 +000082
Marc Kodererdb19acd2015-09-03 16:03:58 +020083 self.check_service_client_function(
84 self.client.enable_service,
Kenji Yasui29830792015-08-19 08:03:11 +000085 'tempest.common.service_client.ServiceClient.put',
Marc Kodererdb19acd2015-09-03 16:03:58 +020086 fake_service,
87 bytes_body,
88 host_name="nova-conductor", binary="controller")
Kenji Yasui29830792015-08-19 08:03:11 +000089
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)