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

Add an installer test #7043

Merged
merged 15 commits into from
Sep 26, 2022
Merged

Add an installer test #7043

merged 15 commits into from
Sep 26, 2022

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Sep 14, 2022

This is loosely based on the Nix installer matrix (https://github.com/grahamc/nix-install-matrix), but it runs inside a Nix build using QEMU rather than outside of it using Vagrant. It also doesn't rely on import-from-derivation, unlike the old installer test that ran inside a declaratively built RedHat/Debian image.

Usage:

# nix build .#hydraJobs.installerTests.ubuntu-14-04.install-default

Hydra jobset for testing: https://hydra.nixos.org/jobset/nix/installer-test

This runs the installer in a QEMU VM. Unlike the old installer test
that ran inside a declaratively built RedHat/Debian image, this uses
an image from Vagrant.
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-installer-workgroup/21495/13

@edolstra edolstra marked this pull request as ready for review September 15, 2022 12:53

"ubuntu-16-04" = {
image = import <nix/fetchurl.nix> {
url = https://app.vagrantup.com/generic/boxes/ubuntu1604/versions/4.1.12/providers/libvirt.box;
Copy link
Member

@cole-h cole-h Sep 21, 2022

Choose a reason for hiding this comment

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

Should all these plain URLs be quoted (especially due to RFC45: NixOS/rfcs#45)? Or does <nix/fetchurl.nix> require unquoted URLs?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't able to get it working with a plain string:

❯  nix build .#hydraJobs.installerTests.rhel-8.x86_64-linux.install-force-daemon --rebuild -L
warning: Git tree '/home/ana/git/nixos/nix' is dirty
error: some outputs of '/nix/store/m54sb60nb2nnrmfmfp5ai2dakc54ry5c-installer-test-rhel-8-install-force-daemon.drv' are not valid, so checking is not possible

Copy link
Member

Choose a reason for hiding this comment

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

If you try without --rebuild, it should succeed.

Comment on lines +135 to +179
echo "Unpacking Vagrant box $image..."
tar xvf $image

image_type=$(qemu-img info ${image.rootDisk} | sed 's/file format: \(.*\)/\1/; t; d')

qemu-img create -b ./${image.rootDisk} -F "$image_type" -f qcow2 ./disk.qcow2

extra_qemu_opts="${image.extraQemuOpts or ""}"

# Add the config disk, required by the Ubuntu images.
config_drive=$(echo *configdrive.vmdk || true)
if [[ -n $config_drive ]]; then
extra_qemu_opts+=" -drive id=disk2,file=$config_drive,if=virtio"
fi

echo "Starting qemu..."
qemu-kvm -m 4096 -nographic \
-drive id=disk1,file=./disk.qcow2,if=virtio \
-netdev user,id=net0,restrict=yes,hostfwd=tcp::20022-:22 -device virtio-net-pci,netdev=net0 \
$extra_qemu_opts &
qemu_pid=$!
trap "kill $qemu_pid" EXIT

if ! [ -e ./vagrant_insecure_key ]; then
cp ${./vagrant_insecure_key} vagrant_insecure_key
fi

chmod 0400 ./vagrant_insecure_key

ssh_opts="-o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -i ./vagrant_insecure_key"
ssh="ssh -p 20022 -q $ssh_opts vagrant@localhost"

echo "Waiting for SSH..."
for ((i = 0; i < 120; i++)); do
echo "[ssh] Trying to connect..."
if $ssh -- true; then
echo "[ssh] Connected!"
break
fi
if ! kill -0 $qemu_pid; then
echo "qemu died unexpectedly"
exit 1
fi
sleep 1
done
Copy link
Member

Choose a reason for hiding this comment

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

Any chance we could directly call vagrant instead of reimplementing the logic ourselves?
It seems like vagrant box add --name testVM ${image.rootDisk} && vagrant init testVM should allow running vagrant against a local image

Copy link
Contributor

Choose a reason for hiding this comment

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

How do you continue from there? I tried vagrant up, but it requires libvirt. I tried to run libvirtd inside a derivation and got into trouble[1]. There's https://github.com/billyan2018/vagrant-qemu which looks interesting though.

[1] After fixing the unix socket path in the Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "testVM"
  config.vm.provider :libvirt do |libvirt|
    libvirt.uri = "qemu+unix:///session?socket=/run/user/$UID/libvirt/libvirt-sock"
  end
end

libvirt failed with some permission / path errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pulling in vagrant and libvirt adds a lot of complexity compared to calling qemu directly that I'd rather avoid...

tests/installer/default.nix Outdated Show resolved Hide resolved

in

builtins.mapAttrs (imageName: image:
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be quite convenient to have an all task that ran them for a specific architecture...

@edolstra edolstra merged commit dfc3a9a into NixOS:master Sep 26, 2022
Minion3665 pushed a commit to Minion3665/nix that referenced this pull request Feb 23, 2023
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.

7 participants