From 99cad2298d6b62f18c9b3dc9e816e23b39fca2f5 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 especially needed when VMD and NPEM are available on one platform. Skip IBPI test when drives are connected to better controller, than used to test. Test multipath drives only with best controller connected. Signed-off-by: Kinga Stefaniuk --- tests/ledctl/ledctl_cmd.py | 11 ++++++++++ tests/ledctl/parameters_test.py | 3 ++- tests/ledctl/slot_test.py | 38 ++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/tests/ledctl/ledctl_cmd.py b/tests/ledctl/ledctl_cmd.py index f6a22e56..db248cf5 100644 --- a/tests/ledctl/ledctl_cmd.py +++ b/tests/ledctl/ledctl_cmd.py @@ -105,6 +105,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( 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..5dac2ba7 100644 --- a/tests/ledctl/slot_test.py +++ b/tests/ledctl/slot_test.py @@ -27,6 +27,14 @@ def get_slots_with_device_or_skip(cmd: LedctlCmd, cntrl): return slots_with_device_node +def filter_by_best_controller(cmd: LedctlCmd, slots_to_test): + for slot in slots_to_test: + best_cntrl = cmd.best_controller_by_device(slot.device_node) + if best_cntrl != slot.cntrl_type: + slots_to_test.remove(slot) + return slots_to_test + + def verify_state(slot, current, expected, msg): if slot.cntrl_type == "SCSI" and expected == "rebuild": # No good way to validate this one as read value won't match what we sent down. @@ -43,9 +51,15 @@ def test_ibpi(ledctl_binary, slot_filters, controller_filters, cntrl): """ cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) - slots_with_device_node = get_slots_with_device_or_skip(cmd, cntrl) + slots_to_test = get_slots_with_device_or_skip(cmd, cntrl) + slots_to_test = filter_by_best_controller(cmd, slots_to_test) - for slot in slots_with_device_node: + if not slots_to_test: + pytest.skip( + "Devices detected but this is not primary controller for any drive, skipping" + ) + + for slot in slots_to_test: for state in LedctlCmd.base_states: cmd.set_ibpi(slot.device_node, state) cur = cmd.get_slot(slot) @@ -105,9 +119,8 @@ def test_set_slot_by_device(ledctl_binary, slot_filters, controller_filters, 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, + controller_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. @@ -118,15 +131,9 @@ def test_nvme_multipath_drives(ledctl_binary, slot_filters, controller_filters, 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 +144,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")