yager: handle usb info though the HOST api

Prior to this commit yanger looked at the running system using
os.path..., this meant that the static reply / capture data wasn't
used properly. This resulted in strange behavior during unit testing
on GitHub runners where USB ports are missing.

Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
Richard Alpe
2025-08-11 14:33:07 +02:00
parent 15a2221b23
commit b3fe0d58d8
2 changed files with 34 additions and 12 deletions
+10 -12
View File
@@ -61,18 +61,16 @@ def usb_port_components(systemjson):
path = usb_port["path"]
if os.path.basename(path) == "authorized_default":
# TODO: Untestable. Should be done via the host API
if os.path.exists(path):
with open(path, "r") as f:
names.append(usb_port["name"])
data = int(f.readline().strip())
enabled = "unlocked" if data == 1 else "locked"
port["state"] = {}
port["state"]["admin-state"] = enabled
port["name"] = usb_port["name"]
port["class"] = "infix-hardware:usb"
port["state"]["oper-state"] = "enabled"
ports.append(port)
if HOST.exists(path):
names.append(usb_port["name"])
data = int(HOST.read(path))
enabled = "unlocked" if data == 1 else "locked"
port["state"] = {}
port["state"]["admin-state"] = enabled
port["name"] = usb_port["name"]
port["class"] = "infix-hardware:usb"
port["state"]["oper-state"] = "enabled"
ports.append(port)
return ports