summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2012-07-17 14:40:25 -0700
committerJoe Gordon <jogo@cloudscaling.com>2012-07-18 11:18:59 -0700
commit0c704cd87c094a37188ecb936c88ebf5a215c28c (patch)
treec4d05329b3fb2cf89c9e4221514940312be7ba72 /nova
parent8a54a9fee3e96c4f43f3f293fda9f6844db5cfc7 (diff)
Split ComputeFilter up.
Pull out compute capabilities to instance_type extra_specs into its own filter. ComputeFilter now only passes active compute nodes. Change-Id: If9b81bdd7b24faa8a27915a9e5de3e651f6ed0d0
Diffstat (limited to 'nova')
-rw-r--r--nova/scheduler/filters/compute_capabilities_filter.py48
-rw-r--r--nova/scheduler/filters/compute_filter.py27
-rw-r--r--nova/scheduler/host_manager.py3
-rw-r--r--nova/tests/scheduler/test_host_filters.py17
4 files changed, 69 insertions, 26 deletions
diff --git a/nova/scheduler/filters/compute_capabilities_filter.py b/nova/scheduler/filters/compute_capabilities_filter.py
new file mode 100644
index 000000000..691b8f910
--- /dev/null
+++ b/nova/scheduler/filters/compute_capabilities_filter.py
@@ -0,0 +1,48 @@
+# Copyright (c) 2011 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.
+
+from nova.openstack.common import log as logging
+from nova.scheduler import filters
+
+
+LOG = logging.getLogger(__name__)
+
+
+class ComputeCapabilitiesFilter(filters.BaseHostFilter):
+ """HostFilter hard-coded to work with InstanceType records."""
+
+ def _satisfies_extra_specs(self, capabilities, instance_type):
+ """Check that the capabilities provided by the compute service
+ satisfy the extra specs associated with the instance type"""
+ if 'extra_specs' not in instance_type:
+ return True
+
+ # NOTE(lorinh): For now, we are just checking exact matching on the
+ # values. Later on, we want to handle numerical
+ # values so we can represent things like number of GPU cards
+ for key, value in instance_type['extra_specs'].iteritems():
+ if capabilities.get(key, None) != value:
+ return False
+ return True
+
+ def host_passes(self, host_state, filter_properties):
+ """Return a list of hosts that can create instance_type."""
+ instance_type = filter_properties.get('instance_type')
+ if not self._satisfies_extra_specs(host_state.capabilities,
+ instance_type):
+ LOG.debug(_("%(host_state)s fails instance_type extra_specs "
+ "requirements"), locals())
+ return False
+ return True
diff --git a/nova/scheduler/filters/compute_filter.py b/nova/scheduler/filters/compute_filter.py
index 5ba078394..2d7c898d6 100644
--- a/nova/scheduler/filters/compute_filter.py
+++ b/nova/scheduler/filters/compute_filter.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 OpenStack, LLC.
+# Copyright (c) 2012 OpenStack, LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,24 +22,10 @@ LOG = logging.getLogger(__name__)
class ComputeFilter(filters.BaseHostFilter):
- """HostFilter hard-coded to work with InstanceType records."""
-
- def _satisfies_extra_specs(self, capabilities, instance_type):
- """Check that the capabilities provided by the compute service
- satisfy the extra specs associated with the instance type"""
- if 'extra_specs' not in instance_type:
- return True
-
- # NOTE(lorinh): For now, we are just checking exact matching on the
- # values. Later on, we want to handle numerical
- # values so we can represent things like number of GPU cards
- for key, value in instance_type['extra_specs'].iteritems():
- if capabilities.get(key, None) != value:
- return False
- return True
+ """Filter on active Compute nodes"""
def host_passes(self, host_state, filter_properties):
- """Return a list of hosts that can create instance_type."""
+ """Returns True for only active compute nodes"""
instance_type = filter_properties.get('instance_type')
if host_state.topic != 'compute' or not instance_type:
return True
@@ -51,10 +37,7 @@ class ComputeFilter(filters.BaseHostFilter):
"heard from in a while"), locals())
return False
if not capabilities.get("enabled", True):
- LOG.debug(_("%(host_state)s is disabled via capabs"), locals())
- return False
- if not self._satisfies_extra_specs(capabilities, instance_type):
- LOG.debug(_("%(host_state)s fails instance_type extra_specs "
- "requirements"), locals())
+ LOG.debug(_("%(host_state)s is disabled via capabilities"),
+ locals())
return False
return True
diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py
index 2c1d597b7..edca8c05c 100644
--- a/nova/scheduler/host_manager.py
+++ b/nova/scheduler/host_manager.py
@@ -46,7 +46,8 @@ host_manager_opts = [
default=[
'AvailabilityZoneFilter',
'RamFilter',
- 'ComputeFilter'
+ 'ComputeFilter',
+ 'ComputeCapabilitiesFilter'
],
help='Which filter class names to use for filtering hosts '
'when not specified in the request.'),
diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py
index c6fabc1b5..f2b549399 100644
--- a/nova/tests/scheduler/test_host_filters.py
+++ b/nova/tests/scheduler/test_host_filters.py
@@ -338,6 +338,17 @@ class HostFiltersTestCase(test.TestCase):
'service': service})
self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ def test_compute_filter_fails_on_capability_disabled(self):
+ self._stub_service_is_up(True)
+ filt_cls = self.class_map['ComputeFilter']()
+ filter_properties = {'instance_type': {'memory_mb': 1024}}
+ capabilities = {'enabled': False}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1', 'compute',
+ {'free_ram_mb': 1024, 'capabilities': capabilities,
+ 'service': service})
+ self.assertFalse(filt_cls.host_passes(host, filter_properties))
+
def test_compute_filter_passes_on_volume(self):
self._stub_service_is_up(True)
filt_cls = self.class_map['ComputeFilter']()
@@ -362,7 +373,7 @@ class HostFiltersTestCase(test.TestCase):
def test_compute_filter_passes_extra_specs(self):
self._stub_service_is_up(True)
- filt_cls = self.class_map['ComputeFilter']()
+ filt_cls = self.class_map['ComputeCapabilitiesFilter']()
extra_specs = {'opt1': 1, 'opt2': 2}
capabilities = {'enabled': True, 'opt1': 1, 'opt2': 2}
service = {'disabled': False}
@@ -375,7 +386,7 @@ class HostFiltersTestCase(test.TestCase):
def test_compute_filter_fails_extra_specs(self):
self._stub_service_is_up(True)
- filt_cls = self.class_map['ComputeFilter']()
+ filt_cls = self.class_map['ComputeCapabilitiesFilter']()
extra_specs = {'opt1': 1, 'opt2': 3}
capabilities = {'enabled': True, 'opt1': 1, 'opt2': 2}
service = {'disabled': False}
@@ -555,7 +566,7 @@ class HostFiltersTestCase(test.TestCase):
'service': service})
self.assertTrue(filt_cls.host_passes(host, filter_properties))
- # Failes due to caps disabled
+ # Fails due to capabilities being disabled
capabilities = {'enabled': False, 'opt1': 'match'}
service = {'disabled': False}
host = fakes.FakeHostState('host1', 'instance_type',