Deal with uppercase MAC address in register-nodes

Ironic will downcase all MAC addresses that are registered, so if
the node description uses uppercase MAC addresses, they will not
be matched. Lowercase when checking MACs against the node mapping
to sort this out.

Change-Id: I322e5d9eeb3ed85dd42d67caff8c61cea8c23856
Closes-Bug: #1394084
This commit is contained in:
Steve Kowalik 2014-11-20 12:29:43 +11:00
parent 4ef5742010
commit e3dbe9ab6a
2 changed files with 28 additions and 2 deletions

View File

@ -156,8 +156,8 @@ def _populate_node_mapping(ironic_in_use, client):
def _get_node_id(node, node_map):
if node['pm_type'] == 'pxe_ssh':
for mac in node['mac']:
if mac in node_map['mac']:
return node_map['mac'][mac]
if mac.lower() in node_map['mac']:
return node_map['mac'][mac.lower()]
else:
if node['pm_addr'] in node_map['pm_addr']:
return node_map['pm_addr'][node['pm_addr']]

View File

@ -252,6 +252,32 @@ class NodesTest(base.TestCase):
ironic.node.update.assert_called_once_with(
ironic.node.get.return_value.uuid, mock.ANY)
def test_register_ironic_node_update_uppercase_mac(self):
node = self._get_node()
node['mac'][0] = node['mac'][0].upper()
ironic = mock.MagicMock()
node_map = {'mac': {'aaa': 1}}
def side_effect(*args, **kwargs):
update_patch = [
{'path': '/driver_info/ssh_key_contents', 'value': 'random'},
{'path': '/driver_info/ssh_address', 'value': 'foo.bar'},
{'path': '/properties/memory_mb', 'value': '2048'},
{'path': '/properties/local_gb', 'value': '30'},
{'path': '/properties/cpu_arch', 'value': 'amd64'},
{'path': '/properties/cpus', 'value': '1'},
{'path': '/driver_info/ssh_username', 'value': 'test'}]
for key in update_patch:
key['op'] = 'replace'
self.assertThat(update_patch,
matchers.MatchesSetwise(*(map(matchers.Equals,
args[1]))))
ironic.node.update.side_effect = side_effect
nodes._update_or_register_ironic_node(None, node, node_map,
client=ironic)
ironic.node.update.assert_called_once_with(
ironic.node.get.return_value.uuid, mock.ANY)
@mock.patch('time.sleep')
def test_register_ironic_node_update_locked_node(self, sleep):
node = self._get_node()