Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/tests/installer: port to python #73237

Open
wants to merge 1 commit into
base: master
from

Conversation

@betaboon
Copy link
Contributor

betaboon commented Nov 11, 2019

Motivation for this change

#72828

Prepare for changes mentioned in #58121 (comment)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

nixos/lib/test-driver/test-driver.py Outdated Show resolved Hide resolved
nixos/tests/installer.nix Outdated Show resolved Hide resolved
@betaboon betaboon force-pushed the betaboon:tests-installer-python-port branch from b0f33f8 to 8a48bc5 Nov 11, 2019
Copy link
Member

samueldr left a comment

One change, two bits brought forward that were already questionable.

nixos/tests/installer.nix Outdated Show resolved Hide resolved
(optionalString (system == "aarch64-linux") "-enable-kvm -machine virt,gic-version=host -cpu host ");
makeMachineConfig = name: pythonDict ({
inherit name;
# FIXME don't duplicate the -enable-kvm etc. flags here yet again!

This comment has been minimized.

Copy link
@samueldr

samueldr Nov 11, 2019

Member

Do you know what that comment was all about? Couldn't figure it out yesterday, though I did not dive into git blame and the history.

This comment has been minimized.

Copy link
@betaboon

betaboon Nov 11, 2019

Author Contributor

no i don't know for sure.
git blame just yields this: e58624a which doesn't clear it up any further.

i am assuming this refers to qemu-flags being defined here as well:
https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/qemu-flags.nix

This comment has been minimized.

Copy link
@samueldr

samueldr Nov 11, 2019

Member

(btw, the change can go through without this being resolved, just wanted to point it out as it's being ported as-is.)

This comment has been minimized.

Copy link
@betaboon

betaboon Nov 19, 2019

Author Contributor

i double checked. the options set here, are exactly the ones in qemu-flags.nix except the ram (-m) option.

The bigger picture situation is as follows:

  • the vm used initially is set up using qemu-vm.nix which respects the options from qemu-flags.nix and thus does not use the flags defined in installer.nix
  • only the machines created with create_machine in installer.nix do not use the flags defined in qemu-flags.nix as they use a completly different codepath, namely create_startcommand from test-driver.py which uses qemu-kvm only

This comment has been minimized.

Copy link
@betaboon

betaboon Nov 21, 2019

Author Contributor

@samueldr what do we wanna do about this?

qemuFlags =
(if system == "x86_64-linux" then "-m 768 " else "-m 512 ") +
(optionalString (system == "x86_64-linux") "-cpu kvm64 ") +
(optionalString (system == "aarch64-linux") "-enable-kvm -machine virt,gic-version=host -cpu host ");

This comment has been minimized.

Copy link
@samueldr

samueldr Nov 11, 2019

Member

Especially since we have -enable-kvm here!

@betaboon betaboon force-pushed the betaboon:tests-installer-python-port branch from 8a48bc5 to 496db01 Nov 11, 2019
@betaboon betaboon force-pushed the betaboon:tests-installer-python-port branch from 496db01 to d07ba9b Nov 18, 2019
@betaboon betaboon mentioned this pull request Nov 19, 2019
3 of 10 tasks complete
$machine->waitForUnit("nixos-manual");
machine.succeed("echo hello")
# machine.wait_for_unit("getty@tty2")
# machine.wait_for_unit("rogue")

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

it looks like "echo hello" is a leftover from earlier experiments. is this and the commented out lines going to vanish before this is merged?

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

I agree.

"${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; } }",
"/mnt/etc/nixos/configuration.nix");
"/mnt/etc/nixos/configuration.nix",

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

wouldn't this path be visible in the VM anyway as it's from the nix store path? wouldn't then machine.succeed("cp ${makeConfig ...} /mnt/etc/nixos/configuration.nix") work or is this suggestion stupid becasue i am missing out anything really fundamental?

This comment has been minimized.

Copy link
@betaboon

betaboon Dec 1, 2019

Author Contributor

i dont think it is available in the VMs nix-store.

$machine->succeed("sync");
machine.succeed("umount /mnt/boot || true")
machine.succeed("umount /mnt")
machine.succeed("sync")

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

all these groups of steps would be perfect candidates for descriptive with subtest(....): sections.

This comment has been minimized.

Copy link
@betaboon

betaboon Dec 1, 2019

Author Contributor

yeah i thought so to. just wanted to do a straight port first without refactoring at the same time.

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

We can do a followup PR, this shouldn't be a reason to block this PR.

}
# Check whether /root has correct permissions.
$machine->succeed("stat -c '%a' /root") =~ /700/ or die;
machine.succeed("stat -c '%a' /root | grep 700")

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

why not assert "700" in machine.succeed(...)

This comment has been minimized.

Copy link
@betaboon

betaboon Dec 1, 2019

Author Contributor

might be possible. It's just done this way everywhere else. If it would be preferable to use assert i am fine with it.

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

Yeah, let's use assert where possible.

$machine->waitForUnit("swap.target");
$machine->succeed("cat /proc/swaps | grep -q /dev");
machine.wait_for_unit("swap.target")
machine.succeed("cat /proc/swaps | grep -q /dev")

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

many grep commands could be substituted by python asserts

$machine->succeed("nixos-option boot.initrd.kernelModules | grep qemu-guest.nix");
machine.succeed("nixos-option boot.initrd.kernelModules | grep virtio_console")
machine.succeed("nixos-option boot.initrd.kernelModules | grep 'List of modules'")
machine.succeed("nixos-option boot.initrd.kernelModules | grep qemu-guest.nix")

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

why not:

modules = machine.succeed("nixos-option boot.initrd.kernelModules")
for line in "virtio_console", "List of modules", "qemu-guest.nix":
   assert line in modules

This comment has been minimized.

Copy link
@betaboon

betaboon Dec 1, 2019

Author Contributor

true. looks better.

machine.wait_for_unit("multi-user.target")
# Booted configuration name should be Work
machine.succeed("cat /run/booted-system/configuration-name >&2")
machine.succeed("cat /run/booted-system/configuration-name | grep Work")

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

isn't this somehow redundant to:

assert "Work" in machine.succeed("cat /run/booted-system/configuration-name >&2")

This comment has been minimized.

Copy link
@betaboon

betaboon Dec 1, 2019

Author Contributor

possibly

"flock /dev/vda parted --script /dev/vda -- mklabel msdos"
" mkpart primary ext2 1M 50MB" # /boot
" mkpart primary linux-swap 50M 1024M"
" mkpart primary 1024M -1s", # LUKS

This comment has been minimized.

Copy link
@tfc

tfc Dec 1, 2019

Contributor

it's not necessary, but might be helpful while reading to prefix those multiline-lines with +

This comment has been minimized.

Copy link
@betaboon

betaboon Dec 1, 2019

Author Contributor

good point. might try that

Copy link
Contributor

flokli left a comment

Some comments, but already looking quite nice so far! 👍

@@ -710,6 +711,13 @@ def unblock(self):
"""
self.send_monitor_command("set_link virtio-net-pci.1 on")

def copy_file_from_host(self, from_path, to_path):

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

This probably needs type annotations and a rebase, as the test driver got annotations too.

$machine->waitForUnit("nixos-manual");
machine.succeed("echo hello")
# machine.wait_for_unit("getty@tty2")
# machine.wait_for_unit("rogue")

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

I agree.

$machine->succeed("sync");
machine.succeed("umount /mnt/boot || true")
machine.succeed("umount /mnt")
machine.succeed("sync")

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

We can do a followup PR, this shouldn't be a reason to block this PR.

}
# Check whether /root has correct permissions.
$machine->succeed("stat -c '%a' /root") =~ /700/ or die;
machine.succeed("stat -c '%a' /root | grep 700")

This comment has been minimized.

Copy link
@flokli

flokli Dec 3, 2019

Contributor

Yeah, let's use assert where possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.