Fix nodes registering with fake_pxe driver

The fake_pxe driver doesn't have any power control system to manage the
power state of the nodes so that things like pm_addr, pm_password, and
pm_user are not required for the driver. This patch fixes the assumption
in the os-cloud-config that those information will be present on the
json file when registering nodes.

Closes-Bug: #1495448
Change-Id: Ife39e1d81fbe0761fb843c59fd4787357489cf48
This commit is contained in:
Lucas Alvares Gomes
2015-09-14 11:42:48 +01:00
parent f08fea6880
commit 204b6f6f92
2 changed files with 41 additions and 3 deletions

View File

@@ -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"],
@@ -88,7 +89,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
@@ -123,7 +124,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:
@@ -148,7 +149,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()]

View File

@@ -304,6 +304,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()
@@ -351,9 +368,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))