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

20 statements  

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

1# Copyright (c) 2011-2012 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 manila.scheduler.filters import base_host 

17 

18 

19class AvailabilityZoneFilter(base_host.BaseHostFilter): 

20 """Filters Hosts by availability zone.""" 

21 

22 # Availability zones do not change within a request 

23 run_filter_once_per_request = True 

24 

25 def host_passes(self, host_state, filter_properties): 

26 spec = filter_properties.get('request_spec', {}) 

27 props = spec.get('resource_properties', {}) 

28 request_az_id = props.get('availability_zone_id', 

29 spec.get('availability_zone_id')) 

30 az_request_multiple_subnet_support_map = spec.get( 

31 'az_request_multiple_subnet_support_map', {}) 

32 request_azs = spec.get('availability_zones') 

33 host_az_id = host_state.service['availability_zone_id'] 

34 host_az = host_state.service['availability_zone']['name'] 

35 host_single_subnet_only = ( 

36 not host_state.share_server_multiple_subnet_support) 

37 

38 host_satisfied = True 

39 if request_az_id is not None: 

40 host_satisfied = request_az_id == host_az_id 

41 

42 if request_azs: 

43 host_satisfied = host_satisfied and host_az in request_azs 

44 

45 # Only validates the multiple subnet support in case it can deny the 

46 # host: 

47 # 1. host is satisfying the AZ 

48 # 2. There is a map to be checked 

49 # 3. The host does not support a multiple subnet 

50 if (host_satisfied and az_request_multiple_subnet_support_map and 

51 host_single_subnet_only): 

52 host_satisfied = ( 

53 not az_request_multiple_subnet_support_map.get(host_az_id, 

54 False)) 

55 

56 return host_satisfied