diff --git a/nova/scheduler/filters/affinity_filter.py b/nova/scheduler/filters/affinity_filter.py index 2fd21b1dd6d3..a2fce180d909 100644 --- a/nova/scheduler/filters/affinity_filter.py +++ b/nova/scheduler/filters/affinity_filter.py @@ -87,7 +87,7 @@ 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') + host_ip = host_state.host_ip if affinity_host_addr: affinity_net = netaddr.IPNetwork(str.join('', (affinity_host_addr, affinity_cidr))) diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 15e0f5c3a893..707cf45f9148 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -120,6 +120,9 @@ class HostState(object): self.num_instances_by_os_type = {} self.num_io_ops = 0 + # Other information + self.host_ip = None + # Resource oversubscription values for the compute host: self.limits = {} @@ -158,6 +161,8 @@ class HostState(object): self.vcpus_used = compute['vcpus_used'] self.updated = compute['updated_at'] + self.host_ip = compute['host_ip'] + stats = compute.get('stats', []) statmap = self._statmap(stats) diff --git a/nova/tests/scheduler/fakes.py b/nova/tests/scheduler/fakes.py index 0ceb452829b0..0469c9258ca6 100644 --- a/nova/tests/scheduler/fakes.py +++ b/nova/tests/scheduler/fakes.py @@ -29,22 +29,22 @@ COMPUTE_NODES = [ disk_available_least=512, free_ram_mb=512, vcpus_used=1, free_disk_mb=512, local_gb_used=0, updated_at=None, service=dict(host='host1', disabled=False), - hypervisor_hostname='node1'), + hypervisor_hostname='node1', host_ip='127.0.0.1'), dict(id=2, local_gb=2048, memory_mb=2048, vcpus=2, disk_available_least=1024, free_ram_mb=1024, vcpus_used=2, free_disk_mb=1024, local_gb_used=0, updated_at=None, service=dict(host='host2', disabled=True), - hypervisor_hostname='node2'), + hypervisor_hostname='node2', host_ip='127.0.0.1'), dict(id=3, local_gb=4096, memory_mb=4096, vcpus=4, disk_available_least=3072, free_ram_mb=3072, vcpus_used=1, free_disk_mb=3072, local_gb_used=0, updated_at=None, service=dict(host='host3', disabled=False), - hypervisor_hostname='node3'), + hypervisor_hostname='node3', host_ip='127.0.0.1'), dict(id=4, local_gb=8192, memory_mb=8192, vcpus=8, disk_available_least=8192, free_ram_mb=8192, vcpus_used=0, free_disk_mb=8192, local_gb_used=0, updated_at=None, service=dict(host='host4', disabled=False), - hypervisor_hostname='node4'), + hypervisor_hostname='node4', host_ip='127.0.0.1'), # Broken entry dict(id=5, local_gb=1024, memory_mb=1024, vcpus=1, service=None), ] diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index dcfe75c2590a..b78dc6aee15a 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -401,7 +401,7 @@ class HostFiltersTestCase(test.NoDBTestCase): def test_affinity_simple_cidr_filter_passes(self): filt_cls = self.class_map['SimpleCIDRAffinityFilter']() host = fakes.FakeHostState('host1', 'node1', {}) - host.capabilities = {'host_ip': '10.8.1.1'} + host.host_ip = '10.8.1.1' affinity_ip = "10.8.1.100" @@ -415,7 +415,7 @@ class HostFiltersTestCase(test.NoDBTestCase): def test_affinity_simple_cidr_filter_fails(self): filt_cls = self.class_map['SimpleCIDRAffinityFilter']() host = fakes.FakeHostState('host1', 'node1', {}) - host.capabilities = {'host_ip': '10.8.1.1'} + host.host_ip = '10.8.1.1' affinity_ip = "10.8.1.100" diff --git a/nova/tests/scheduler/test_host_manager.py b/nova/tests/scheduler/test_host_manager.py index 8db62bfea291..c6e9873d6be5 100644 --- a/nova/tests/scheduler/test_host_manager.py +++ b/nova/tests/scheduler/test_host_manager.py @@ -437,7 +437,7 @@ class HostStateTestCase(test.NoDBTestCase): ] compute = dict(stats=stats, memory_mb=0, free_disk_gb=0, local_gb=0, local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0, - updated_at=None) + updated_at=None, host_ip='127.0.0.1') host = host_manager.HostState("fakehost", "fakenode") host.update_from_compute_node(compute)