Coverage for manila/tests/scheduler/filters/test_driver.py: 100%
51 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 (c) 2014 Hewlett-Packard Development Company, L.P.
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.
16from manila.scheduler.filters import driver
17from manila import test
18from manila.tests.scheduler import fakes
21class HostFiltersTestCase(test.TestCase):
23 def setUp(self):
24 super(HostFiltersTestCase, self).setUp()
25 self.filter = driver.DriverFilter()
27 def test_passing_function(self):
28 host1 = fakes.FakeHostState(
29 'host1', {
30 'capabilities': {
31 'filter_function': '1 == 1',
32 }
33 })
35 filter_properties = {'share_type': {}}
37 self.assertTrue(self.filter.host_passes(host1, filter_properties))
39 def test_failing_function(self):
40 host1 = fakes.FakeHostState(
41 'host1', {
42 'capabilities': {
43 'filter_function': '1 == 2',
44 }
45 })
47 filter_properties = {'share_type': {}}
49 self.assertFalse(self.filter.host_passes(host1, filter_properties))
51 def test_no_filter_function(self):
52 host1 = fakes.FakeHostState(
53 'host1', {
54 'capabilities': {
55 'filter_function': None,
56 }
57 })
59 filter_properties = {'share_type': {}}
61 self.assertTrue(self.filter.host_passes(host1, filter_properties))
63 def test_not_implemented(self):
64 host1 = fakes.FakeHostState(
65 'host1', {
66 'capabilities': {}
67 })
69 filter_properties = {'share_type': {}}
71 self.assertTrue(self.filter.host_passes(host1, filter_properties))
73 def test_no_share_extra_specs(self):
74 host1 = fakes.FakeHostState(
75 'host1', {
76 'capabilities': {
77 'filter_function': '1 == 1',
78 }
79 })
81 filter_properties = {'share_type': {}}
83 self.assertTrue(self.filter.host_passes(host1, filter_properties))
85 def test_function_extra_spec_replacement(self):
86 host1 = fakes.FakeHostState(
87 'host1', {
88 'capabilities': {
89 'filter_function': 'extra.var == 1',
90 }
91 })
93 filter_properties = {
94 'share_type': {
95 'extra_specs': {
96 'var': 1,
97 }
98 }
99 }
101 self.assertTrue(self.filter.host_passes(host1, filter_properties))
103 def test_function_stats_replacement(self):
104 host1 = fakes.FakeHostState(
105 'host1', {
106 'total_capacity_gb': 100,
107 'capabilities': {
108 'filter_function': 'stats.total_capacity_gb < 200',
109 }
110 })
112 filter_properties = {'share_type': {}}
114 self.assertTrue(self.filter.host_passes(host1, filter_properties))
116 def test_function_share_replacement(self):
117 host1 = fakes.FakeHostState(
118 'host1', {
119 'capabilities': {
120 'filter_function': 'share.size < 5',
121 }
122 })
124 filter_properties = {
125 'request_spec': {
126 'resource_properties': {
127 'size': 1
128 }
129 }
130 }
132 self.assertTrue(self.filter.host_passes(host1, filter_properties))
134 def test_function_exception_caught(self):
135 host1 = fakes.FakeHostState(
136 'host1', {
137 'capabilities': {
138 'filter_function': '1 / 0 == 0',
139 }
140 })
142 filter_properties = {}
144 self.assertFalse(self.filter.host_passes(host1, filter_properties))
146 def test_capabilities(self):
147 host1 = fakes.FakeHostState(
148 'host1', {
149 'capabilities': {
150 'foo': 10,
151 'filter_function': 'capabilities.foo == 10',
152 },
153 })
155 filter_properties = {}
157 self.assertTrue(self.filter.host_passes(host1, filter_properties))
159 def test_wrong_capabilities(self):
160 host1 = fakes.FakeHostState(
161 'host1', {
162 'capabilities': {
163 'bar': 10,
164 'filter_function': 'capabilities.foo == 10',
165 },
166 })
168 filter_properties = {}
170 self.assertFalse(self.filter.host_passes(host1, filter_properties))