Merge "Fix TypeError in _update_from_compute_node race"

This commit is contained in:
Jenkins
2017-01-07 00:47:20 +00:00
committed by Gerrit Code Review
4 changed files with 27 additions and 3 deletions

View File

@@ -183,7 +183,9 @@ class HostState(object):
"""Update information about a host from a ComputeNode object."""
# NOTE(jichenjc): if the compute record is just created but not updated
# some field such as free_disk_gb can be None
if compute.updated_at is None:
if 'free_disk_gb' not in compute or compute.free_disk_gb is None:
LOG.debug('Ignoring compute node %s as its usage has not been '
'updated yet.', compute.uuid)
return
if (self.updated and compute.updated_at

View File

@@ -21,6 +21,8 @@ This host manager will consume all cpu's, disk space, and
ram from a host / node as it is supporting Baremetal hosts, which can not be
subdivided into multiple instances.
"""
from oslo_log import log as logging
import nova.conf
from nova import context as context_module
from nova import objects
@@ -29,6 +31,8 @@ from nova.scheduler import host_manager
CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
class IronicNodeState(host_manager.HostState):
"""Mutable and immutable information tracked for a host.
@@ -38,6 +42,14 @@ class IronicNodeState(host_manager.HostState):
def _update_from_compute_node(self, compute):
"""Update information about a host from a ComputeNode object."""
# NOTE(jichenjc): if the compute record is just created but not updated
# some field such as free_disk_gb can be None
if 'free_disk_gb' not in compute or compute.free_disk_gb is None:
LOG.debug('Ignoring compute node %s as its usage has not been '
'updated yet.', compute.uuid)
return
self.vcpus_total = compute.vcpus
self.vcpus_used = compute.vcpus_used

View File

@@ -1218,7 +1218,7 @@ class HostStateTestCase(test.NoDBTestCase):
def test_stat_consumption_from_compute_node_not_ready(self):
compute = objects.ComputeNode(free_ram_mb=100,
updated_at=None)
uuid=uuids.compute_node_uuid)
host = host_manager.HostState("fakehost", "fakenode")
host._update_from_compute_node(compute)

View File

@@ -182,7 +182,8 @@ class IronicHostManagerChangedNodesTestCase(test.NoDBTestCase):
hypervisor_version=1,
hypervisor_hostname='fake_host',
cpu_allocation_ratio=16.0, ram_allocation_ratio=1.5,
disk_allocation_ratio=1.0)
disk_allocation_ratio=1.0,
uuid=uuids.compute_node_uuid)
@mock.patch.object(ironic_host_manager.IronicNodeState, '__init__')
def test_create_ironic_node_state(self, init_mock):
@@ -265,6 +266,15 @@ class IronicHostManagerChangedNodesTestCase(test.NoDBTestCase):
self.assertEqual(1, host.hypervisor_version)
self.assertEqual('fake_host', host.hypervisor_hostname)
def test_update_from_compute_node_not_ready(self):
"""Tests that we ignore a compute node that does not have its
free_disk_gb field set yet from the compute resource tracker.
"""
host = ironic_host_manager.IronicNodeState("fakehost", "fakenode")
self.compute_node.free_disk_gb = None
host.update(compute=self.compute_node)
self.assertEqual(0, host.free_disk_mb)
def test_consume_identical_instance_from_compute(self):
host = ironic_host_manager.IronicNodeState("fakehost", "fakenode")
host.update(compute=self.compute_node)