Store good MAC's and interfaces in node_info after processing
This makes life easier for post-processing hooks and removes need to pass valid_macs to _process_node. Change-Id: I49191290b7941e88f7fcb25dba6a324e21acb63c
This commit is contained in:
parent
a29c3999fa
commit
0047d87f2d
|
@ -64,6 +64,9 @@ def process(node_info):
|
|||
'ipmi_address': bmc_address})
|
||||
LOG.info('Eligible interfaces are %s', valid_interfaces)
|
||||
|
||||
node_info['interfaces'] = valid_interfaces
|
||||
node_info['macs'] = valid_macs
|
||||
|
||||
cached_node = node_cache.pop_node(bmc_address=bmc_address, mac=valid_macs)
|
||||
ironic = utils.get_client()
|
||||
try:
|
||||
|
@ -83,15 +86,15 @@ def process(node_info):
|
|||
cached_node.uuid,
|
||||
code=403)
|
||||
|
||||
updated = _process_node(ironic, node, node_info, valid_macs)
|
||||
updated = _process_node(ironic, node, node_info)
|
||||
return {'node': updated.to_dict()}
|
||||
|
||||
|
||||
def _process_node(ironic, node, node_info, valid_macs):
|
||||
def _process_node(ironic, node, node_info):
|
||||
hooks = plugins_base.processing_hooks_manager()
|
||||
|
||||
ports = {}
|
||||
for mac in valid_macs:
|
||||
for mac in node_info['macs']:
|
||||
try:
|
||||
port = ironic.port.create(node_uuid=node.uuid, address=mac)
|
||||
ports[mac] = port
|
||||
|
|
|
@ -81,6 +81,8 @@ class TestProcess(BaseTest):
|
|||
self.macs = ['11:22:33:44:55:66', 'broken', '', '66:55:44:33:22:11']
|
||||
self.port = Mock(uuid='port_uuid')
|
||||
self.attributes = dict(bmc_address='1.2.3.4', mac=ANY)
|
||||
self.good_macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
|
||||
self.good_interfaces = ['em1', 'em4']
|
||||
|
||||
def _do_test(self, client_mock, pop_mock, filters_mock, pre_mock,
|
||||
post_mock):
|
||||
|
@ -90,7 +92,7 @@ class TestProcess(BaseTest):
|
|||
cli = client_mock.return_value
|
||||
|
||||
def fake_port_create(node_uuid, address):
|
||||
if address == '11:22:33:44:55:66':
|
||||
if address == self.good_macs[0]:
|
||||
return self.port
|
||||
else:
|
||||
raise exceptions.Conflict()
|
||||
|
@ -100,7 +102,7 @@ class TestProcess(BaseTest):
|
|||
started_at=time.time())
|
||||
cli.node.get.return_value = self.node
|
||||
post_mock.return_value = (['fake patch', 'fake patch 2'],
|
||||
{'11:22:33:44:55:66': ['port patch']})
|
||||
{self.good_macs[0]: ['port patch']})
|
||||
self.node.to_dict.return_value = self.data
|
||||
cli.node.update.side_effect = [None, self.node]
|
||||
|
||||
|
@ -109,8 +111,7 @@ class TestProcess(BaseTest):
|
|||
|
||||
pop_mock.assert_called_once_with(**self.attributes)
|
||||
cli.node.get.assert_called_once_with(self.node.uuid)
|
||||
self.assertEqual(['11:22:33:44:55:66', '66:55:44:33:22:11'],
|
||||
sorted(pop_mock.call_args[1]['mac']))
|
||||
self.assertEqual(self.good_macs, sorted(pop_mock.call_args[1]['mac']))
|
||||
|
||||
cli.node.update.assert_any_call(self.node.uuid,
|
||||
self.patch1 + ['fake patch',
|
||||
|
@ -118,9 +119,9 @@ class TestProcess(BaseTest):
|
|||
cli.node.update.assert_any_call(self.node.uuid, self.patch2)
|
||||
self.assertEqual(2, cli.node.update.call_count)
|
||||
cli.port.create.assert_any_call(node_uuid=self.node.uuid,
|
||||
address='11:22:33:44:55:66')
|
||||
address=self.good_macs[0])
|
||||
cli.port.create.assert_any_call(node_uuid=self.node.uuid,
|
||||
address='66:55:44:33:22:11')
|
||||
address=self.good_macs[1])
|
||||
self.assertEqual(2, cli.port.create.call_count)
|
||||
filters_mock.assert_called_once_with(cli)
|
||||
cli.port.update.assert_called_once_with(self.port.uuid, ['port patch'])
|
||||
|
@ -128,6 +129,9 @@ class TestProcess(BaseTest):
|
|||
pre_mock.assert_called_once_with(self.data)
|
||||
post_mock.assert_called_once_with(self.node, [self.port], self.data)
|
||||
|
||||
self.assertEqual(self.good_macs, sorted(self.data['macs']))
|
||||
self.assertEqual(self.good_interfaces, sorted(self.data['interfaces']))
|
||||
|
||||
def test_ok(self, client_mock, pop_mock, filters_mock, pre_mock,
|
||||
post_mock):
|
||||
self._do_test(client_mock, pop_mock, filters_mock, pre_mock, post_mock)
|
||||
|
@ -151,6 +155,7 @@ class TestProcess(BaseTest):
|
|||
pre_mock, post_mock):
|
||||
del self.data['interfaces']
|
||||
self.data['macs'] = self.macs
|
||||
self.good_interfaces = ['dummy0', 'dummy3']
|
||||
self._do_test(client_mock, pop_mock, filters_mock, pre_mock, post_mock)
|
||||
|
||||
def test_ports_for_inactive(self, client_mock, pop_mock, filters_mock,
|
||||
|
@ -158,6 +163,7 @@ class TestProcess(BaseTest):
|
|||
del self.data['interfaces']['em4']
|
||||
conf.CONF.set('discoverd', 'ports_for_inactive_interfaces',
|
||||
'true')
|
||||
self.good_interfaces = ['em1', 'em5']
|
||||
self._do_test(client_mock, pop_mock, filters_mock, pre_mock, post_mock)
|
||||
|
||||
def test_not_on_discovery(self, client_mock, pop_mock, filters_mock,
|
||||
|
|
Loading…
Reference in New Issue