From 8bc80cab3c134d64953b4f6493cab80b5bdc1b69 Mon Sep 17 00:00:00 2001 From: Hans Lindgren Date: Sun, 27 Jan 2013 21:19:16 +0100 Subject: Fix an error in affinity filters Fix a call to compute_api.get_all to properly exclude deleted instances. Add tests to prohibit this error in the future. After some thought, this can be further optimized to let the instance query do all the filtering/matching. Resolves bug 1107156. Change-Id: I6d6a6ba44d38d363489853d0407ad4cc94046656 --- nova/tests/scheduler/test_host_filters.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index 6fcd19d92..230e2ea03 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -337,6 +337,20 @@ class HostFiltersTestCase(test.TestCase): self.assertTrue(filt_cls.host_passes(host, filter_properties)) + def test_affinity_different_filter_handles_deleted_instance(self): + filt_cls = self.class_map['DifferentHostFilter']() + host = fakes.FakeHostState('host1', 'node1', {}) + instance = fakes.FakeInstance(context=self.context, + params={'host': 'host1'}) + instance_uuid = instance.uuid + db.instance_destroy(self.context, instance_uuid) + + filter_properties = {'context': self.context.elevated(), + 'scheduler_hints': { + 'different_host': [instance_uuid], }} + + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + def test_affinity_same_filter_no_list_passes(self): filt_cls = self.class_map['SameHostFilter']() host = fakes.FakeHostState('host1', 'node1', {}) @@ -388,6 +402,20 @@ class HostFiltersTestCase(test.TestCase): self.assertTrue(filt_cls.host_passes(host, filter_properties)) + def test_affinity_same_filter_handles_deleted_instance(self): + filt_cls = self.class_map['SameHostFilter']() + host = fakes.FakeHostState('host1', 'node1', {}) + instance = fakes.FakeInstance(context=self.context, + params={'host': 'host1'}) + instance_uuid = instance.uuid + db.instance_destroy(self.context, instance_uuid) + + filter_properties = {'context': self.context.elevated(), + 'scheduler_hints': { + 'same_host': [instance_uuid], }} + + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + def test_affinity_simple_cidr_filter_passes(self): filt_cls = self.class_map['SimpleCIDRAffinityFilter']() host = fakes.FakeHostState('host1', 'node1', {}) -- cgit