diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-18 16:45:03 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-18 16:45:03 +0000 |
| commit | 60ea96b288d9d8f29d772dce3763fda466c73040 (patch) | |
| tree | 20756824bd6aed2dcf68f9ff91427be9b218ee65 | |
| parent | fb9abcc83935b01746aeba0db4c431fe72b921fc (diff) | |
| parent | 31336b35b4604f70150d0073d77dbf63b9bf7598 (diff) | |
| download | nova-60ea96b288d9d8f29d772dce3763fda466c73040.tar.gz nova-60ea96b288d9d8f29d772dce3763fda466c73040.tar.xz nova-60ea96b288d9d8f29d772dce3763fda466c73040.zip | |
Merge "Add CPU arch filter scheduler support"
| -rw-r--r-- | nova/compute/api.py | 1 | ||||
| -rw-r--r-- | nova/scheduler/filters/arch_filter.py | 44 | ||||
| -rw-r--r-- | nova/tests/scheduler/test_host_filters.py | 54 | ||||
| -rw-r--r-- | nova/utils.py | 9 | ||||
| -rw-r--r-- | nova/virt/libvirt/connection.py | 4 |
5 files changed, 111 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index f11dcbe82..5bfb5b844 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -322,7 +322,6 @@ class API(base.Base): return value options_from_image = {'os_type': prop('os_type'), - 'architecture': prop('arch'), 'vm_mode': prop('vm_mode')} # If instance doesn't have auto_disk_config overridden by request, use diff --git a/nova/scheduler/filters/arch_filter.py b/nova/scheduler/filters/arch_filter.py new file mode 100644 index 000000000..1f11d07b6 --- /dev/null +++ b/nova/scheduler/filters/arch_filter.py @@ -0,0 +1,44 @@ +# Copyright (c) 2011-2012 OpenStack, LLC +# Copyright (c) 2012 Canonical Ltd +# 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 import log as logging +from nova.scheduler import filters +from nova import utils + + +LOG = logging.getLogger(__name__) + + +class ArchFilter(filters.BaseHostFilter): + """Filter out hosts that can not support the guest architecture. + Note: This is supported for libvirt only now. + """ + + def host_passes(self, host_state, filter_properties): + spec = filter_properties.get('request_spec', {}) + props = spec.get('instance_properties', {}) + + cpu_info = host_state.capabilities.get('cpu_info') + permitted_instances = cpu_info.get('permitted_instance_types', None) + + instance_arch = utils.sys_platform_translate(props.get('architecture')) + + if permitted_instances and instance_arch in permitted_instances: + return True + + LOG.warn(_('%(host_state)s fails permitted_instance_types'), locals()) + return False diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index 60f3577ac..80da5acd2 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -793,3 +793,57 @@ class HostFiltersTestCase(test.TestCase): request = self._make_zone_request('bad') host = fakes.FakeHostState('host1', 'compute', {'service': service}) self.assertFalse(filt_cls.host_passes(host, request)) + + def test_arch_filter_same(self): + permitted_instances = ['x86_64'] + filt_cls = self.class_map['ArchFilter']() + filter_properties = { + 'request_spec': { + 'instance_properties': {'architecture': 'x86_64'} + } + } + capabilities = {'enabled': True, + 'cpu_info': { + 'permitted_instance_types': permitted_instances + } + } + service = {'disabled': False} + host = fakes.FakeHostState('host1', 'compute', + {'capabilities': capabilities, 'service': service}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + def test_arch_filter_different(self): + permitted_instances = ['arm'] + filt_cls = self.class_map['ArchFilter']() + filter_properties = { + 'request_spec': { + 'instance_properties': {'architecture': 'x86_64'} + } + } + capabilities = {'enabled': True, + 'cpu_info': { + 'permitted_instance_types': permitted_instances + } + } + service = {'disabled': False} + host = fakes.FakeHostState('host1', 'compute', + {'capabilities': capabilities, 'service': service}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + + def test_arch_filter_without_permitted_instances(self): + permitted_instances = [] + filt_cls = self.class_map['ArchFilter']() + filter_properties = { + 'request_spec': { + 'instance_properties': {'architecture': 'x86_64'} + } + } + capabilities = {'enabled': True, + 'cpu_info': { + 'permitted_instance_types': permitted_instances + } + } + service = {'disabled': False} + host = fakes.FakeHostState('host1', 'compute', + {'capabilities': capabilities, 'service': service}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) diff --git a/nova/utils.py b/nova/utils.py index ddc998524..8bd71359f 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1321,6 +1321,15 @@ def strcmp_const_time(s1, s2): return result == 0 +def sys_platform_translate(arch): + """Translate cpu architecture into supported platforms.""" + if (arch[0] == 'i' and arch[1].isdigit() and arch[2:4] == '86'): + arch = 'i686' + elif arch.startswith('arm'): + arch = 'arm' + return arch + + class UndoManager(object): """Provides a mechanism to facilitate rolling back a series of actions when an exception is raised. diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 5118ca0be..ba4d90a4a 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -2008,8 +2008,12 @@ class LibvirtDriver(driver.ComputeDriver): for nodes in feature_nodes: features.append(nodes.get('name')) + arch_nodes = xml.findall('.//guest/arch') + guest_cpu_arches = list(node.get('name') for node in arch_nodes) + cpu_info['topology'] = topology cpu_info['features'] = features + cpu_info['permitted_instance_types'] = guest_cpu_arches return jsonutils.dumps(cpu_info) def block_stats(self, instance_name, disk): |
