-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update testsuite to new nixos test api
- Loading branch information
Showing
2 changed files
with
118 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,56 @@ | ||
(import ./lib/test-base.nix) { | ||
name = "from-nixos-build-on-remote"; | ||
nodes = { | ||
installer = ./modules/installer.nix; | ||
installed = { | ||
services.openssh.enable = true; | ||
virtualisation.memorySize = 1512; | ||
(import ./lib/test-base.nix) ( | ||
{ pkgs, ... }: | ||
{ | ||
name = "from-nixos-build-on-remote"; | ||
nodes = { | ||
installer = ./modules/installer.nix; | ||
installed = { | ||
services.openssh.enable = true; | ||
virtualisation.memorySize = 1512; | ||
|
||
users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ]; | ||
users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ]; | ||
}; | ||
}; | ||
}; | ||
testScript = '' | ||
def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix> | ||
machine = create_machine({ | ||
"qemuFlags": | ||
'-cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store,' | ||
f' -drive file={oldmachine.state_dir}/installed.qcow2,id=drive1,if=none,index=1,werror=report' | ||
f' -device virtio-blk-pci,drive=drive1', | ||
} | args) | ||
driver.machines.append(machine) | ||
return machine | ||
start_all() | ||
testScript = '' | ||
def create_test_machine( | ||
oldmachine=None, **kwargs | ||
): # 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", | ||
"-drive", | ||
f"file={oldmachine.state_dir}/installed.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 | ||
start_all() | ||
installer.succeed(""" | ||
nixos-anywhere \ | ||
-i /root/.ssh/install_key \ | ||
--debug \ | ||
--build-on-remote \ | ||
--kexec /etc/nixos-anywhere/kexec-installer \ | ||
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \ | ||
root@installed >&2 | ||
""") | ||
try: | ||
installed.shutdown() | ||
except BrokenPipeError: | ||
# qemu has already exited | ||
pass | ||
new_machine = create_test_machine(oldmachine=installed, args={ "name": "after_install" }) | ||
new_machine.start() | ||
hostname = new_machine.succeed("hostname").strip() | ||
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'" | ||
''; | ||
} | ||
installer.succeed(""" | ||
nixos-anywhere \ | ||
-i /root/.ssh/install_key \ | ||
--debug \ | ||
--build-on-remote \ | ||
--kexec /etc/nixos-anywhere/kexec-installer \ | ||
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \ | ||
root@installed >&2 | ||
""") | ||
try: | ||
installed.shutdown() | ||
except BrokenPipeError: | ||
# qemu has already exited | ||
pass | ||
new_machine = create_test_machine(oldmachine=installed, name="after_install") | ||
new_machine.start() | ||
hostname = new_machine.succeed("hostname").strip() | ||
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'" | ||
''; | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,67 @@ | ||
(import ./lib/test-base.nix) { | ||
name = "from-nixos"; | ||
nodes = { | ||
installer = ./modules/installer.nix; | ||
installed = { | ||
services.openssh.enable = true; | ||
virtualisation.memorySize = 1512; | ||
(import ./lib/test-base.nix) ( | ||
{ pkgs, ... }: | ||
{ | ||
name = "from-nixos"; | ||
nodes = { | ||
installer = ./modules/installer.nix; | ||
installed = { | ||
services.openssh.enable = true; | ||
virtualisation.memorySize = 1512; | ||
|
||
users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ]; | ||
users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ]; | ||
}; | ||
}; | ||
}; | ||
testScript = '' | ||
def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix> | ||
machine = create_machine({ | ||
"qemuFlags": | ||
'-cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store,' | ||
f' -drive file={oldmachine.state_dir}/installed.qcow2,id=drive1,if=none,index=1,werror=report' | ||
f' -device virtio-blk-pci,drive=drive1', | ||
} | args) | ||
driver.machines.append(machine) | ||
return machine | ||
start_all() | ||
installer.succeed("mkdir -p /tmp/extra-files/var/lib/secrets") | ||
installer.succeed("echo value > /tmp/extra-files/var/lib/secrets/key") | ||
ssh_key_path = "/etc/ssh/ssh_host_ed25519_key.pub" | ||
ssh_key_output = installer.wait_until_succeeds(f""" | ||
ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ | ||
root@installed cat {ssh_key_path} | ||
""") | ||
installer.succeed(""" | ||
nixos-anywhere \ | ||
-i /root/.ssh/install_key \ | ||
--debug \ | ||
--kexec /etc/nixos-anywhere/kexec-installer \ | ||
--extra-files /tmp/extra-files \ | ||
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \ | ||
--copy-host-keys \ | ||
root@installed >&2 | ||
""") | ||
try: | ||
installed.shutdown() | ||
except BrokenPipeError: | ||
# qemu has already exited | ||
pass | ||
new_machine = create_test_machine(oldmachine=installed, args={ "name": "after_install" }) | ||
new_machine.start() | ||
hostname = new_machine.succeed("hostname").strip() | ||
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'" | ||
content = new_machine.succeed("cat /var/lib/secrets/key").strip() | ||
assert "value" == content, f"secret does not have expected value: {content}" | ||
ssh_key_content = new_machine.succeed(f"cat {ssh_key_path}").strip() | ||
assert ssh_key_content in ssh_key_output, "SSH host identity changed" | ||
''; | ||
} | ||
testScript = '' | ||
def create_test_machine( | ||
oldmachine=None, **kwargs | ||
): # 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", | ||
"-drive", | ||
f"file={oldmachine.state_dir}/installed.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 | ||
start_all() | ||
installer.succeed("mkdir -p /tmp/extra-files/var/lib/secrets") | ||
installer.succeed("echo value > /tmp/extra-files/var/lib/secrets/key") | ||
ssh_key_path = "/etc/ssh/ssh_host_ed25519_key.pub" | ||
ssh_key_output = installer.wait_until_succeeds(f""" | ||
ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ | ||
root@installed cat {ssh_key_path} | ||
""") | ||
installer.succeed(""" | ||
nixos-anywhere \ | ||
-i /root/.ssh/install_key \ | ||
--debug \ | ||
--kexec /etc/nixos-anywhere/kexec-installer \ | ||
--extra-files /tmp/extra-files \ | ||
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \ | ||
--copy-host-keys \ | ||
root@installed >&2 | ||
""") | ||
try: | ||
installed.shutdown() | ||
except BrokenPipeError: | ||
# qemu has already exited | ||
pass | ||
new_machine = create_test_machine(oldmachine=installed, name="after_install") | ||
new_machine.start() | ||
hostname = new_machine.succeed("hostname").strip() | ||
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'" | ||
content = new_machine.succeed("cat /var/lib/secrets/key").strip() | ||
assert "value" == content, f"secret does not have expected value: {content}" | ||
ssh_key_content = new_machine.succeed(f"cat {ssh_key_path}").strip() | ||
assert ssh_key_content in ssh_key_output, "SSH host identity changed" | ||
''; | ||
} | ||
) |