about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorK900 <me@0upti.me>2024-02-27 23:14:15 +0300
committerK900 <me@0upti.me>2024-02-28 09:32:11 +0300
commitbdacdc46e4b38531cb9dd2486c1bf2821c57e72a (patch)
tree27b82b9d4a37dc68f118fb3b51e74076637422d2 /nixos
parent423098c284063106bf15f669a7d5b0665d35be54 (diff)
nixos/lib/test-driver: provide legacy path for create_machine({"startCommand": "..."})
Diffstat (limited to 'nixos')
-rw-r--r--nixos/lib/test-driver/test_driver/driver.py38
-rw-r--r--nixos/lib/test-script-prepend.py2
2 files changed, 38 insertions, 2 deletions
diff --git a/nixos/lib/test-driver/test_driver/driver.py b/nixos/lib/test-driver/test_driver/driver.py
index daabd28d20ee0..72a33e0b2d578 100644
--- a/nixos/lib/test-driver/test_driver/driver.py
+++ b/nixos/lib/test-driver/test_driver/driver.py
@@ -12,6 +12,8 @@ from test_driver.machine import Machine, NixStartScript, retry
 from test_driver.polling_condition import PollingCondition
 from test_driver.vlan import VLan
 
+SENTINEL = object()
+
 
 def get_tmp_dir() -> Path:
     """Returns a temporary directory that is defined by TMPDIR, TEMP, TMP or CWD
@@ -189,11 +191,45 @@ class Driver:
 
     def create_machine(
         self,
-        start_command: str,
+        start_command: str | dict,
         *,
         name: Optional[str] = None,
         keep_vm_state: bool = False,
     ) -> Machine:
+        # Legacy args handling
+        # FIXME: remove after 24.05
+        if isinstance(start_command, dict):
+            if name is not None or keep_vm_state:
+                raise TypeError(
+                    "Dictionary passed to create_machine must be the only argument"
+                )
+
+            args = start_command
+            start_command = args.pop("startCommand", SENTINEL)
+
+            if start_command is SENTINEL:
+                raise TypeError(
+                    "Dictionary passed to create_machine must contain startCommand"
+                )
+
+            if not isinstance(start_command, str):
+                raise TypeError(
+                    f"startCommand must be a string, got: {repr(start_command)}"
+                )
+
+            name = args.pop("name", None)
+            keep_vm_state = args.pop("keep_vm_state", False)
+
+            if args:
+                raise TypeError(
+                    f"Unsupported arguments passed to create_machine: {args}"
+                )
+
+            rootlog.warning(
+                "Using create_machine with a single dictionary argument is deprecated, and will be removed in NixOS 24.11"
+            )
+        # End legacy args handling
+
         tmp_dir = get_tmp_dir()
 
         cmd = NixStartScript(start_command)
diff --git a/nixos/lib/test-script-prepend.py b/nixos/lib/test-script-prepend.py
index 77e913ff04587..976992ea00158 100644
--- a/nixos/lib/test-script-prepend.py
+++ b/nixos/lib/test-script-prepend.py
@@ -29,7 +29,7 @@ class PollingConditionProtocol(Protocol):
 class CreateMachineProtocol(Protocol):
     def __call__(
         self,
-        start_command: str,
+        start_command: str | dict,
         *,
         name: Optional[str] = None,
         keep_vm_state: bool = False,