From 365283d600bf78ecd18e2a6b2685f3f11820adc5 Mon Sep 17 00:00:00 2001 From: Sudeep Bhandari Date: Tue, 27 Jun 2023 14:29:39 +0545 Subject: [PATCH] Update unit tests for ssacli (#14) --- .../test_resources/ssacli/sample_outputs.py | 25 ++++++++++++++ tests/unit/test_ssacli.py | 33 +++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_resources/ssacli/sample_outputs.py b/tests/unit/test_resources/ssacli/sample_outputs.py index 08949a9..0952f0a 100644 --- a/tests/unit/test_resources/ssacli/sample_outputs.py +++ b/tests/unit/test_resources/ssacli/sample_outputs.py @@ -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 = """ @@ -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 = """ @@ -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 + +""" diff --git a/tests/unit/test_ssacli.py b/tests/unit/test_ssacli.py index fd3f763..1c24383 100644 --- a/tests/unit/test_ssacli.py +++ b/tests/unit/test_ssacli.py @@ -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 @@ -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): @@ -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) @@ -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) @@ -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")