Coverage for manila/tests/scheduler/filters/test_create_from_snapshot.py: 100%
37 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 2020 NetApp, Inc.
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 the CreateFromSnapshotFilter.
18"""
19import ddt
21from manila.scheduler.filters import create_from_snapshot
22from manila import test
23from manila.tests.scheduler import fakes
26@ddt.ddt
27class CreateFromSnapshotFilterTestCase(test.TestCase):
28 """Test case for CreateFromSnapshotFilter."""
30 def setUp(self):
31 super(CreateFromSnapshotFilterTestCase, self).setUp()
32 self.filter = create_from_snapshot.CreateFromSnapshotFilter()
34 @staticmethod
35 def _create_request(snapshot_id=None,
36 snapshot_host=None,
37 replication_domain=None):
38 return {
39 'request_spec': {
40 'snapshot_id': snapshot_id,
41 'snapshot_host': snapshot_host,
42 },
43 'replication_domain': replication_domain,
44 }
46 @staticmethod
47 def _create_host_state(host=None, rep_domain=None):
48 return fakes.FakeHostState(host,
49 {
50 'replication_domain': rep_domain,
51 })
53 def test_without_snapshot_id(self):
54 request = self._create_request()
55 host = self._create_host_state(host='fake_host')
57 self.assertTrue(self.filter.host_passes(host, request))
59 def test_without_snapshot_host(self):
60 request = self._create_request(snapshot_id='fake_snapshot_id',
61 replication_domain="fake_domain")
62 host = self._create_host_state(host='fake_host',
63 rep_domain='fake_domain_2')
65 self.assertTrue(self.filter.host_passes(host, request))
67 @ddt.data(('host1@AAA#pool1', 'host1@AAA#pool1'),
68 ('host1@AAA#pool1', 'host1@AAA#pool2'))
69 @ddt.unpack
70 def test_same_backend(self, request_host, host_state):
71 request = self._create_request(snapshot_id='fake_snapshot_id',
72 snapshot_host=request_host)
73 host = self._create_host_state(host=host_state)
75 self.assertTrue(self.filter.host_passes(host, request))
77 def test_same_availability_zone(self):
78 request = self._create_request(snapshot_id='fake_snapshot_id',
79 snapshot_host='fake_host',
80 replication_domain="fake_domain")
81 host = self._create_host_state(host='fake_host_2',
82 rep_domain='fake_domain')
83 self.assertTrue(self.filter.host_passes(host, request))
85 def test_different_backend_and_availability_zone(self):
86 request = self._create_request(snapshot_id='fake_snapshot_id',
87 snapshot_host='fake_host',
88 replication_domain="fake_domain")
89 host = self._create_host_state(host='fake_host_2',
90 rep_domain='fake_domain_2')
92 self.assertFalse(self.filter.host_passes(host, request))