-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add an installer test #7043
Conversation
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.
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 |
tests/installer/default.nix
Outdated
|
||
"ubuntu-16-04" = { | ||
image = import <nix/fetchurl.nix> { | ||
url = https://app.vagrantup.com/generic/boxes/ubuntu1604/versions/4.1.12/providers/libvirt.box; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
|
||
in | ||
|
||
builtins.mapAttrs (imageName: image: |
There was a problem hiding this comment.
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...
c3b0763
to
71e364c
Compare
Add an installer test
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:
Hydra jobset for testing: https://hydra.nixos.org/jobset/nix/installer-test