diff --git a/ironic_inspector/introspect.py b/ironic_inspector/introspect.py index cb48d67f2..f351a7a62 100644 --- a/ironic_inspector/introspect.py +++ b/ironic_inspector/introspect.py @@ -54,8 +54,9 @@ def introspect(node_id, manage_boot=True, token=None): node_info=node) bmc_address, bmc_ipv4, bmc_ipv6 = ir_utils.get_ipmi_address(node) + lookup_attrs = list(filter(None, [bmc_ipv4, bmc_ipv6])) node_info = node_cache.start_introspection(node.uuid, - bmc_address=bmc_address, + bmc_address=lookup_attrs, manage_boot=manage_boot, ironic=ironic) diff --git a/ironic_inspector/test/unit/test_introspect.py b/ironic_inspector/test/unit/test_introspect.py index b93086fc6..ec4d8f4c4 100644 --- a/ironic_inspector/test/unit/test_introspect.py +++ b/ironic_inspector/test/unit/test_introspect.py @@ -66,7 +66,36 @@ class TestIntrospect(BaseTest): cli.node.validate.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], + manage_boot=True, + ironic=cli) + self.node_info.ports.assert_called_once_with() + self.node_info.add_attribute.assert_called_once_with('mac', + self.macs) + self.sync_filter_mock.assert_called_with(cli) + 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') + self.node_info.acquire_lock.assert_called_once_with() + self.node_info.release_lock.assert_called_once_with() + + @mock.patch.object(ir_utils, 'get_ipmi_address', autospec=True) + def test_resolved_bmc_address(self, ipmi_mock, client_mock, start_mock): + self.node.driver_info['ipmi_address'] = 'example.com' + addresses = ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'] + ipmi_mock.return_value = ('example.com',) + tuple(addresses) + cli = self._prepare(client_mock) + start_mock.return_value = self.node_info + + introspect.introspect(self.node.uuid) + + cli.node.get.assert_called_once_with(self.uuid) + cli.node.validate.assert_called_once_with(self.uuid) + + start_mock.assert_called_once_with(self.uuid, + bmc_address=addresses, manage_boot=True, ironic=cli) self.node_info.ports.assert_called_once_with() @@ -92,7 +121,7 @@ class TestIntrospect(BaseTest): cli.node.validate.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, - bmc_address=None, + bmc_address=[], manage_boot=True, ironic=cli) self.node_info.ports.assert_called_once_with() @@ -116,7 +145,7 @@ class TestIntrospect(BaseTest): introspect.introspect(self.node.uuid) start_mock.assert_called_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) @@ -130,7 +159,7 @@ class TestIntrospect(BaseTest): cli.node.get.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, @@ -153,7 +182,7 @@ class TestIntrospect(BaseTest): cli.node.get.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) self.assertFalse(cli.node.set_boot_device.called) @@ -172,7 +201,7 @@ class TestIntrospect(BaseTest): cli.node.get.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, @@ -194,7 +223,7 @@ class TestIntrospect(BaseTest): self.node_info.ports.assert_called_once_with() start_mock.assert_called_once_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) self.assertFalse(self.node_info.add_attribute.called) @@ -352,7 +381,7 @@ class TestIntrospect(BaseTest): cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, - bmc_address=self.bmc_address, + bmc_address=[self.bmc_address], manage_boot=False, ironic=cli) self.node_info.ports.assert_called_once_with()