Merge "Fix host manager node detection logic"
This commit is contained in:
commit
d90c5a3732
@ -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