Allow empty lookup attributes if node_not_found_hook is provided

An operator might choose to completely replace our lookup with
a custom one, so we should not enforce even one attribute in this case.
If node is not found even using the hook, we will fail later.

Closes-Bug: #1497237
Change-Id: I61382fcff043c1f7388878ada459a157bd4f39fe
This commit is contained in:
Dmitry Tantsur 2015-09-21 15:24:33 +02:00
parent 3cdb38109f
commit 8f7f889acb
2 changed files with 21 additions and 2 deletions

View File

@ -126,7 +126,8 @@ def _background_introspect(ironic, node_info):
{'macs': macs, 'node': node_info.uuid})
firewall.update_filters(ironic)
if not node_info.attributes:
attrs = node_info.attributes
if CONF.processing.node_not_found_hook is None and not attrs:
raise utils.Error(
_('No lookup attributes were found for node %s, inspector won\'t '
'be able to find it after introspection. Consider creating '
@ -134,7 +135,7 @@ def _background_introspect(ironic, node_info):
LOG.info(_LI('The following attributes will be used for looking up '
'node %(uuid)s: %(attrs)s'),
{'attrs': node_info.attributes, 'uuid': node_info.uuid})
{'attrs': attrs, 'uuid': node_info.uuid})
if not node_info.options.get('new_ipmi_credentials'):
try:

View File

@ -195,6 +195,24 @@ class TestIntrospect(BaseTest):
self.assertEqual(0, filters_mock.call_count)
self.assertEqual(0, cli.node.set_power_state.call_count)
def test_no_lookup_attrs_with_node_not_found_hook(self, client_mock,
add_mock, filters_mock):
CONF.set_override('node_not_found_hook', 'example', 'processing')
cli = self._prepare(client_mock)
self.node_info.ports.return_value = []
add_mock.return_value = self.node_info
self.node_info.attributes = {}
introspect.introspect(self.uuid)
self.node_info.ports.assert_called_once_with()
self.assertFalse(self.node_info.finished.called)
cli.node.set_boot_device.assert_called_once_with(self.uuid,
'pxe',
persistent=False)
cli.node.set_power_state.assert_called_once_with(self.uuid,
'reboot')
def test_failed_to_get_node(self, client_mock, add_mock, filters_mock):
cli = client_mock.return_value
cli.node.get.side_effect = exceptions.NotFound()