Merge "Fix nodes registering with fake_pxe driver"
This commit is contained in:
commit
e09d60d68c
@ -26,6 +26,7 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _extract_driver_info(node):
|
||||
driver_info = {}
|
||||
if "ipmi" in node["pm_type"]:
|
||||
driver_info = {"ipmi_address": node["pm_addr"],
|
||||
"ipmi_username": node["pm_user"],
|
||||
@ -93,7 +94,7 @@ def register_ironic_node(service_host, node, client=None, blocking=True):
|
||||
|
||||
for count in range(60):
|
||||
LOG.debug('Registering %s node with ironic, try #%d.' %
|
||||
(node["pm_addr"], count))
|
||||
(node.get("pm_addr", ''), count))
|
||||
try:
|
||||
ironic_node = client.node.create(**create_map)
|
||||
break
|
||||
@ -128,7 +129,7 @@ def _populate_node_mapping(client):
|
||||
nodes = [n.to_dict() for n in client.node.list()]
|
||||
for node in nodes:
|
||||
node_details = client.node.get(node['uuid'])
|
||||
if node_details.driver == 'pxe_ssh':
|
||||
if node_details.driver in ('pxe_ssh', 'fake_pxe'):
|
||||
for port in client.node.list_ports(node['uuid']):
|
||||
node_map['mac'][port.address] = node['uuid']
|
||||
elif 'ipmi' in node_details.driver:
|
||||
@ -153,7 +154,7 @@ def _populate_node_mapping(client):
|
||||
|
||||
|
||||
def _get_node_id(node, node_map):
|
||||
if node['pm_type'] == 'pxe_ssh':
|
||||
if node['pm_type'] in ('pxe_ssh', 'fake_pxe'):
|
||||
for mac in node['mac']:
|
||||
if mac.lower() in node_map['mac']:
|
||||
return node_map['mac'][mac.lower()]
|
||||
|
@ -325,6 +325,23 @@ class NodesTest(base.TestCase):
|
||||
properties=node_properties,
|
||||
driver_info=mock.ANY)
|
||||
|
||||
def test_register_ironic_node_fake_pxe(self):
|
||||
node_properties = {"cpus": "1",
|
||||
"memory_mb": "2048",
|
||||
"local_gb": "30",
|
||||
"cpu_arch": "amd64",
|
||||
"capabilities": "num_nics:6"}
|
||||
node = self._get_node()
|
||||
for v in ('pm_addr', 'pm_user', 'pm_password'):
|
||||
del node[v]
|
||||
node['pm_type'] = 'fake_pxe'
|
||||
client = mock.MagicMock()
|
||||
nodes.register_ironic_node('service_host', node, client=client)
|
||||
client.node.create.assert_called_once_with(driver='fake_pxe',
|
||||
name='node1',
|
||||
properties=node_properties,
|
||||
driver_info={})
|
||||
|
||||
def test_register_ironic_node_update_int_values(self):
|
||||
node = self._get_node()
|
||||
ironic = mock.MagicMock()
|
||||
@ -372,9 +389,29 @@ class NodesTest(base.TestCase):
|
||||
'pm_addr': {'10.0.1.2': 'fedcba'}}
|
||||
self.assertEqual(expected, nodes._populate_node_mapping(client))
|
||||
|
||||
def test_populate_node_mapping_ironic_fake_pxe(self):
|
||||
client = mock.MagicMock()
|
||||
node = mock.MagicMock()
|
||||
node.to_dict.return_value = {'uuid': 'abcdef'}
|
||||
ironic_node = collections.namedtuple('node', ['uuid', 'driver',
|
||||
'driver_info'])
|
||||
ironic_port = collections.namedtuple('port', ['address'])
|
||||
node_detail = ironic_node('abcdef', 'fake_pxe', None)
|
||||
client.node.get.return_value = node_detail
|
||||
client.node.list_ports.return_value = [ironic_port('aaa')]
|
||||
client.node.list.return_value = [node]
|
||||
expected = {'mac': {'aaa': 'abcdef'}, 'pm_addr': {}}
|
||||
self.assertEqual(expected, nodes._populate_node_mapping(client))
|
||||
|
||||
def test_clean_up_extra_nodes_ironic(self):
|
||||
node = collections.namedtuple('node', ['uuid'])
|
||||
client = mock.MagicMock()
|
||||
client.node.list.return_value = [node('foobar')]
|
||||
nodes._clean_up_extra_nodes(set(('abcd',)), client, remove=True)
|
||||
client.node.delete.assert_called_once_with('foobar')
|
||||
|
||||
def test__get_node_id_fake_pxe(self):
|
||||
node = self._get_node()
|
||||
node['pm_type'] = 'fake_pxe'
|
||||
node_map = {'mac': {'aaa': 'abcdef'}, 'pm_addr': {}}
|
||||
self.assertEqual('abcdef', nodes._get_node_id(node, node_map))
|
||||
|
Loading…
x
Reference in New Issue
Block a user