Merge "Separate isolated hosts filter unit tests"

This commit is contained in:
Jenkins
2014-10-27 16:26:21 +00:00
committed by Gerrit Code Review
2 changed files with 90 additions and 69 deletions
@@ -0,0 +1,90 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.scheduler.filters import isolated_hosts_filter
from nova import test
from nova.tests.scheduler import fakes
class TestIsolatedHostsFilter(test.NoDBTestCase):
def setUp(self):
super(TestIsolatedHostsFilter, self).setUp()
self.filt_cls = isolated_hosts_filter.IsolatedHostsFilter()
def _do_test_isolated_hosts(self, host_in_list, image_in_list,
set_flags=True,
restrict_isolated_hosts_to_isolated_images=True):
if set_flags:
self.flags(isolated_images=['isolated_image'],
isolated_hosts=['isolated_host'],
restrict_isolated_hosts_to_isolated_images=
restrict_isolated_hosts_to_isolated_images)
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': image_ref}
}
}
host = fakes.FakeHostState(host_name, 'node', {})
return self.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.assertFalse(self._do_test_isolated_hosts(True, False))
def test_isolated_hosts_passes_isolated_on_isolated(self):
self.assertTrue(self._do_test_isolated_hosts(True, True))
def test_isolated_hosts_passes_non_isolated_on_non_isolated(self):
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_isolated_hosts_less_restrictive(self):
# If there are isolated hosts and non isolated images
self.assertTrue(self._do_test_isolated_hosts(True, False, True, False))
# If there are isolated hosts and isolated images
self.assertTrue(self._do_test_isolated_hosts(True, True, True, False))
# If there are non isolated hosts and non isolated images
self.assertTrue(self._do_test_isolated_hosts(False, False, True,
False))
# If there are non isolated hosts and isolated images
self.assertFalse(self._do_test_isolated_hosts(False, True, True,
False))
-69
View File
@@ -163,75 +163,6 @@ class HostFiltersTestCase(test.NoDBTestCase):
db.aggregate_host_add(self.context.elevated(), result['id'], host)
return result
def _do_test_isolated_hosts(self, host_in_list, image_in_list,
set_flags=True,
restrict_isolated_hosts_to_isolated_images=True):
if set_flags:
self.flags(isolated_images=['isolated_image'],
isolated_hosts=['isolated_host'],
restrict_isolated_hosts_to_isolated_images=
restrict_isolated_hosts_to_isolated_images)
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': image_ref}
}
}
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.assertFalse(self._do_test_isolated_hosts(True, False))
def test_isolated_hosts_passes_isolated_on_isolated(self):
self.assertTrue(self._do_test_isolated_hosts(True, True))
def test_isolated_hosts_passes_non_isolated_on_non_isolated(self):
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_isolated_hosts_less_restrictive(self):
# If there are isolated hosts and non isolated images
self.assertTrue(self._do_test_isolated_hosts(True, False, True, False))
# If there are isolated hosts and isolated images
self.assertTrue(self._do_test_isolated_hosts(True, True, True, False))
# If there are non isolated hosts and non isolated images
self.assertTrue(self._do_test_isolated_hosts(False, False, True,
False))
# If there are non isolated hosts and isolated images
self.assertFalse(self._do_test_isolated_hosts(False, True, True,
False))
def test_core_filter_passes(self):
filt_cls = self.class_map['CoreFilter']()
filter_properties = {'instance_type': {'vcpus': 1}}