mirror of
https://github.com/nix-community/disko.git
synced 2024-09-11 06:25:33 +03:00
update to new nixos test api
This commit is contained in:
parent
713aa3df48
commit
398acc470f
@ -220,21 +220,37 @@ let
|
|||||||
|
|
||||||
testScript = { nodes, ... }: ''
|
testScript = { nodes, ... }: ''
|
||||||
def disks(oldmachine, num_disks):
|
def disks(oldmachine, num_disks):
|
||||||
disk_flags = ""
|
disk_flags = []
|
||||||
for i in range(num_disks):
|
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 += [
|
||||||
disk_flags += f' -device virtio-blk-pci,drive=drive{i + 1}'
|
'-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
|
return disk_flags
|
||||||
def create_test_machine(oldmachine, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
|
|
||||||
startCommand = "${pkgs.qemu_test}/bin/qemu-kvm"
|
def create_test_machine(
|
||||||
startCommand += " -cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store"
|
oldmachine=None, **kwargs
|
||||||
startCommand += disks(oldmachine, ${toString num-disks})
|
): # taken from <nixpkgs/nixos/tests/installer.nix>
|
||||||
|
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 ''
|
${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({
|
machine = create_machine(start_command=" ".join(start_command), **kwargs)
|
||||||
"startCommand": startCommand,
|
|
||||||
} | args)
|
|
||||||
driver.machines.append(machine)
|
driver.machines.append(machine)
|
||||||
return machine
|
return machine
|
||||||
|
|
||||||
@ -283,7 +299,7 @@ let
|
|||||||
machine.succeed("sync")
|
machine.succeed("sync")
|
||||||
machine.shutdown()
|
machine.shutdown()
|
||||||
|
|
||||||
machine = create_test_machine(oldmachine=machine, args={ "name": "booted_machine" })
|
machine = create_test_machine(oldmachine=machine, name="booted_machine")
|
||||||
machine.start()
|
machine.start()
|
||||||
${bootCommands}
|
${bootCommands}
|
||||||
machine.wait_for_unit("local-fs.target")
|
machine.wait_for_unit("local-fs.target")
|
||||||
|
@ -20,14 +20,23 @@ pkgs.nixosTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
def create_test_machine(oldmachine, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
|
def create_test_machine(
|
||||||
startCommand = "${pkgs.qemu_test}/bin/qemu-kvm"
|
oldmachine=None, **kwargs
|
||||||
startCommand += " -cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store"
|
): # taken from <nixpkgs/nixos/tests/installer.nix>
|
||||||
startCommand += f' -drive file={oldmachine.state_dir}/empty0.qcow2,id=drive1,if=none,index=1,werror=report'
|
start_command = [
|
||||||
startCommand += ' -device virtio-blk-pci,drive=drive1'
|
"${pkgs.qemu_test}/bin/qemu-kvm",
|
||||||
machine = create_machine({
|
"-cpu",
|
||||||
"startCommand": startCommand,
|
"max",
|
||||||
} | args)
|
"-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)
|
driver.machines.append(machine)
|
||||||
return machine
|
return machine
|
||||||
machine.succeed("lsblk >&2")
|
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.succeed("${disko}/bin/disko-install --mode mount --disk main /dev/vdb --flake ${../..}#testmachine")
|
||||||
machine.shutdown()
|
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()
|
new_machine.start()
|
||||||
name = new_machine.succeed("hostname").strip()
|
name = new_machine.succeed("hostname").strip()
|
||||||
assert name == "disko-machine", f"expected hostname 'disko-machine', got {name}"
|
assert name == "disko-machine", f"expected hostname 'disko-machine', got {name}"
|
||||||
|
Loading…
Reference in New Issue
Block a user