From a1f430d30149637e07a288c70b40edd57600f8b8 Mon Sep 17 00:00:00 2001 From: yaguang tang Date: Thu, 7 Jun 2012 21:06:40 +0800 Subject: Fixes bug lp:999928 The CIDR affinity filter currently matches the scheduler's IP address against the network specified by the 'build_near_host_ip' and 'cidr' scheduler hints. It should be matching each compute host's IP address against the network in the scheduler hints. Ensure that the compute host's IP address is reported as part of host_state and use this value in the filter. this issue has been talked at https://review.openstack.org/#/c/7470/ Change-Id: I14eac8797dfe8aaf870bb31ef7bf87edcf691f93 --- nova/compute/manager.py | 1 + nova/scheduler/filters/affinity_filter.py | 7 ++++--- nova/tests/scheduler/test_host_filters.py | 10 ++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 4735f4a76..ca113ba6f 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2385,6 +2385,7 @@ class ComputeManager(manager.SchedulerDependentManager): # This will grab info about the host and queue it # to be sent to the Schedulers. capabilities = _get_additional_capabilities() + capabilities['host_ip'] = FLAGS.my_ip capabilities.update(self.driver.get_host_stats(refresh=True)) self.update_service_capabilities(capabilities) diff --git a/nova/scheduler/filters/affinity_filter.py b/nova/scheduler/filters/affinity_filter.py index e6e7a116a..2e4d8938d 100644 --- a/nova/scheduler/filters/affinity_filter.py +++ b/nova/scheduler/filters/affinity_filter.py @@ -40,8 +40,7 @@ class DifferentHostFilter(AffinityFilter): affinity_uuids = scheduler_hints.get('different_host', []) if affinity_uuids: - return not any([i for i - in affinity_uuids + return not any([i for i in affinity_uuids if self._affinity_host(context, i) == me]) # With no different_host key return True @@ -72,10 +71,12 @@ class SimpleCIDRAffinityFilter(AffinityFilter): affinity_cidr = scheduler_hints.get('cidr', '/24') affinity_host_addr = scheduler_hints.get('build_near_host_ip') + host_ip = host_state.capabilities.get('host_ip') if affinity_host_addr: affinity_net = netaddr.IPNetwork(str.join('', (affinity_host_addr, affinity_cidr))) - return netaddr.IPAddress(flags.FLAGS.my_ip) in affinity_net + + return netaddr.IPAddress(host_ip) in affinity_net # We don't have an affinity host address. return True diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index b7a5402c8..c52dd058d 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -166,10 +166,9 @@ class HostFiltersTestCase(test.TestCase): def test_affinity_simple_cidr_filter_passes(self): filt_cls = self.class_map['SimpleCIDRAffinityFilter']() host = fakes.FakeHostState('host1', 'compute', {}) + host.capabilities = {'host_ip': '10.8.1.1'} - affinity_ip = flags.FLAGS.my_ip.split('.')[0:3] - affinity_ip.append('100') - affinity_ip = str.join('.', affinity_ip) + affinity_ip = "10.8.1.100" filter_properties = {'context': self.context.elevated(), 'scheduler_hints': { @@ -181,10 +180,9 @@ class HostFiltersTestCase(test.TestCase): def test_affinity_simple_cidr_filter_fails(self): filt_cls = self.class_map['SimpleCIDRAffinityFilter']() host = fakes.FakeHostState('host1', 'compute', {}) + host.capabilities = {'host_ip': '10.8.1.1'} - affinity_ip = flags.FLAGS.my_ip.split('.') - affinity_ip[-1] = '100' if affinity_ip[-1] != '100' else '101' - affinity_ip = str.join('.', affinity_ip) + affinity_ip = "10.8.1.100" filter_properties = {'context': self.context.elevated(), 'scheduler_hints': { -- cgit