From 91d6a7be85adc6af3d4570084ff44d4294f295ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Tue, 3 Sep 2024 12:58:09 +0200 Subject: [PATCH] test: USB: Add new test to test systems with two USB ports Break out this from the general USB test. Test if you can modify the ports independent of eachother. --- test/case/ietf_hardware/ietf_hardware.yaml | 3 + test/case/ietf_hardware/usb/test.py | 21 ----- test/case/ietf_hardware/usb_two_ports/test.py | 78 +++++++++++++++++++ .../ietf_hardware/usb_two_ports/topology.dot | 23 ++++++ 4 files changed, 104 insertions(+), 21 deletions(-) create mode 100755 test/case/ietf_hardware/usb_two_ports/test.py create mode 100644 test/case/ietf_hardware/usb_two_ports/topology.dot diff --git a/test/case/ietf_hardware/ietf_hardware.yaml b/test/case/ietf_hardware/ietf_hardware.yaml index e30dd9f0..5acbf280 100644 --- a/test/case/ietf_hardware/ietf_hardware.yaml +++ b/test/case/ietf_hardware/ietf_hardware.yaml @@ -1,3 +1,6 @@ --- - name: usb case: usb/test.py + +- name: usb two ports + case: usb_two_ports/test.py diff --git a/test/case/ietf_hardware/usb/test.py b/test/case/ietf_hardware/usb/test.py index f260e4a6..b61d7846 100755 --- a/test/case/ietf_hardware/usb/test.py +++ b/test/case/ietf_hardware/usb/test.py @@ -38,27 +38,6 @@ with infamy.Test() as test: for port in available: until(lambda: usb.get_usb_state(target, port) == "unlocked") - if len(available) > 1: - with test.step("Lock one port"): - components = [] - component = { - "name": available[1], - "class": "infix-hardware:usb", - "state": { - "admin-state": "locked" - } - } - components.append(component) - - target.put_config_dict("ietf-hardware", { - "hardware": { - "component": components - } - }) - with test.step("Verify one port is locked and one unlocked"): - until(lambda: usb.get_usb_state(target, available[1]) == "locked") - until(lambda: usb.get_usb_state(target, available[0]) == "unlocked") - with test.step("Lock USB ports"): components = [] for port in available: diff --git a/test/case/ietf_hardware/usb_two_ports/test.py b/test/case/ietf_hardware/usb_two_ports/test.py new file mode 100755 index 00000000..3adcfa44 --- /dev/null +++ b/test/case/ietf_hardware/usb_two_ports/test.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +""" +@name USB configuration with USB ports +@description Test that the configuration is consistent +when having two USB ports. +""" +import infamy +import copy +import infamy.usb as usb +import time +import infamy.netconf as netconf +from infamy.util import until,wait_boot + +with infamy.Test() as test: + with test.step("Initialize"): + env = infamy.Env() + target = env.attach("target", "mgmt") + available=usb.get_usb_ports(target) + + if len(available) < 2: + test.skip() + + with test.step("Lock the first USB port, and unlock the second USB port"): + components = [] + component = { + "name": available[0], + "class": "infix-hardware:usb", + "state": { + "admin-state": "locked" + } + } + components.append(component) + component = { + "name": available[1], + "class": "infix-hardware:usb", + "state": { + "admin-state": "unlocked" + } + } + components.append(component) + + target.put_config_dict("ietf-hardware", { + "hardware": { + "component": components + } + }) + with test.step("Verify that the correct port is locked and the correct one is unlocked"): + until(lambda: usb.get_usb_state(target, available[0]) == "locked") + until(lambda: usb.get_usb_state(target, available[1]) == "unlocked") + + with test.step("Unlock the first USB port, and lock the second USB port"): + components = [] + component = { + "name": available[0], + "class": "infix-hardware:usb", + "state": { + "admin-state": "unlocked" + } + } + components.append(component) + component = { + "name": available[1], + "class": "infix-hardware:usb", + "state": { + "admin-state": "locked" + } + } + components.append(component) + + target.put_config_dict("ietf-hardware", { + "hardware": { + "component": components + } + }) + with test.step("Verify that the correct port is locked and the correct one is unlocked"): + until(lambda: usb.get_usb_state(target, available[0]) == "unlocked") + until(lambda: usb.get_usb_state(target, available[1]) == "locked") + test.succeed() diff --git a/test/case/ietf_hardware/usb_two_ports/topology.dot b/test/case/ietf_hardware/usb_two_ports/topology.dot new file mode 100644 index 00000000..dc72e816 --- /dev/null +++ b/test/case/ietf_hardware/usb_two_ports/topology.dot @@ -0,0 +1,23 @@ +graph "1x1" { + layout="neato"; + overlap="false"; + esep="+20"; + + node [shape=record, fontname="monospace"]; + edge [color="cornflowerblue", penwidth="2"]; + + host [ + label="host | { tgt }", + pos="0,12!", + kind="controller", + ]; + + target [ + label="{ mgmt } | target", + pos="10,12!", + + kind="infix", + ]; + + host:tgt -- target:mgmt [kind=mgmt] +}