Fix host manager node detection logic
This is the last in a series of patches to prepare Ironic for the removal of capabilities in Nova HostManager. IronicHostManager used to rely on capabilities info to decide which host state class to use, VM or baremetal. This has been broken since host capabilities reporting were removed in Nova, resulting in Nova HostState class always being used. This patch fixes the detection logic in IronicHostManager to correctly choose IronicHostState class for use with baremetal nodes. Tests are added to verify that the correct class is used for both vm and baremetal nodes. In reality, the new detection logic will not start to deliver the correct HostState class until the Nova HostManager change has landed. Change-Id: Ifa47d721835cfea87e9d0bce87c7853dd6724b98 Closes-Bug: #1260265
This commit is contained in:
parent
9373b141c7
commit
09f07a79a2
@ -84,18 +84,17 @@ class IronicNodeState(host_manager.HostState):
|
||||
self.updated = timeutils.utcnow()
|
||||
|
||||
|
||||
def new_host_state(self, host, node, capabilities=None, service=None):
|
||||
def new_host_state(self, host, node, **kwargs):
|
||||
"""Returns an instance of IronicNodeState or HostState according to
|
||||
capabilities. If 'ironic_driver' is in capabilities, it returns an
|
||||
instance of IronicHostState. If not, returns an instance of HostState.
|
||||
compute['cpu_info']. If 'cpu_info' equals 'baremetal cpu', it returns an
|
||||
instance of IronicNodeState. If not, returns an instance of HostState.
|
||||
"""
|
||||
if capabilities is None:
|
||||
capabilities = {}
|
||||
cap = capabilities.get('compute', {})
|
||||
if bool(cap.get('ironic_driver')):
|
||||
return IronicNodeState(host, node, capabilities, service)
|
||||
compute = kwargs.get('compute')
|
||||
|
||||
if compute and compute.get('cpu_info') == 'baremetal cpu':
|
||||
return IronicNodeState(host, node, **kwargs)
|
||||
else:
|
||||
return host_manager.HostState(host, node, capabilities, service)
|
||||
return host_manager.HostState(host, node, **kwargs)
|
||||
|
||||
|
||||
class IronicHostManager(host_manager.HostManager):
|
||||
|
@ -17,6 +17,8 @@
|
||||
Tests For IronicHostManager
|
||||
"""
|
||||
|
||||
import mock
|
||||
|
||||
from ironic.nova.scheduler import ironic_host_manager
|
||||
from ironic.nova.tests.scheduler import ironic_fakes
|
||||
|
||||
@ -24,6 +26,7 @@ from nova import db
|
||||
from nova import exception
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.scheduler import filters
|
||||
from nova.scheduler import host_manager
|
||||
from nova import test
|
||||
|
||||
|
||||
@ -87,6 +90,22 @@ class IronicHostManagerChangedNodesTestCase(test.NoDBTestCase):
|
||||
'[["i386", "baremetal", "baremetal"]]',
|
||||
free_disk_gb=10, free_ram_mb=1024)
|
||||
|
||||
@mock.patch.object(ironic_host_manager.IronicNodeState, '__init__')
|
||||
def test_create_ironic_node_state(self, init_mock):
|
||||
init_mock.return_value = None
|
||||
compute = {'cpu_info': 'baremetal cpu'}
|
||||
host_state = self.host_manager.host_state_cls('fake-host', 'fake-node',
|
||||
compute=compute)
|
||||
self.assertIs(ironic_host_manager.IronicNodeState, type(host_state))
|
||||
|
||||
@mock.patch.object(host_manager.HostState, '__init__')
|
||||
def test_create_non_ironic_host_state(self, init_mock):
|
||||
init_mock.return_value = None
|
||||
compute = {'cpu_info': 'other cpu'}
|
||||
host_state = self.host_manager.host_state_cls('fake-host', 'fake-node',
|
||||
compute=compute)
|
||||
self.assertIs(host_manager.HostState, type(host_state))
|
||||
|
||||
def test_get_all_host_states_after_delete_one(self):
|
||||
context = 'fake_context'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user