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

Closed
wants to merge 1 commit into from

Conversation

betaboon
Copy link
Contributor

@betaboon 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
Copy link
Member

@samueldr samueldr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially since we have -enable-kvm here!

@betaboon betaboon mentioned this pull request Nov 19, 2019
10 tasks
$machine->waitForUnit("nixos-manual");
machine.succeed("echo hello")
# machine.wait_for_unit("getty@tty2")
# machine.wait_for_unit("rogue")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this somehow redundant to:

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. might try that

Copy link
Contributor

@flokli flokli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's use assert where possible.

@betaboon
Copy link
Contributor Author

seems like this is now obsolete as #78670 has been merged.

closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants