Coverage for manila/scheduler/filters/create_from_snapshot.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2019 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. 

15 

16 

17from oslo_log import log 

18 

19from manila.scheduler.filters import base_host 

20from manila.share import utils as share_utils 

21 

22LOG = log.getLogger(__name__) 

23 

24 

25class CreateFromSnapshotFilter(base_host.BaseHostFilter): 

26 """CreateFromSnapshotFilter filters hosts based on replication_domain.""" 

27 

28 def host_passes(self, host_state, filter_properties): 

29 """Return True if new share's host is compatible with snapshot's host. 

30 

31 Design of this filter: 

32 

33 - Creating shares from snapshots in another pool or backend needs 

34 to match with one of the below conditions: 

35 - The backend of the new share must be the same as its parent 

36 snapshot. 

37 - Both new share and snapshot are in the same replication_domain 

38 """ 

39 snapshot_id = filter_properties.get('request_spec', {}).get( 

40 'snapshot_id') 

41 snapshot_host = filter_properties.get( 

42 'request_spec', {}).get('snapshot_host') 

43 

44 if None in [snapshot_id, snapshot_host]: 

45 # NOTE(silvacarlose): if the request does not contain a snapshot_id 

46 # or a snapshot_host, the user is not creating a share from a 

47 # snapshot and we don't need to filter out the host. 

48 return True 

49 

50 snapshot_backend = share_utils.extract_host(snapshot_host, 'backend') 

51 snapshot_rep_domain = filter_properties.get('replication_domain') 

52 

53 host_backend = share_utils.extract_host(host_state.host, 'backend') 

54 host_rep_domain = host_state.replication_domain 

55 

56 # Same backend 

57 if host_backend == snapshot_backend: 

58 return True 

59 # Same replication domain 

60 if snapshot_rep_domain and snapshot_rep_domain == host_rep_domain: 

61 return True 

62 

63 msg = ("The parent's snapshot %(snapshot_id)s back end and " 

64 "replication domain don't match with the back end and " 

65 "replication domain of the Host %(host)s.") 

66 kwargs = { 

67 "snapshot_id": snapshot_id, 

68 "host": host_state.host 

69 } 

70 LOG.debug(msg, kwargs) 

71 return False