summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v1_1/test_availability_zone.py
blob: fda4764a155b1af8b002ecb9390570e8ff16b6a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 2011 OpenStack Foundation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import six

from novaclient.tests.unit.fixture_data import availability_zones as data
from novaclient.tests.unit.fixture_data import client
from novaclient.tests.unit import utils
from novaclient.v1_1 import availability_zones


class AvailabilityZoneTest(utils.FixturedTestCase):
    # NOTE(cyeoh): import shell here so the V3 version of
    # this class can inherit off the v3 version of shell
    from novaclient.v1_1 import shell  # noqa

    data_fixture_class = data.V1

    scenarios = [('original', {'client_fixture_class': client.V1}),
                 ('session', {'client_fixture_class': client.SessionV1})]

    def setUp(self):
        super(AvailabilityZoneTest, self).setUp()
        self.availability_zone_type = self._get_availability_zone_type()

    def _get_availability_zone_type(self):
        return availability_zones.AvailabilityZone

    def _assertZone(self, zone, name, status):
        self.assertEqual(zone.zoneName, name)
        self.assertEqual(zone.zoneState, status)

    def test_list_availability_zone(self):
        zones = self.cs.availability_zones.list(detailed=False)
        self.assert_called('GET', '/os-availability-zone')

        for zone in zones:
            self.assertIsInstance(zone, self.availability_zone_type)

        self.assertEqual(2, len(zones))

        l0 = [six.u('zone-1'), six.u('available')]
        l1 = [six.u('zone-2'), six.u('not available')]

        z0 = self.shell._treeizeAvailabilityZone(zones[0])
        z1 = self.shell._treeizeAvailabilityZone(zones[1])

        self.assertEqual((1, 1), (len(z0), len(z1)))

        self._assertZone(z0[0], l0[0], l0[1])
        self._assertZone(z1[0], l1[0], l1[1])

    def test_detail_availability_zone(self):
        zones = self.cs.availability_zones.list(detailed=True)
        self.assert_called('GET', '/os-availability-zone/detail')

        for zone in zones:
            self.assertIsInstance(zone, self.availability_zone_type)

        self.assertEqual(3, len(zones))

        l0 = [six.u('zone-1'), six.u('available')]
        l1 = [six.u('|- fake_host-1'), six.u('')]
        l2 = [six.u('| |- nova-compute'),
              six.u('enabled :-) 2012-12-26 14:45:25')]
        l3 = [six.u('internal'), six.u('available')]
        l4 = [six.u('|- fake_host-1'), six.u('')]
        l5 = [six.u('| |- nova-sched'),
              six.u('enabled :-) 2012-12-26 14:45:25')]
        l6 = [six.u('|- fake_host-2'), six.u('')]
        l7 = [six.u('| |- nova-network'),
              six.u('enabled XXX 2012-12-26 14:45:24')]
        l8 = [six.u('zone-2'), six.u('not available')]

        z0 = self.shell._treeizeAvailabilityZone(zones[0])
        z1 = self.shell._treeizeAvailabilityZone(zones[1])
        z2 = self.shell._treeizeAvailabilityZone(zones[2])

        self.assertEqual((3, 5, 1), (len(z0), len(z1), len(z2)))

        self._assertZone(z0[0], l0[0], l0[1])
        self._assertZone(z0[1], l1[0], l1[1])
        self._assertZone(z0[2], l2[0], l2[1])
        self._assertZone(z1[0], l3[0], l3[1])
        self._assertZone(z1[1], l4[0], l4[1])
        self._assertZone(z1[2], l5[0], l5[1])
        self._assertZone(z1[3], l6[0], l6[1])
        self._assertZone(z1[4], l7[0], l7[1])
        self._assertZone(z2[0], l8[0], l8[1])