Coverage for manila/tests/scheduler/filters/test_availability_zone.py: 100%
43 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2011 OpenStack Foundation.
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.
16"""
17Tests For AvailabilityZoneFilter.
18"""
19import ddt
20from oslo_context import context
22from manila.scheduler.filters import availability_zone
23from manila import test
24from manila.tests.scheduler import fakes
27@ddt.ddt
28class HostFiltersTestCase(test.TestCase):
29 """Test case for AvailabilityZoneFilter."""
31 def setUp(self):
32 super(HostFiltersTestCase, self).setUp()
33 self.filter = availability_zone.AvailabilityZoneFilter()
34 self.az_id = 'e3ecad6f-e984-4cd1-b149-d83c962374a8'
35 self.fake_service = {
36 'service': {
37 'availability_zone_id': self.az_id,
38 'availability_zone': {
39 'name': 'nova',
40 'id': self.az_id
41 }
42 }
43 }
45 @staticmethod
46 def _make_zone_request(zone, is_admin=False):
47 ctxt = context.RequestContext('fake', 'fake', is_admin=is_admin)
48 return {
49 'context': ctxt,
50 'request_spec': {
51 'resource_properties': {
52 'availability_zone_id': zone
53 }
54 }
55 }
57 def test_availability_zone_filter_same(self):
58 request = self._make_zone_request(self.az_id)
59 host = fakes.FakeHostState('host1', self.fake_service)
60 self.assertTrue(self.filter.host_passes(host, request))
62 def test_availability_zone_filter_different(self):
63 request = self._make_zone_request('bad')
64 host = fakes.FakeHostState('host1', self.fake_service)
65 self.assertFalse(self.filter.host_passes(host, request))
67 def test_availability_zone_filter_empty(self):
68 request = {}
69 host = fakes.FakeHostState('host1', self.fake_service)
70 self.assertTrue(self.filter.host_passes(host, request))
72 def test_availability_zone_filter_both_request_AZ_and_type_AZs_match(self):
73 request = self._make_zone_request(
74 '9382098d-d40f-42a2-8f31-8eb78ee18c02')
75 request['request_spec']['availability_zones'] = [
76 'nova', 'super nova', 'hypernova']
77 service = {
78 'availability_zone': {
79 'name': 'nova',
80 'id': '9382098d-d40f-42a2-8f31-8eb78ee18c02',
81 },
82 'availability_zone_id': '9382098d-d40f-42a2-8f31-8eb78ee18c02',
83 }
84 host = fakes.FakeHostState('host1', {'service': service})
86 self.assertTrue(self.filter.host_passes(host, request))
88 @ddt.data((['zone1', 'zone2', 'zone 4', 'zone3'], 'zone2', True),
89 (['zone1zone2zone3'], 'zone2', False),
90 (['zone1zone2zone3'], 'nova', False),
91 (['zone1', 'zone2', 'zone 4', 'zone3'], 'zone 4', True))
92 @ddt.unpack
93 def test_availability_zone_filter_only_share_type_AZs(
94 self, supported_azs, request_az, host_passes):
95 service = {
96 'availability_zone': {
97 'name': request_az,
98 'id': '9382098d-d40f-42a2-8f31-8eb78ee18c02',
99 },
100 'availability_zone_id': '9382098d-d40f-42a2-8f31-8eb78ee18c02',
101 }
102 request = self._make_zone_request(None)
103 request['request_spec']['availability_zones'] = supported_azs
104 request['request_spec']['az_request_multiple_subnet_support_map'] = \
105 {'zone2': 2}
106 host = fakes.FakeHostState('host1', {'service': service})
108 self.assertEqual(host_passes, self.filter.host_passes(host, request))