summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_services.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_services.py')
-rw-r--r--novaclient/tests/unit/v2/test_services.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_services.py b/novaclient/tests/unit/v2/test_services.py
new file mode 100644
index 0000000..2724342
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_services.py
@@ -0,0 +1,99 @@
1# Copyright 2012 IBM Corp.
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
16from novaclient.tests.unit import utils
17from novaclient.tests.unit.v2 import fakes
18from novaclient.v2 import services
19
20
21class ServicesTest(utils.TestCase):
22 def setUp(self):
23 super(ServicesTest, self).setUp()
24 self.cs = self._get_fake_client()
25 self.service_type = self._get_service_type()
26
27 def _get_fake_client(self):
28 return fakes.FakeClient()
29
30 def _get_service_type(self):
31 return services.Service
32
33 def test_list_services(self):
34 svs = self.cs.services.list()
35 self.cs.assert_called('GET', '/os-services')
36 for s in svs:
37 self.assertIsInstance(s, self._get_service_type())
38 self.assertEqual('nova-compute', s.binary)
39 self.assertEqual('host1', s.host)
40 self.assertTrue(str(s).startswith('<Service: '))
41
42 def test_list_services_with_hostname(self):
43 svs = self.cs.services.list(host='host2')
44 self.cs.assert_called('GET', '/os-services?host=host2')
45 for s in svs:
46 self.assertIsInstance(s, self._get_service_type())
47 self.assertEqual('nova-compute', s.binary)
48 self.assertEqual('host2', s.host)
49
50 def test_list_services_with_binary(self):
51 svs = self.cs.services.list(binary='nova-cert')
52 self.cs.assert_called('GET', '/os-services?binary=nova-cert')
53 for s in svs:
54 self.assertIsInstance(s, self._get_service_type())
55 self.assertEqual('nova-cert', s.binary)
56 self.assertEqual('host1', s.host)
57
58 def test_list_services_with_host_binary(self):
59 svs = self.cs.services.list(host='host2', binary='nova-cert')
60 self.cs.assert_called('GET',
61 '/os-services?host=host2&binary=nova-cert')
62 for s in svs:
63 self.assertIsInstance(s, self._get_service_type())
64 self.assertEqual('nova-cert', s.binary)
65 self.assertEqual('host2', s.host)
66
67 def _update_body(self, host, binary, disabled_reason=None):
68 body = {"host": host,
69 "binary": binary}
70 if disabled_reason is not None:
71 body["disabled_reason"] = disabled_reason
72 return body
73
74 def test_services_enable(self):
75 service = self.cs.services.enable('host1', 'nova-cert')
76 values = self._update_body("host1", "nova-cert")
77 self.cs.assert_called('PUT', '/os-services/enable', values)
78 self.assertIsInstance(service, self._get_service_type())
79 self.assertEqual('enabled', service.status)
80
81 def test_services_delete(self):
82 self.cs.services.delete('1')
83 self.cs.assert_called('DELETE', '/os-services/1')
84
85 def test_services_disable(self):
86 service = self.cs.services.disable('host1', 'nova-cert')
87 values = self._update_body("host1", "nova-cert")
88 self.cs.assert_called('PUT', '/os-services/disable', values)
89 self.assertIsInstance(service, self._get_service_type())
90 self.assertEqual('disabled', service.status)
91
92 def test_services_disable_log_reason(self):
93 service = self.cs.services.disable_log_reason(
94 'compute1', 'nova-compute', 'disable bad host')
95 values = self._update_body("compute1", "nova-compute",
96 "disable bad host")
97 self.cs.assert_called('PUT', '/os-services/disable-log-reason', values)
98 self.assertIsInstance(service, self._get_service_type())
99 self.assertEqual('disabled', service.status)