Skip to content

Commit

Permalink
Update unit tests for ssacli (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeephb authored Jun 27, 2023
1 parent e66a3de commit 365283d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
25 changes: 25 additions & 0 deletions tests/unit/test_resources/ssacli/sample_outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CTRL_ALL_SHOW = """
Smart Array P222 in Slot 2 (sn: PDSXH0BRH6G0QU)
Smart HBA P222 in Slot 3 (sn: PDSXH0BRH6G0QU)
"""
CTRL_SHOW_STATUS = """
Expand All @@ -12,6 +13,16 @@
Battery/Capacitor Status: OK
"""
CTRL_SHOW_STATUS_BAD = """
Smart HBA P22 in Slot 3
Random bad output line
Controller Status: OK
Cache Status: ERROR
Battery/Capacitor Status: OK
"""
CTRL_LD_ALL_SHOW_STATUS = """
Expand All @@ -24,3 +35,17 @@
physicaldrive 2I:0:2 (port 2I:box 0:bay 2, 1 TB): OK
"""

CTRL_LD_ALL_SHOW_STATUS_ABSENT = """
Error: The specified controller does not have any logical drive.
Arbitrary line
"""

CTRL_PD_ALL_SHOW_STATUS_ABSENT = """
Error: The specified controller does not have any physical drive.
Arbitrary line
"""
33 changes: 31 additions & 2 deletions tests/unit/test_ssacli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from test_resources.ssacli.sample_outputs import (
CTRL_ALL_SHOW,
CTRL_LD_ALL_SHOW_STATUS,
CTRL_LD_ALL_SHOW_STATUS_ABSENT,
CTRL_PD_ALL_SHOW_STATUS,
CTRL_PD_ALL_SHOW_STATUS_ABSENT,
CTRL_SHOW_STATUS,
CTRL_SHOW_STATUS_BAD,
)

from prometheus_hardware_exporter.collectors.ssacli import SsaCLI
Expand All @@ -20,7 +23,7 @@ def test_00__get_controller_slots_success(self, mock_call):
mock_call.return_value = Result(CTRL_ALL_SHOW, None)
ssacli = SsaCLI()
slots = ssacli._get_controller_slots()
self.assertEqual(slots, ["2"])
self.assertEqual(slots, ["2", "3"])

@patch.object(Command, "__call__")
def test_01__get_controller_slots_error(self, mock_call):
Expand All @@ -42,7 +45,19 @@ def test_10__get_controller_status_success(self, mock_call):
self.assertEqual(ctrl_status, expected_ctrl_status)

@patch.object(Command, "__call__")
def test_11__get_controller_status_error(self, mock_call):
def test_11__get_controller_status_success_bad(self, mock_call):
mock_call.return_value = Result(CTRL_SHOW_STATUS_BAD, None)
ssacli = SsaCLI()
ctrl_status = ssacli._get_controller_status(1)
expected_ctrl_status = {
"Controller Status": "OK",
"Cache Status": "ERROR",
"Battery/Capacitor Status": "OK",
}
self.assertEqual(ctrl_status, expected_ctrl_status)

@patch.object(Command, "__call__")
def test_12__get_controller_status_error(self, mock_call):
mock_call.return_value = Result("", True)
ssacli = SsaCLI()
ctrl_status = ssacli._get_controller_status(1)
Expand All @@ -63,6 +78,13 @@ def test_21__get_ld_status_error(self, mock_call):
ld_status = ssacli._get_ld_status(1)
self.assertEqual(ld_status, {})

@patch.object(Command, "__call__")
def test_22__get_ld_status_absent(self, mock_call):
mock_call.return_value = Result(CTRL_LD_ALL_SHOW_STATUS_ABSENT, None)
ssacli = SsaCLI()
ld_status = ssacli._get_ld_status(1)
self.assertEqual(ld_status, {})

@patch.object(Command, "__call__")
def test_30__get_pd_status_success(self, mock_call):
mock_call.return_value = Result(CTRL_PD_ALL_SHOW_STATUS, None)
Expand All @@ -78,6 +100,13 @@ def test_31__get_pd_status_error(self, mock_call):
pd_status = ssacli._get_pd_status(1)
self.assertEqual(pd_status, {})

@patch.object(Command, "__call__")
def test_32__get_pd_status_absent(self, mock_call):
mock_call.return_value = Result(CTRL_PD_ALL_SHOW_STATUS_ABSENT, None)
ssacli = SsaCLI()
pd_status = ssacli._get_pd_status(1)
self.assertEqual(pd_status, {})

@patch.object(SsaCLI, "_get_controller_slots")
@patch.object(SsaCLI, "_get_controller_status")
@patch.object(SsaCLI, "_get_ld_status")
Expand Down

0 comments on commit 365283d

Please sign in to comment.