From 7361edb76fbe2d6b748f5558884e4a5da01f4597 Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Thu, 22 Aug 2024 15:31:12 +0200 Subject: [PATCH] tests: align tests and use --best-controller Add parameter tests for new command: --best-controller. Use new method to choose best controller for device. It is escpecially needed when VMD and NPEM are available on one platform. Skip IBPI test when drive is connected to better controller, than used to test. Test multipath drives only with best controller connected. Signed-off-by: Kinga Stefaniuk --- tests/conftest.py | 5 ---- tests/ledctl/ledctl_cmd.py | 25 ++++++++++--------- tests/ledctl/parameters_test.py | 3 ++- tests/ledctl/slot_test.py | 43 +++++++++++++++------------------ 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1c245c6b..e5481b3f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,10 +9,6 @@ [ "--slot-filters", "none", "List comma separated. Filter out slots starting with filter." - ], - [ - "--controller-filters", "none", - "List comma separated. Filter out controllers matching by name e.g. VMD, SCSI, NPEM." ] ] @@ -31,7 +27,6 @@ def pytest_generate_tests(metafunc): params = { "ledctl_binary": metafunc.config.option.ledctl_binary, "slot_filters": metafunc.config.option.slot_filters, - "controller_filters": metafunc.config.option.controller_filters } for param, val in params.items(): if param in metafunc.fixturenames and val is not None: diff --git a/tests/ledctl/ledctl_cmd.py b/tests/ledctl/ledctl_cmd.py index f6a22e56..d203c489 100644 --- a/tests/ledctl/ledctl_cmd.py +++ b/tests/ledctl/ledctl_cmd.py @@ -31,10 +31,7 @@ class LedctlCmd: # These base states should be supported by all controllers base_states = ["failure", "locate", "normal", "rebuild"] - def __init__(self, - ledctl_bin=["none"], - slot_filters="none", - controller_filters="none"): + def __init__(self, ledctl_bin=["none"], slot_filters="none"): # We cares about first entry (not full valdation but it is enough for test purposes) self.bin = ledctl_bin[0] @@ -42,11 +39,6 @@ def __init__(self, # globally. self.slot_filters = slot_filters - # Give possibility to skip controllers. - self.slot_ctrls = [ - i for i in self.slot_mgmt_ctrls if i not in controller_filters - ] - def run_ledctl_cmd(self, params: list, output=False, check=True): params.insert(0, "sudo") params.insert(1, self.bin) @@ -105,6 +97,17 @@ def get_slot_by_device(self, slot: Slot): ]).stdout return self.parse_slot_line(slot.cntrl_type, out) + def get_slot_by_device_cntrl(self, dev_node, cntrl): + out = self.run_ledctl_cmd_valid( + ["--get-slot", "--controller-type", cntrl, "--device", + dev_node]).stdout + return self.parse_slot_line(cntrl, out) + + def best_controller_by_device(self, dev_node): + result = self.run_ledctl_cmd_valid( + ["--best-controller", "--device", dev_node]).stdout + return result.rstrip() + def list_slots(self, controller_type): rc = [] out = self.run_ledctl_cmd_valid( @@ -148,7 +151,7 @@ def get_controllers_with_slot_functionality(self): out = self.run_ledctl_cmd_valid(["--list-controllers"]).stdout for raw_line in out.split("\n"): line = raw_line.strip() - for ctrl in self.slot_ctrls: + for ctrl in self.slot_mgmt_ctrls: if ctrl in line: rc[ctrl] = True break @@ -156,7 +159,7 @@ def get_controllers_with_slot_functionality(self): # Respect controller filter def get_slots(self, cntrl): - if cntrl not in self.slot_ctrls: + if cntrl not in self.slot_mgmt_ctrls: raise AssertionError(f"Controller \"{cntrl}\" filtered out") return self.list_slots(cntrl) diff --git a/tests/ledctl/parameters_test.py b/tests/ledctl/parameters_test.py index 32cbf59b..1da01757 100644 --- a/tests/ledctl/parameters_test.py +++ b/tests/ledctl/parameters_test.py @@ -33,7 +33,8 @@ def test_parameters_are_valid_long_test_flag(ledctl_binary): "-G -n vmd -p 1 -r state -T", "--get-slot --controller-type=vmd --slot=1 --print=state -T", "-S -n vmd -p 1 -s normal -T", - "--set-slot --controller-type=vmd --slot=1 --state=normal -T" + "--set-slot --controller-type=vmd --slot=1 --state=normal -T", + "-B -d /dev/nvme0n1 -T", "--best-controller --device /dev/nvme0n1 -T" ], ) def test_parameters_are_valid_short_test_flag(ledctl_binary, diff --git a/tests/ledctl/slot_test.py b/tests/ledctl/slot_test.py index 21a82c02..127454e0 100644 --- a/tests/ledctl/slot_test.py +++ b/tests/ledctl/slot_test.py @@ -36,17 +36,22 @@ def verify_state(slot, current, expected, msg): @pytest.mark.parametrize("cntrl", LedctlCmd.slot_mgmt_ctrls) -def test_ibpi(ledctl_binary, slot_filters, controller_filters, cntrl): +def test_ibpi(ledctl_binary, slot_filters, cntrl): """ Test setting the led status by using IBPI syntax for the disk under the chosen controller. Limited to controllers with slots feature support. """ - cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) + cmd = LedctlCmd(ledctl_binary, slot_filters) slots_with_device_node = get_slots_with_device_or_skip(cmd, cntrl) + tested = False for slot in slots_with_device_node: + best_cntrl = cmd.best_controller_by_device(slot.device_node) + if best_cntrl != slot.cntrl_type: + continue for state in LedctlCmd.base_states: + tested = True cmd.set_ibpi(slot.device_node, state) cur = cmd.get_slot(slot) verify_state( @@ -54,15 +59,17 @@ def test_ibpi(ledctl_binary, slot_filters, controller_filters, cntrl): f"unable to set \"{slot.device_node}\" to \"{state}\", current = \"{cur.state}\" using ibpi syntax" ) + if tested == False: + pytest.skip("All drives are connected to better controller") + @pytest.mark.parametrize("cntrl", LedctlCmd.slot_mgmt_ctrls) -def test_set_slot_by_slot(ledctl_binary, slot_filters, controller_filters, - cntrl): +def test_set_slot_by_slot(ledctl_binary, slot_filters, cntrl): """ Test that we can set slots to different states and verify that they reported a change, using --slot. """ - cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) + cmd = LedctlCmd(ledctl_binary, slot_filters) try: slots = [s for s in cmd.get_slots(cntrl)] except AssertionError as e: @@ -92,41 +99,32 @@ def slot_set_and_get_by_device_all(cmd: LedctlCmd, slot): @pytest.mark.parametrize("cntrl", LedctlCmd.slot_mgmt_ctrls) -def test_set_slot_by_device(ledctl_binary, slot_filters, controller_filters, - cntrl): +def test_set_slot_by_device(ledctl_binary, slot_filters, cntrl): """ Test that we can set slots to different states and verify that they reported a change, using device. """ - cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) + cmd = LedctlCmd(ledctl_binary, slot_filters) slots_with_device_node = get_slots_with_device_or_skip(cmd, cntrl) for slot in slots_with_device_node: slot_set_and_get_by_device_all(cmd, slot) -@pytest.mark.parametrize("cntrl", ["VMD", "NPEM"]) -def test_nvme_multipath_drives(ledctl_binary, slot_filters, controller_filters, - cntrl): +def test_nvme_multipath_drives(ledctl_binary, slot_filters): """ Special test for multipath drives using both set methods and get via device. We need to check if ledctl provides nvme multipath minimal support. """ - cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) + cmd = LedctlCmd(ledctl_binary, slot_filters) mp_drives = cmd.get_mp_nodes() if len(mp_drives) == 0: pytest.skip("No nvme multipath drives found") - slots_with_device_node = get_slots_with_device_or_skip(cmd, cntrl) - any_found = False - - for slot in slots_with_device_node: - if slot.device_node not in mp_drives: - continue - any_found = True - - LOGGER.debug(f"Found nvme multipath drive {slot}") + for mp_drive in mp_drives: + mp_cntrl = cmd.best_controller_by_device(mp_drive) + slot = cmd.get_slot_by_device_cntrl(mp_drive, mp_cntrl) for state in cmd.base_states: cmd.set_ibpi(slot.device_node, state) @@ -137,6 +135,3 @@ def test_nvme_multipath_drives(ledctl_binary, slot_filters, controller_filters, ) slot_set_and_get_by_device_all(cmd, slot) - - if not any_found: - pytest.skip("Multipath drives are not connected to tested controller")