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

15 statements  

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

1# Copyright (c) 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. 

15 

16from oslo_log import log 

17 

18from manila.scheduler.filters import base_host 

19 

20LOG = log.getLogger(__name__) 

21 

22 

23class IgnoreAttemptedHostsFilter(base_host.BaseHostFilter): 

24 """Filter out previously attempted hosts 

25 

26 A host passes this filter if it has not already been attempted for 

27 scheduling. The scheduler needs to add previously attempted hosts 

28 to the 'retry' key of filter_properties in order for this to work 

29 correctly. For example:: 

30 

31 { 

32 'retry': { 

33 'hosts': ['host1', 'host2'], 

34 'num_attempts': 3, 

35 } 

36 } 

37 """ 

38 

39 def host_passes(self, host_state, filter_properties): 

40 """Skip nodes that have already been attempted.""" 

41 attempted = filter_properties.get('retry') 

42 if not attempted: 

43 # Re-scheduling is disabled 

44 LOG.debug("Re-scheduling is disabled.") 

45 return True 

46 

47 hosts = attempted.get('hosts', []) 

48 host = host_state.host 

49 

50 passes = host not in hosts 

51 pass_msg = "passes" if passes else "fails" 

52 

53 LOG.debug("Host %(host)s %(pass_msg)s. Previously tried hosts: " 

54 "%(hosts)s", {'host': host, 

55 'pass_msg': pass_msg, 

56 'hosts': hosts}) 

57 return passes