Skip to content

Commit

Permalink
tests: align tests and use --best-controller
Browse files Browse the repository at this point in the history
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 <kinga.stefaniuk@intel.com>
  • Loading branch information
ktanska committed Sep 2, 2024
1 parent eb88a85 commit 7361edb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 41 deletions.
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
]

Expand All @@ -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:
Expand Down
25 changes: 14 additions & 11 deletions tests/ledctl/ledctl_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,14 @@ 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]

# The purpose or slot filters is exclude unsupported but recognized slots, apply it
# 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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -148,15 +151,15 @@ 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
return rc.keys()

# 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)

Expand Down
3 changes: 2 additions & 1 deletion tests/ledctl/parameters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 19 additions & 24 deletions tests/ledctl/slot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,40 @@ 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(
cur, cur.state, state,
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:
Expand Down Expand Up @@ -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)
Expand All @@ -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")

0 comments on commit 7361edb

Please sign in to comment.