diff --git a/src/hw_tools.py b/src/hw_tools.py index 7a47d67e..7e6cc180 100644 --- a/src/hw_tools.py +++ b/src/hw_tools.py @@ -365,6 +365,9 @@ def redfish_available() -> bool: except (SessionCreationError, InvalidCredentialsError): # redfish available, wrong credentials or not able to create a session result = True + except Exception: # pylint: disable=W0718 + # mark redfish unavailable for any generic exception + result = False else: # login succeeded with empty credentials result = True redfish_obj.logout() diff --git a/tests/unit/test_hw_tools.py b/tests/unit/test_hw_tools.py index f33a9c9e..b3319d84 100644 --- a/tests/unit/test_hw_tools.py +++ b/tests/unit/test_hw_tools.py @@ -716,6 +716,20 @@ def test_redfish_not_available(self, mock_bmc_address, mock_redfish_client): mock_redfish_client.assert_called_once() mock_redfish_obj.login.assert_called_once() + @mock.patch("hw_tools.redfish_client") + @mock.patch("hw_tools.get_bmc_address", return_value="1.2.3.4") + def test_redfish_not_available_generic(self, mock_bmc_address, mock_redfish_client): + mock_redfish_obj = mock.Mock() + mock_redfish_client.return_value = mock_redfish_obj + mock_redfish_obj.login.side_effect = Exception() + + result = redfish_available() + + self.assertEqual(result, False) + mock_bmc_address.assert_called_once() + mock_redfish_client.assert_called_once() + mock_redfish_obj.login.assert_called_once() + @mock.patch("hw_tools.redfish_client") @mock.patch("hw_tools.get_bmc_address", return_value="1.2.3.4") def test_redfish_available(self, mock_bmc_address, mock_redfish_client):