Make affinity_filters use host_ip from DB not RPC
Instead of using host_ip from capabilities, which are being removed, get the host_ip from the same place the rest of scheduling information comes from, the database. Part of bp no-compute-fanout-to-scheduler Change-Id: I56a1cbb1903c20b347469d0ee5a8c6d89a21c44e
This commit is contained in:
		@@ -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)))
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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),
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user