Coverage for manila/tests/scheduler/filters/test_host.py: 100%
27 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 2021 Cloudification GmbH.
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.
16import ddt
18from manila import context
19from manila.scheduler.filters import host
20from manila import test
21from manila.tests.scheduler import fakes
24fake_host1 = fakes.FakeHostState('host1', {})
25fake_host2 = fakes.FakeHostState('host2', {})
28@ddt.ddt
29class OnlyHostFilterTestCase(test.TestCase):
30 """Test case for OnlyHostFilter."""
32 def setUp(self):
33 super(OnlyHostFilterTestCase, self).setUp()
34 self.filter = host.OnlyHostFilter()
35 self.user_context = context.RequestContext('user', 'project')
36 self.admin_context = context.RequestContext('user', 'project',
37 is_admin=True)
39 def _make_filter_properties(self, hint):
40 return {
41 'context': self.admin_context,
42 'scheduler_hints': hint,
43 }
45 @ddt.data((fake_host1, {'scheduler_hints': None}),
46 (fake_host1, {'scheduler_hints': {}}),
47 (fake_host1,
48 {'scheduler_hints': {'only_host': fake_host2.host}}))
49 @ddt.unpack
50 def test_only_host_filter_user_context(self, host, filter_properties):
51 context = {'context': self.user_context}
52 filter_properties.update(context)
53 self.assertTrue(self.filter.host_passes(host, filter_properties))
55 @ddt.data((fake_host1, None, True),
56 (fake_host1, {}, True),
57 (fake_host1, {'only_host': fake_host1.host}, True),
58 (fake_host2, {'only_host': fake_host1.host}, False))
59 @ddt.unpack
60 def test_only_host_filter_admin_context(self, host, hint, host_passes):
61 filter_properties = self._make_filter_properties(hint)
62 self.assertEqual(host_passes,
63 self.filter.host_passes(host, filter_properties))