summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-04-29 19:55:37 +0000
committerGerrit Code Review <review@openstack.org>2013-04-29 19:55:37 +0000
commitd04e94de0a00f141d0fcad6d4150c754cd117e73 (patch)
tree49623dfce5af399290de160c2d85f13c586706ac /nova/tests
parente07986c141b2fba75bf677b2b8665917ccf4ceac (diff)
parentd480e4e6a5405c864124d7ae819d245d10996247 (diff)
downloadnova-d04e94de0a00f141d0fcad6d4150c754cd117e73.tar.gz
nova-d04e94de0a00f141d0fcad6d4150c754cd117e73.tar.xz
nova-d04e94de0a00f141d0fcad6d4150c754cd117e73.zip
Merge "Adds tests for isolated_hosts_filter"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/scheduler/test_host_filters.py76
1 files changed, 43 insertions, 33 deletions
diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py
index 20906051f..7d7c12339 100644
--- a/nova/tests/scheduler/test_host_filters.py
+++ b/nova/tests/scheduler/test_host_filters.py
@@ -815,49 +815,59 @@ class HostFiltersTestCase(test.TestCase):
'trust:trusted_host': 'true'},
passes=False)
- def test_isolated_hosts_fails_isolated_on_non_isolated(self):
- self.flags(isolated_images=['isolated'], isolated_hosts=['isolated'])
- filt_cls = self.class_map['IsolatedHostsFilter']()
+ def _do_test_isolated_hosts(self, host_in_list, image_in_list,
+ set_flags=True):
+ if set_flags:
+ self.flags(isolated_images=['isolated_image'],
+ isolated_hosts=['isolated_host'])
+ host_name = 'isolated_host' if host_in_list else 'free_host'
+ image_ref = 'isolated_image' if image_in_list else 'free_image'
filter_properties = {
'request_spec': {
- 'instance_properties': {'image_ref': 'isolated'}
+ 'instance_properties': {'image_ref': image_ref}
}
}
- host = fakes.FakeHostState('non-isolated', 'node', {})
- self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ filt_cls = self.class_map['IsolatedHostsFilter']()
+ host = fakes.FakeHostState(host_name, 'node', {})
+ return filt_cls.host_passes(host, filter_properties)
+
+ def test_isolated_hosts_fails_isolated_on_non_isolated(self):
+ self.assertFalse(self._do_test_isolated_hosts(False, True))
def test_isolated_hosts_fails_non_isolated_on_isolated(self):
- self.flags(isolated_images=['isolated'], isolated_hosts=['isolated'])
- filt_cls = self.class_map['IsolatedHostsFilter']()
- filter_properties = {
- 'request_spec': {
- 'instance_properties': {'image_ref': 'non-isolated'}
- }
- }
- host = fakes.FakeHostState('isolated', 'node', {})
- self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ self.assertFalse(self._do_test_isolated_hosts(True, False))
def test_isolated_hosts_passes_isolated_on_isolated(self):
- self.flags(isolated_images=['isolated'], isolated_hosts=['isolated'])
- filt_cls = self.class_map['IsolatedHostsFilter']()
- filter_properties = {
- 'request_spec': {
- 'instance_properties': {'image_ref': 'isolated'}
- }
- }
- host = fakes.FakeHostState('isolated', 'node', {})
- self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertTrue(self._do_test_isolated_hosts(True, True))
def test_isolated_hosts_passes_non_isolated_on_non_isolated(self):
- self.flags(isolated_images=['isolated'], isolated_hosts=['isolated'])
- filt_cls = self.class_map['IsolatedHostsFilter']()
- filter_properties = {
- 'request_spec': {
- 'instance_properties': {'image_ref': 'non-isolated'}
- }
- }
- host = fakes.FakeHostState('non-isolated', 'node', {})
- self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertTrue(self._do_test_isolated_hosts(False, False))
+
+ def test_isolated_hosts_no_config(self):
+ # If there are no hosts nor isolated images in the config, it should
+ # not filter at all. This is the default config.
+ self.assertTrue(self._do_test_isolated_hosts(False, True, False))
+ self.assertTrue(self._do_test_isolated_hosts(True, False, False))
+ self.assertTrue(self._do_test_isolated_hosts(True, True, False))
+ self.assertTrue(self._do_test_isolated_hosts(False, False, False))
+
+ def test_isolated_hosts_no_hosts_config(self):
+ self.flags(isolated_images=['isolated_image'])
+ # If there are no hosts in the config, it should only filter out
+ # images that are listed
+ self.assertFalse(self._do_test_isolated_hosts(False, True, False))
+ self.assertTrue(self._do_test_isolated_hosts(True, False, False))
+ self.assertFalse(self._do_test_isolated_hosts(True, True, False))
+ self.assertTrue(self._do_test_isolated_hosts(False, False, False))
+
+ def test_isolated_hosts_no_images_config(self):
+ self.flags(isolated_hosts=['isolated_host'])
+ # If there are no images in the config, it should only filter out
+ # isolated_hosts
+ self.assertTrue(self._do_test_isolated_hosts(False, True, False))
+ self.assertFalse(self._do_test_isolated_hosts(True, False, False))
+ self.assertFalse(self._do_test_isolated_hosts(True, True, False))
+ self.assertTrue(self._do_test_isolated_hosts(False, False, False))
def test_json_filter_passes(self):
filt_cls = self.class_map['JsonFilter']()