Browse Source

Fix lookup when ipmi_address is a hostname

The commit 771f2d396b breaks it because
it tries to use hostname for lookup. Lookup must always use IP addresses,
because that's what `ipmitool lan print` outputs.

Change-Id: I62ff646b77e2d39f70bade11924b2a47e1173cb5
(cherry picked from commit b3088916c6)
changes/60/642760/2
Dmitry Tantsur 3 years ago committed by Bob Fournier
parent
commit
f66e207769
  1. 3
      ironic_inspector/introspect.py
  2. 45
      ironic_inspector/test/unit/test_introspect.py

3
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)

45
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()

Loading…
Cancel
Save