diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-01-23 20:12:59 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-01-23 20:12:59 +0000 |
| commit | 1bb45d07a2ce0747e338350a286e788d11447e21 (patch) | |
| tree | 5b867ab636ab3b4daee7f7dffdc5f641e40503d3 | |
| parent | 152da40a0651bfbdeb748c249e771c10e716c79c (diff) | |
| parent | 972fc7d80fae386cf4c72b7891f6601d6f7fb00b (diff) | |
Merge "Adds isolated hosts filter"
| -rw-r--r-- | nova/flags.py | 2 | ||||
| -rw-r--r-- | nova/scheduler/filters/__init__.py | 1 | ||||
| -rw-r--r-- | nova/scheduler/filters/isolated_hosts_filter.py | 33 | ||||
| -rw-r--r-- | nova/scheduler/simple.py | 2 | ||||
| -rw-r--r-- | nova/tests/scheduler/test_host_filters.py | 68 |
5 files changed, 80 insertions, 26 deletions
diff --git a/nova/flags.py b/nova/flags.py index b9aad32b5..4345b4777 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -469,3 +469,5 @@ DEFINE_integer('service_down_time', 60, 'maximum time since last check-in for up service') DEFINE_string('default_schedule_zone', None, 'zone to use when user doesnt specify one') +DEFINE_list('isolated_images', [], 'Images to run on isolated host') +DEFINE_list('isolated_hosts', [], 'Host reserved for specific images') diff --git a/nova/scheduler/filters/__init__.py b/nova/scheduler/filters/__init__.py index a1a704c25..ecd0cd7b0 100644 --- a/nova/scheduler/filters/__init__.py +++ b/nova/scheduler/filters/__init__.py @@ -32,6 +32,7 @@ InstanceType filter. from abstract_filter import AbstractHostFilter from all_hosts_filter import AllHostsFilter +from isolated_hosts_filter import IsolatedHostsFilter from compute_filter import ComputeFilter from core_filter import CoreFilter from json_filter import JsonFilter diff --git a/nova/scheduler/filters/isolated_hosts_filter.py b/nova/scheduler/filters/isolated_hosts_filter.py new file mode 100644 index 000000000..82478ab7a --- /dev/null +++ b/nova/scheduler/filters/isolated_hosts_filter.py @@ -0,0 +1,33 @@ +# Copyright (c) 2011-2012 Openstack, LLC. +# All Rights Reserved. +# +# 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. + + +import abstract_filter +from nova import flags + + +FLAGS = flags.FLAGS + + +class IsolatedHostsFilter(abstract_filter.AbstractHostFilter): + """Returns host.""" + + def host_passes(self, host_state, filter_properties): + spec = filter_properties.get('request_spec', {}) + props = spec.get('instance_properties', {}) + image_ref = props.get('image_ref') + image_isolated = image_ref in FLAGS.isolated_images + host_isolated = host_state.host in FLAGS.isolated_hosts + return image_isolated == host_isolated diff --git a/nova/scheduler/simple.py b/nova/scheduler/simple.py index 9ce3473ee..a61005bfa 100644 --- a/nova/scheduler/simple.py +++ b/nova/scheduler/simple.py @@ -35,8 +35,6 @@ flags.DEFINE_integer("max_gigabytes", 10000, "maximum number of volume gigabytes to allow per host") flags.DEFINE_integer("max_networks", 1000, "maximum number of networks to allow per host") -flags.DEFINE_list('isolated_images', [], 'Images to run on isolated host') -flags.DEFINE_list('isolated_hosts', [], 'Host reserved for specific images') flags.DEFINE_boolean('skip_isolated_core_check', True, 'Allow overcommitting vcpus on isolated hosts') diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index 35f2dec20..6e9d34abb 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -135,6 +135,50 @@ class HostFiltersTestCase(test.TestCase): self.assertFalse(filt_cls.host_passes(host, filter_properties)) + def test_isolated_hosts_fails_isolated_on_non_isolated(self): + self.flags(isolated_images=['isolated'], isolated_hosts=['isolated']) + filt_cls = filters.IsolatedHostsFilter() + filter_properties = { + 'request_spec': { + 'instance_properties': {'image_ref': 'isolated'} + } + } + host = fakes.FakeHostState('non-isolated', 'compute', {}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + + def test_isolated_hosts_fails_non_isolated_on_isolated(self): + self.flags(isolated_images=['isolated'], isolated_hosts=['isolated']) + filt_cls = filters.IsolatedHostsFilter() + filter_properties = { + 'request_spec': { + 'instance_properties': {'image_ref': 'non-isolated'} + } + } + host = fakes.FakeHostState('isolated', 'compute', {}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + + def test_isolated_hosts_passes_isolated_on_isolated(self): + self.flags(isolated_images=['isolated'], isolated_hosts=['isolated']) + filt_cls = filters.IsolatedHostsFilter() + filter_properties = { + 'request_spec': { + 'instance_properties': {'image_ref': 'isolated'} + } + } + host = fakes.FakeHostState('isolated', 'compute', {}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + def test_isolated_hosts_passes_non_isolated_on_non_isolated(self): + self.flags(isolated_images=['isolated'], isolated_hosts=['isolated']) + filt_cls = filters.IsolatedHostsFilter() + filter_properties = { + 'request_spec': { + 'instance_properties': {'image_ref': 'non-isolated'} + } + } + host = fakes.FakeHostState('non-isolated', 'compute', {}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + def test_json_filter_passes(self): filt_cls = filters.JsonFilter() filter_properties = {'instance_type': {'memory_mb': 1024, @@ -182,18 +226,6 @@ class HostFiltersTestCase(test.TestCase): 'capabilities': capabilities}) self.assertFalse(filt_cls.host_passes(host, filter_properties)) - def test_json_filter_fails_on_disk(self): - filt_cls = filters.JsonFilter() - filter_properties = {'instance_type': {'memory_mb': 1024, - 'local_gb': 200}, - 'query': self.json_query} - capabilities = {'enabled': True} - host = fakes.FakeHostState('host1', 'compute', - {'free_ram_mb': 1024, - 'free_disk_mb': (200 * 1024) - 1, - 'capabilities': capabilities}) - self.assertFalse(filt_cls.host_passes(host, filter_properties)) - def test_json_filter_fails_on_caps_disabled(self): filt_cls = filters.JsonFilter() json_query = json.dumps( @@ -227,18 +259,6 @@ class HostFiltersTestCase(test.TestCase): 'capabilities': capabilities}) self.assertFalse(filt_cls.host_passes(host, filter_properties)) - def test_json_filter_passes(self): - filt_cls = filters.JsonFilter() - filter_properties = {'instance_type': {'memory_mb': 1024, - 'local_gb': 200}, - 'query': self.json_query} - capabilities = {'enabled': True} - host = fakes.FakeHostState('host1', 'compute', - {'free_ram_mb': 1024, - 'free_disk_mb': 200 * 1024, - 'capabilities': capabilities}) - self.assertTrue(filt_cls.host_passes(host, filter_properties)) - def test_json_filter_happy_day(self): """Test json filter more thoroughly""" filt_cls = filters.JsonFilter() |
