Skip to content

Commit

Permalink
Catch generic error while verifying redfish availablity.
Browse files Browse the repository at this point in the history
  • Loading branch information
chanchiwai-ray committed Nov 20, 2023
1 parent 497bba0 commit c22edfa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c22edfa

Please sign in to comment.