From d480e4e6a5405c864124d7ae819d245d10996247 Mon Sep 17 00:00:00 2001 From: Matthew Sherborne Date: Sun, 21 Apr 2013 07:50:35 +1000 Subject: Adds tests for isolated_hosts_filter The isolated_hosts_filter takes two configuration options. This patch adds three tests defining the behaviour for when one or more of these variables are missing. This patch speeds things up a bit when the isolated_images option is missing, making it do less dict lookups to come up with the same answer. Matrix of isolated_hosts_filter changes: +----------------------+--------------------+--------------+ | Config options | Before patch | After | +----------------------+--------------------+--------------+ | 0 + 0 | No filtering | Same as B4 | | | no tests | Tested | +----------------------+--------------------+--------------+ | 0 + iso_image | Block iso'd images | Same as B4 | | | no tests | Tested | +----------------------+--------------------+--------------+ | iso_host + 0 | Block iso'd images | Same as b4 | | | no tests | Tested | +----------------------+--------------------+--------------+ | iso_host + iso_image | Block matched h+i | Same as b4 | | | Tested | Tested | +----------------------+--------------------+--------------+ Change-Id: Ibe6725e39a771b31fdf49513335275deba33e96b --- nova/scheduler/filters/isolated_hosts_filter.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/filters/isolated_hosts_filter.py b/nova/scheduler/filters/isolated_hosts_filter.py index c8849bcca..fc9884a55 100644 --- a/nova/scheduler/filters/isolated_hosts_filter.py +++ b/nova/scheduler/filters/isolated_hosts_filter.py @@ -33,9 +33,27 @@ class IsolatedHostsFilter(filters.BaseHostFilter): """Returns host.""" def host_passes(self, host_state, filter_properties): + """ + Result Matrix: + | isolated_image | non_isolated_image + -------------+----------------+------------------- + iso_host | True | False + non_iso_host | False | True + + """ + # If the configuration does not list any hosts, the filter will always + # return True, assuming a configuration error, so letting all hosts + # through. + isolated_hosts = CONF.isolated_hosts + isolated_images = CONF.isolated_images + if not isolated_images: + # As there are no images to match, return False if the host is in + # the isolation list + return host_state.host not in isolated_hosts + spec = filter_properties.get('request_spec', {}) props = spec.get('instance_properties', {}) image_ref = props.get('image_ref') - image_isolated = image_ref in CONF.isolated_images - host_isolated = host_state.host in CONF.isolated_hosts + image_isolated = image_ref in isolated_images + host_isolated = host_state.host in isolated_hosts return image_isolated == host_isolated -- cgit