Files
infix/test/case/hardware/usb_two_ports/test.py
T
Joachim Wiberg 1bbd80d8c7 test: drop leading ietf/infix prefix from directories
Let's drop the leading IETF or Infix prefixes from tests.  Initially the
idea was to mimnic the YANG models, but it's difficult to navigate and
does not provide any real benefit to developers or end-users.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-11-20 20:23:23 +01:00

80 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""
USB configuration with two USB ports
Test that the USB locked/unlocked 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("Set up topology and attach to target DUTs"):
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()