summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_hosts.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_hosts.py')
-rw-r--r--novaclient/tests/unit/v2/test_hosts.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_hosts.py b/novaclient/tests/unit/v2/test_hosts.py
new file mode 100644
index 0000000..029964b
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_hosts.py
@@ -0,0 +1,84 @@
1#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
14from novaclient.tests.unit.fixture_data import client
15from novaclient.tests.unit.fixture_data import hosts as data
16from novaclient.tests.unit import utils
17from novaclient.v2 import hosts
18
19
20class HostsTest(utils.FixturedTestCase):
21
22 client_fixture_class = client.V1
23 data_fixture_class = data.V1
24
25 def test_describe_resource(self):
26 hs = self.cs.hosts.get('host')
27 self.assert_called('GET', '/os-hosts/host')
28 [self.assertIsInstance(h, hosts.Host) for h in hs]
29
30 def test_list_host(self):
31 hs = self.cs.hosts.list()
32 self.assert_called('GET', '/os-hosts')
33 [self.assertIsInstance(h, hosts.Host) for h in hs]
34 [self.assertEqual(h.zone, 'nova1') for h in hs]
35
36 def test_list_host_with_zone(self):
37 hs = self.cs.hosts.list('nova')
38 self.assert_called('GET', '/os-hosts?zone=nova')
39 [self.assertIsInstance(h, hosts.Host) for h in hs]
40 [self.assertEqual(h.zone, 'nova') for h in hs]
41
42 def test_update_enable(self):
43 host = self.cs.hosts.get('sample_host')[0]
44 values = {"status": "enabled"}
45 result = host.update(values)
46 self.assert_called('PUT', '/os-hosts/sample_host', values)
47 self.assertIsInstance(result, hosts.Host)
48
49 def test_update_maintenance(self):
50 host = self.cs.hosts.get('sample_host')[0]
51 values = {"maintenance_mode": "enable"}
52 result = host.update(values)
53 self.assert_called('PUT', '/os-hosts/sample_host', values)
54 self.assertIsInstance(result, hosts.Host)
55
56 def test_update_both(self):
57 host = self.cs.hosts.get('sample_host')[0]
58 values = {"status": "enabled",
59 "maintenance_mode": "enable"}
60 result = host.update(values)
61 self.assert_called('PUT', '/os-hosts/sample_host', values)
62 self.assertIsInstance(result, hosts.Host)
63
64 def test_host_startup(self):
65 host = self.cs.hosts.get('sample_host')[0]
66 host.startup()
67 self.assert_called(
68 'GET', '/os-hosts/sample_host/startup')
69
70 def test_host_reboot(self):
71 host = self.cs.hosts.get('sample_host')[0]
72 host.reboot()
73 self.assert_called(
74 'GET', '/os-hosts/sample_host/reboot')
75
76 def test_host_shutdown(self):
77 host = self.cs.hosts.get('sample_host')[0]
78 host.shutdown()
79 self.assert_called(
80 'GET', '/os-hosts/sample_host/shutdown')
81
82 def test_hosts_repr(self):
83 hs = self.cs.hosts.get('host')
84 self.assertEqual('<Host: dummy>', repr(hs[0]))