From 55431e134435cf163c4f627c4b584428c4a42a99 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Fri, 12 Dec 2025 16:21:59 +0100
Subject: [PATCH] minor changes of Bens patches

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 tuxrun/__main__.py                            | 41 +++++++++++++------
 tuxrun/argparse.py                            | 14 +------
 .../dispatchers/dispatcher.yaml.jinja2        |  2 +-
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/tuxrun/__main__.py b/tuxrun/__main__.py
index 5b221e32f1b9..b7a26f02cd48 100644
--- a/tuxrun/__main__.py
+++ b/tuxrun/__main__.py
@@ -37,6 +37,7 @@ from tuxrun.utils import (  # noqa: E402
 from tuxrun.writer import Writer  # noqa: E402
 from tuxrun.yaml import yaml_load  # noqa: E402
 
+from tuxlava.devices import Device  # type: ignore  # noqa: E402
 from tuxlava.jobs import Job  # type: ignore  # noqa: E402
 from tuxlava.exceptions import TuxLavaException  # type: ignore # noqa: E402
 
@@ -188,7 +189,6 @@ def run(options, tmpdir: Path, cache_dir: Optional[Path], artefacts: dict) -> in
         "fip": options.fip,
         "job_definition": options.job_definition,
         "kernel": options.kernel,
-        "laa": options.laa,
         "device_dict": options.device_dict,
         "mcp_fw": options.mcp_fw,
         "mcp_romfw": options.mcp_romfw,
@@ -252,7 +252,7 @@ def run(options, tmpdir: Path, cache_dir: Optional[Path], artefacts: dict) -> in
     if options.fvp_ubl_license:
         context["fvp_ubl_license"] = options.fvp_ubl_license
 
-    device_dict = job.device.device_dict(context, laa_config=job.laa_config)
+    device_dict = job.device.device_dict(context, d_dict_config=job.d_dict_config)
     LOG.debug("device dictionary")
     LOG.debug(device_dict)
 
@@ -261,17 +261,17 @@ def run(options, tmpdir: Path, cache_dir: Optional[Path], artefacts: dict) -> in
 
     # Render the dispatcher.yaml
     (tmpdir / "dispatcher").mkdir()
-    # For LAA mode, get dispatcher_ip from config or use default LAA network IP
+    # For device dict mode, get dispatcher_ip from --parameters or use default device dict network IP
     dispatcher_ip = None
-    if options.laa and job.laa_config:
-        dispatcher_ip = job.laa_config.get("dispatcher_ip", "198.18.0.1")
+    if options.device_dict:
+        dispatcher_ip = options.parameters.get("DISPATCHER_IP", "198.18.0.1")
     dispatcher = (
         templates.dispatchers()
         .get_template("dispatcher.yaml.jinja2")
         .render(
             dispatcher_download_dir=options.dispatcher_download_dir,
             prefix=tmpdir.name,
-            laa_mode=options.laa,
+            d_dict_mode=bool(options.device_dict),
             dispatcher_ip=dispatcher_ip,
         )
     )
@@ -312,12 +312,17 @@ def run(options, tmpdir: Path, cache_dir: Optional[Path], artefacts: dict) -> in
     if job.qemu_binary:
         overlay_qemu(job.qemu_binary, tmpdir, runtime)
 
-    # LAA: host network, skip HTTP server, bind laacli/lsibcli/dbus
-    if options.laa:
+    # Device dict mode: When --device-dict is provided. Requires
+    # host networking and access to device control binaries.
+    if options.device_dict:
         runtime.use_host_network()
         runtime.skip_http_server()
-        for path in ["/usr/bin/laacli", "/usr/bin/lsibcli"]:
-            if Path(path).exists():
+        # Bind device control binaries (configurable via --parameters DEVICE_CONTROL_BINARIES)
+        default_binaries = "/usr/bin/laacli,/usr/bin/lsibcli"
+        control_binaries = options.parameters.get("DEVICE_CONTROL_BINARIES", default_binaries).split(",")
+        for path in control_binaries:
+            path = path.strip()
+            if path and Path(path).exists():
                 runtime.bind(Path(path), Path(path), ro=True)
         if Path("/run/dbus/system_bus_socket").exists():
             runtime.bind(
@@ -343,10 +348,10 @@ def run(options, tmpdir: Path, cache_dir: Optional[Path], artefacts: dict) -> in
     signal.alarm(job_timeout)
 
     # Start the pre_run command
-    if job.device.flag_use_pre_run_cmd or job.qemu_image or options.laa:
+    if job.device.flag_use_pre_run_cmd or job.qemu_image or options.device_dict:
         LOG.debug("Pre run command")
-        if options.laa:
-            # LAA: bind host directory to /srv/tftp (LAVA TFTP) and dispatcher_download_dir (NFS)
+        if options.device_dict:
+            # Device dict: bind host directory to /srv/tftp (LAVA TFTP) and dispatcher_download_dir (NFS)
             runtime.bind(options.dispatcher_download_dir, Path("/srv/tftp"))
             runtime.bind(options.dispatcher_download_dir, options.dispatcher_download_dir)
         else:
@@ -431,6 +436,16 @@ def main() -> int:
         if not (options.tuxmake or options.tuxbuild):
             parser.error("argument --device is required")
 
+    # Validate device choice unless --device-dict is provided
+    if options.device and not options.device_dict:
+        device_choices = [d.name for d in Device.list(virtual_device=True)]
+        device_choices = sorted(set(device_choices))
+        if options.device not in device_choices:
+            parser.error(
+                f"argument --device: invalid choice: '{options.device}' "
+                f"(choose from {', '.join(device_choices)})"
+            )
+
     if "hacking-session" in options.tests:
         options.enable_network = True
         if not options.parameters.get("PUB_KEY"):
diff --git a/tuxrun/argparse.py b/tuxrun/argparse.py
index 094c13a00b8e..69d444b4a817 100644
--- a/tuxrun/argparse.py
+++ b/tuxrun/argparse.py
@@ -13,7 +13,7 @@ from tuxrun import __version__
 from tuxrun.assets import get_rootfs, get_test_definitions
 from tuxrun.utils import ProgressIndicator, pathurlnone, DEFAULT_DISPATCHER_DOWNLOAD_DIR
 
-from tuxlava.devices import Device, list_laa_supported_devices  # type: ignore
+from tuxlava.devices import Device  # type: ignore
 from tuxlava.tests import Test  # type: ignore
 
 
@@ -52,7 +52,6 @@ class ListDevicesAction(argparse.Action):
     def __call__(self, parser, namespace, values, option_string=None):
         # Virtual devices (qemu, fvp, avh) + LAA-supported devices (nfs-*, fastboot-*)
         devices = [d.name for d in Device.list(virtual_device=True)]
-        devices.extend(list_laa_supported_devices())
         devices = sorted(set(devices))
         parser._print_message("\n".join(devices) + "\n", sys.stdout)
         parser.exit()
@@ -329,22 +328,11 @@ def setup_parser() -> argparse.ArgumentParser:
     )
 
     group = parser.add_argument_group("run options")
-    # Virtual devices (qemu, fvp, avh) + LAA-supported devices (nfs-*, fastboot-*)
-    device_choices = [d.name for d in Device.list(virtual_device=True)]
-    device_choices.extend(list_laa_supported_devices())
-    device_choices = sorted(set(device_choices))
     group.add_argument(
         "--device",
         default=None,
         metavar="NAME",
         help="Device type",
-        choices=device_choices,
-    )
-    group.add_argument(
-        "--laa",
-        default=False,
-        action="store_true",
-        help="Run on LAA (LAVA Appliance) hardware with laacli power/serial control",
     )
     group.add_argument(
         "--device-dict",
diff --git a/tuxrun/templates/dispatchers/dispatcher.yaml.jinja2 b/tuxrun/templates/dispatchers/dispatcher.yaml.jinja2
index e34e69337706..0f635af40981 100644
--- a/tuxrun/templates/dispatchers/dispatcher.yaml.jinja2
+++ b/tuxrun/templates/dispatchers/dispatcher.yaml.jinja2
@@ -6,7 +6,7 @@ dispatcher_download_dir: "{{ dispatcher_download_dir }}"
 # <dispatcher_download_dir>/<job_id>
 prefix: "{{ prefix }}-"
 
-{% if laa_mode %}
+{% if d_dict_mode %}
 dispatcher_ip: {{ dispatcher_ip|default('198.18.0.1') }}
 {% endif %}
 
-- 
2.51.0

