From 260d9cc7e10e477a60d11e9b44d80fd76a4492ae Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 12 Aug 2021 22:50:29 +0200 Subject: [PATCH 1/3] nixos/testing: re-add nixos-run-vms script Originally removed in 926fb9396881202e727e5ec1fbf609b64455b388. This one is actually quite useful for `nixos-build-vms(8)`. --- nixos/lib/testing-python.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 6369d6ef05d4..070a3a7ddc21 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -186,6 +186,12 @@ rec { --set startScripts "''${vmStartScripts[*]}" \ --set testScript "$out/test-script" \ --set vlans '${toString vlans}' + + ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms + wrapProgram $out/bin/nixos-run-vms \ + --set startScripts "''${vmStartScripts[*]}" \ + --set testScript "${pkgs.writeText "start-all" "start_all(); join_all();"}" \ + --set vlans '${toString vlans}' ''); # Make a full-blown test From e1ec5acd3137d3af247f9a938d9cc086d8111377 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 12 Aug 2021 23:01:03 +0200 Subject: [PATCH 2/3] nixos/test-driver: start interactive mode if `testScript` is empty This is relevant for `nixos-build-vms(8)` which doesn't have a test-script. In that case it's more intuitive to directly go into the interactive mode which is IMHO more intuitive. --- nixos/lib/test-driver/test-driver.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index 1720e553d733..0372148cb33c 100755 --- a/nixos/lib/test-driver/test-driver.py +++ b/nixos/lib/test-driver/test-driver.py @@ -1029,10 +1029,11 @@ if __name__ == "__main__": args = arg_parser.parse_args() global test_script + testscript = pathlib.Path(args.testscript).read_text() def test_script() -> None: with log.nested("running the VM test script"): - exec(pathlib.Path(args.testscript).read_text(), globals()) + exec(testscript, globals()) log = Logger() @@ -1061,7 +1062,8 @@ if __name__ == "__main__": process.terminate() log.close() + interactive = args.interactive or (not bool(testscript)) tic = time.time() - run_tests(args.interactive) + run_tests(interactive) toc = time.time() print("test script finished in {:.2f}s".format(toc - tic)) From 1ba3f7927f9a8a982994ff6bdf1adc3949812128 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 13 Aug 2021 17:35:30 +0200 Subject: [PATCH 3/3] nixos/testing: only create `nixos-run-vms` for `nixos-build-vms(8)` This is the case when the test-script is empty. `nixos-build-vms(8)` is primarily supposed to be used as tool to test changes or to reproduce bugs (IMHO) where "just spinning up a few VMs" is the primary use-case. In the ongoing discussion about these changes[1] it was suggested to only expose it when needed (i.e. in the case I described above) to keep the API surface as slim as possible. [1] https://github.com/NixOS/nixpkgs/pull/133675#discussion_r688112485 --- nixos/lib/testing-python.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 070a3a7ddc21..e95ebe16ecac 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -187,11 +187,13 @@ rec { --set testScript "$out/test-script" \ --set vlans '${toString vlans}' - ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms - wrapProgram $out/bin/nixos-run-vms \ - --set startScripts "''${vmStartScripts[*]}" \ - --set testScript "${pkgs.writeText "start-all" "start_all(); join_all();"}" \ - --set vlans '${toString vlans}' + ${lib.optionalString (testScript == "") '' + ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms + wrapProgram $out/bin/nixos-run-vms \ + --set startScripts "''${vmStartScripts[*]}" \ + --set testScript "${pkgs.writeText "start-all" "start_all(); join_all();"}" \ + --set vlans '${toString vlans}' + ''} ''); # Make a full-blown test