From 398acc470f7c2d68621db01900f053e6000129c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 7 Jun 2024 15:42:51 +0200 Subject: [PATCH] update to new nixos test api --- lib/tests.nix | 40 +++++++++++++++++++++++---------- tests/disko-install/default.nix | 27 ++++++++++++++-------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index 77c07ba..e2e8f60 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -220,21 +220,37 @@ let testScript = { nodes, ... }: '' def disks(oldmachine, num_disks): - disk_flags = "" + disk_flags = [] for i in range(num_disks): - disk_flags += f' -drive file={oldmachine.state_dir}/empty{i}.qcow2,id=drive{i + 1},if=none,index={i + 1},werror=report' - disk_flags += f' -device virtio-blk-pci,drive=drive{i + 1}' + disk_flags += [ + '-drive', + f"file={oldmachine.state_dir}/empty{i}.qcow2,id=drive{i + 1},if=none,index={i + 1},werror=report", + '-device', + f"virtio-blk-pci,drive=drive{i + 1}" + ] return disk_flags - def create_test_machine(oldmachine, args={}): # taken from - startCommand = "${pkgs.qemu_test}/bin/qemu-kvm" - startCommand += " -cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store" - startCommand += disks(oldmachine, ${toString num-disks}) + + def create_test_machine( + oldmachine=None, **kwargs + ): # taken from + start_command = [ + "${pkgs.qemu_test}/bin/qemu-kvm", + "-cpu", + "max", + "-m", + "1024", + "-virtfs", + "local,path=/nix/store,security_model=none,mount_tag=nix-store", + *disks(oldmachine, ${toString num-disks}) + ] ${lib.optionalString efi '' - startCommand +=" -drive if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware} -drive if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}" + start_command += ["-drive", + "if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}", + "-drive", + "if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}" + ] ''} - machine = create_machine({ - "startCommand": startCommand, - } | args) + machine = create_machine(start_command=" ".join(start_command), **kwargs) driver.machines.append(machine) return machine @@ -283,7 +299,7 @@ let machine.succeed("sync") machine.shutdown() - machine = create_test_machine(oldmachine=machine, args={ "name": "booted_machine" }) + machine = create_test_machine(oldmachine=machine, name="booted_machine") machine.start() ${bootCommands} machine.wait_for_unit("local-fs.target") diff --git a/tests/disko-install/default.nix b/tests/disko-install/default.nix index eabb7b7..48e1357 100644 --- a/tests/disko-install/default.nix +++ b/tests/disko-install/default.nix @@ -20,14 +20,23 @@ pkgs.nixosTest { }; testScript = '' - def create_test_machine(oldmachine, args={}): # taken from - startCommand = "${pkgs.qemu_test}/bin/qemu-kvm" - startCommand += " -cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store" - startCommand += f' -drive file={oldmachine.state_dir}/empty0.qcow2,id=drive1,if=none,index=1,werror=report' - startCommand += ' -device virtio-blk-pci,drive=drive1' - machine = create_machine({ - "startCommand": startCommand, - } | args) + def create_test_machine( + oldmachine=None, **kwargs + ): # taken from + start_command = [ + "${pkgs.qemu_test}/bin/qemu-kvm", + "-cpu", + "max", + "-m", + "1024", + "-virtfs", + "local,path=/nix/store,security_model=none,mount_tag=nix-store", + "-drive", + f"file={oldmachine.state_dir}/empty0.qcow2,id=drive1,if=none,index=1,werror=report", + "-device", + "virtio-blk-pci,drive=drive1", + ] + machine = create_machine(start_command=" ".join(start_command), **kwargs) driver.machines.append(machine) return machine machine.succeed("lsblk >&2") @@ -42,7 +51,7 @@ pkgs.nixosTest { machine.succeed("${disko}/bin/disko-install --mode mount --disk main /dev/vdb --flake ${../..}#testmachine") machine.shutdown() - new_machine = create_test_machine(oldmachine=machine, args={ "name": "after_install" }) + new_machine = create_test_machine(oldmachine=machine, name="after_install") new_machine.start() name = new_machine.succeed("hostname").strip() assert name == "disko-machine", f"expected hostname 'disko-machine', got {name}"