From 51c73d22fa8fe5a2e857331ef3c3b4480f250159 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Wed, 4 Dec 2024 17:09:38 +0100 Subject: [PATCH] Silence modprobe loading errors for IPMI drivers Debug messages from modprobe failing to load ipmi drivers can be confusing and they do not add anything since they're not really errors. This patch silence the message in the logs. Change-Id: I7452bc9e56148e3d423be92f384ff9aeffbe88d7 --- ironic_python_agent/hardware.py | 11 +++++++--- .../tests/unit/test_hardware.py | 22 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index da59781a2..66d16bab2 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -129,9 +129,14 @@ def _load_ipmi_modules(): This is required to be called at least once before attempting to use ipmitool or related tools. """ - utils.try_execute('modprobe', 'ipmi_msghandler') - utils.try_execute('modprobe', 'ipmi_devintf') - utils.try_execute('modprobe', 'ipmi_si') + + ipmi_drivers = ['ipmi_msghandler', 'ipmi_devintf', 'ipmi_si'] + for ipmi_driver in ipmi_drivers: + try: + processutils.execute('modprobe', ipmi_driver) + except (processutils.ProcessExecutionError, OSError): + LOG.debug("IPMI driver %s not supported or not present", + ipmi_driver) def _load_multipath_modules(): diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index 5823e168e..395b3c48f 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -5928,14 +5928,30 @@ class TestModuleFunctions(base.IronicAgentTest): mocked_execute.assert_has_calls([ mock.call('iscsistart', '-f')]) - @mock.patch.object(utils, 'try_execute', autospec=True) - def test__load_ipmi_modules(self, mocked_try_execute, me): + @mock.patch.object(processutils, 'execute', autospec=True) + def test__load_ipmi_modules(self, mocked_proc_execute, mocked_execute): hardware._load_ipmi_modules() - mocked_try_execute.assert_has_calls([ + mocked_proc_execute.assert_has_calls([ mock.call('modprobe', 'ipmi_msghandler'), mock.call('modprobe', 'ipmi_devintf'), mock.call('modprobe', 'ipmi_si')]) + @mock.patch.object(hardware, 'LOG', autospec=True) + @mock.patch.object(processutils, 'execute', autospec=True) + def test__load_ipmi_modules_fail(self, mocked_proc_execute, mocked_log, + mocked_execute): + mocked_proc_execute.side_effect = [ + processutils.ProcessExecutionError, + ('', ''), + ('', ''), + ] + hardware._load_ipmi_modules() + mocked_proc_execute.assert_has_calls([ + mock.call('modprobe', 'ipmi_msghandler'), + mock.call('modprobe', 'ipmi_devintf'), + mock.call('modprobe', 'ipmi_si')]) + mocked_log.debug.assert_called_once() + @mock.patch.object(utils, 'execute', autospec=True) class TestMultipathEnabled(base.IronicAgentTest):