From 8f7f889acbaa80625324f90ca19c5f5ef863c9fc Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Mon, 21 Sep 2015 15:24:33 +0200 Subject: [PATCH] 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 --- ironic_inspector/introspect.py | 5 +++-- ironic_inspector/test/test_introspect.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ironic_inspector/introspect.py b/ironic_inspector/introspect.py index f9c113e32..981eda337 100644 --- a/ironic_inspector/introspect.py +++ b/ironic_inspector/introspect.py @@ -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: diff --git a/ironic_inspector/test/test_introspect.py b/ironic_inspector/test/test_introspect.py index 037b1fd16..f2bbd509c 100644 --- a/ironic_inspector/test/test_introspect.py +++ b/ironic_inspector/test/test_introspect.py @@ -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()