summaryrefslogtreecommitdiff
path: root/ironic_python_agent/tests/unit
diff options
context:
space:
mode:
authorJonas Schäfer <jonas.schaefer@cloudandheat.com>2021-07-19 09:20:24 +0200
committerJonas Schäfer <jonas.schaefer@cloudandheat.com>2021-08-06 13:14:45 +0200
commit61af712fe52d474d688d677e7e678a45ca0336ab (patch)
tree8bec1596488916757bc5238dad37ac052fc18d81 /ironic_python_agent/tests/unit
parent21c24abe6119083c739667ddc8dae5536e1b3c2e (diff)
downloadironic-python-agent-61af712fe52d474d688d677e7e678a45ca0336ab.tar.gz
Expose BMC MAC address in inventory data
This exposes the MAC address of the first LAN channel with an assigned IP address in the inventory data. This is useful for inventory processes where the asset number is not discoverable from the software side: the BMC MAC is going to be unique (at least within an organization). Change-Id: I8a4bee0c25743befd7f2033e4e0cba26895c8926
Diffstat (limited to 'ironic_python_agent/tests/unit')
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index 61001260..44b2a87d 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -1165,6 +1165,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
current_boot_mode='bios', pxe_interface='boot:if')
self.hardware.get_bmc_address = mock.Mock()
+ self.hardware.get_bmc_mac = mock.Mock()
self.hardware.get_bmc_v6address = mock.Mock()
self.hardware.get_system_vendor_info = mock.Mock()
@@ -2302,6 +2303,68 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch.object(il_utils, 'try_execute', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac_not_available(self, mocked_execute, mte):
+ mocked_execute.return_value = '', ''
+ self.assertRaises(errors.IncompatibleHardwareMethodError,
+ self.hardware.get_bmc_mac)
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac(self, mocked_execute, mte):
+ mocked_execute.return_value = '192.1.2.3\n01:02:03:04:05:06', ''
+ self.assertEqual('01:02:03:04:05:06', self.hardware.get_bmc_mac())
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac_virt(self, mocked_execute, mte):
+ mocked_execute.side_effect = processutils.ProcessExecutionError()
+ self.assertIsNone(self.hardware.get_bmc_mac())
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac_zeroed(self, mocked_execute, mte):
+ mocked_execute.return_value = '0.0.0.0\n00:00:00:00:00:00', ''
+ self.assertRaises(errors.IncompatibleHardwareMethodError,
+ self.hardware.get_bmc_mac)
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac_invalid(self, mocked_execute, mte):
+ # In case of invalid lan channel, stdout is empty and the error
+ # on stderr is "Invalid channel"
+ mocked_execute.return_value = '\n', 'Invalid channel: 55'
+ self.assertRaises(errors.IncompatibleHardwareMethodError,
+ self.hardware.get_bmc_mac)
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac_random_error(self, mocked_execute, mte):
+ mocked_execute.return_value = ('192.1.2.3\n00:00:00:00:00:02',
+ 'Random error message')
+ self.assertEqual('00:00:00:00:00:02', self.hardware.get_bmc_mac())
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_bmc_mac_iterate_channels(self, mocked_execute, mte):
+ # For channel 1 we simulate unconfigured IP
+ # and for any other we return a correct IP address
+ def side_effect(*args, **kwargs):
+ if args[0].startswith("ipmitool lan print 1"):
+ return '', 'Invalid channel 1\n'
+ elif args[0].startswith("ipmitool lan print 2"):
+ return '0.0.0.0\n00:00:00:00:23:42', ''
+ elif args[0].startswith("ipmitool lan print 3"):
+ return 'meow', ''
+ elif args[0].startswith("ipmitool lan print 4"):
+ return '192.1.2.3\n01:02:03:04:05:06', ''
+ else:
+ # this should never happen because the previous one was good
+ raise AssertionError
+ mocked_execute.side_effect = side_effect
+ self.assertEqual('01:02:03:04:05:06', self.hardware.get_bmc_mac())
+
+ @mock.patch.object(il_utils, 'try_execute', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
def test_get_bmc_v6address_not_enabled(self, mocked_execute, mte):
mocked_execute.side_effect = [('ipv4\n', '')] * 11
self.assertEqual('::/0', self.hardware.get_bmc_v6address())