summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_availability_zone.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_availability_zone.py')
-rw-r--r--novaclient/tests/unit/v2/test_availability_zone.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_availability_zone.py b/novaclient/tests/unit/v2/test_availability_zone.py
new file mode 100644
index 0000000..a7d6d82
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_availability_zone.py
@@ -0,0 +1,102 @@
1# Copyright 2011 OpenStack Foundation
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
17import six
18
19from novaclient.tests.unit.fixture_data import availability_zones as data
20from novaclient.tests.unit.fixture_data import client
21from novaclient.tests.unit import utils
22from novaclient.v2 import availability_zones
23
24
25class AvailabilityZoneTest(utils.FixturedTestCase):
26 # NOTE(cyeoh): import shell here so the V3 version of
27 # this class can inherit off the v3 version of shell
28 from novaclient.v2 import shell # noqa
29
30 data_fixture_class = data.V1
31
32 scenarios = [('original', {'client_fixture_class': client.V1}),
33 ('session', {'client_fixture_class': client.SessionV1})]
34
35 def setUp(self):
36 super(AvailabilityZoneTest, self).setUp()
37 self.availability_zone_type = self._get_availability_zone_type()
38
39 def _get_availability_zone_type(self):
40 return availability_zones.AvailabilityZone
41
42 def _assertZone(self, zone, name, status):
43 self.assertEqual(zone.zoneName, name)
44 self.assertEqual(zone.zoneState, status)
45
46 def test_list_availability_zone(self):
47 zones = self.cs.availability_zones.list(detailed=False)
48 self.assert_called('GET', '/os-availability-zone')
49
50 for zone in zones:
51 self.assertIsInstance(zone, self.availability_zone_type)
52
53 self.assertEqual(2, len(zones))
54
55 l0 = [six.u('zone-1'), six.u('available')]
56 l1 = [six.u('zone-2'), six.u('not available')]
57
58 z0 = self.shell._treeizeAvailabilityZone(zones[0])
59 z1 = self.shell._treeizeAvailabilityZone(zones[1])
60
61 self.assertEqual((1, 1), (len(z0), len(z1)))
62
63 self._assertZone(z0[0], l0[0], l0[1])
64 self._assertZone(z1[0], l1[0], l1[1])
65
66 def test_detail_availability_zone(self):
67 zones = self.cs.availability_zones.list(detailed=True)
68 self.assert_called('GET', '/os-availability-zone/detail')
69
70 for zone in zones:
71 self.assertIsInstance(zone, self.availability_zone_type)
72
73 self.assertEqual(3, len(zones))
74
75 l0 = [six.u('zone-1'), six.u('available')]
76 l1 = [six.u('|- fake_host-1'), six.u('')]
77 l2 = [six.u('| |- nova-compute'),
78 six.u('enabled :-) 2012-12-26 14:45:25')]
79 l3 = [six.u('internal'), six.u('available')]
80 l4 = [six.u('|- fake_host-1'), six.u('')]
81 l5 = [six.u('| |- nova-sched'),
82 six.u('enabled :-) 2012-12-26 14:45:25')]
83 l6 = [six.u('|- fake_host-2'), six.u('')]
84 l7 = [six.u('| |- nova-network'),
85 six.u('enabled XXX 2012-12-26 14:45:24')]
86 l8 = [six.u('zone-2'), six.u('not available')]
87
88 z0 = self.shell._treeizeAvailabilityZone(zones[0])
89 z1 = self.shell._treeizeAvailabilityZone(zones[1])
90 z2 = self.shell._treeizeAvailabilityZone(zones[2])
91
92 self.assertEqual((3, 5, 1), (len(z0), len(z1), len(z2)))
93
94 self._assertZone(z0[0], l0[0], l0[1])
95 self._assertZone(z0[1], l1[0], l1[1])
96 self._assertZone(z0[2], l2[0], l2[1])
97 self._assertZone(z1[0], l3[0], l3[1])
98 self._assertZone(z1[1], l4[0], l4[1])
99 self._assertZone(z1[2], l5[0], l5[1])
100 self._assertZone(z1[3], l6[0], l6[1])
101 self._assertZone(z1[4], l7[0], l7[1])
102 self._assertZone(z2[0], l8[0], l8[1])