From 8f6d8cf9790e522a5122bab633ba5da1600b454c Mon Sep 17 00:00:00 2001 From: Tom DNetto Date: Mon, 11 Apr 2022 11:58:06 -0700 Subject: [PATCH] tstest/integration/vms: test on stable nixos (21.11) I would like to do some more customized integration tests in the future, (specifically, bringing up a mitm proxy and testing tailscaled through that) so hoping to bring back the nixos wiring to support that. Signed-off-by: Tom DNetto --- tstest/integration/vms/README.md | 2 +- tstest/integration/vms/distros.go | 1 + tstest/integration/vms/distros.hujson | 9 +++++++++ tstest/integration/vms/top_level_test.go | 6 ++++++ tstest/integration/vms/vm_setup_test.go | 16 +++++++++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tstest/integration/vms/README.md b/tstest/integration/vms/README.md index 52903cabd..519c3d000 100644 --- a/tstest/integration/vms/README.md +++ b/tstest/integration/vms/README.md @@ -35,7 +35,7 @@ If you are using [Nix](https://nixos.org), you can run all of the tests with the correct command line tools using this command: ```console -$ nix-shell -p openssh -p go -p qemu -p cdrkit --run "go test . --run-vm-tests --v --timeout 30m --no-s3" +$ nix-shell -p nixos-generators -p openssh -p go -p qemu -p cdrkit --run "go test . --run-vm-tests --v --timeout 30m --no-s3" ``` Keep the timeout high for the first run, especially if you are not downloading diff --git a/tstest/integration/vms/distros.go b/tstest/integration/vms/distros.go index ad899a1b7..4b8394653 100644 --- a/tstest/integration/vms/distros.go +++ b/tstest/integration/vms/distros.go @@ -20,6 +20,7 @@ type Distro struct { MemoryMegs int // VM memory in megabytes PackageManager string // yum/apt/dnf/zypper InitSystem string // systemd/openrc + HostGenerated bool // generated image rather than downloaded } func (d *Distro) InstallPre() string { diff --git a/tstest/integration/vms/distros.hujson b/tstest/integration/vms/distros.hujson index d024f35ff..049091ed5 100644 --- a/tstest/integration/vms/distros.hujson +++ b/tstest/integration/vms/distros.hujson @@ -27,4 +27,13 @@ "PackageManager": "apt", "InitSystem": "systemd" }, + { + "Name": "nixos-21-11", + "URL": "channel:nixos-21.11", + "SHA256Sum": "lolfakesha", + "MemoryMegs": 512, + "PackageManager": "nix", + "InitSystem": "systemd", + "HostGenerated": true + }, ] diff --git a/tstest/integration/vms/top_level_test.go b/tstest/integration/vms/top_level_test.go index 5f0744119..a7d6172d0 100644 --- a/tstest/integration/vms/top_level_test.go +++ b/tstest/integration/vms/top_level_test.go @@ -18,3 +18,9 @@ func TestRunUbuntu2004(t *testing.T) { setupTests(t) testOneDistribution(t, 1, Distros[1]) } + +func TestRunNixos2111(t *testing.T) { + t.Parallel() + setupTests(t) + testOneDistribution(t, 2, Distros[2]) +} \ No newline at end of file diff --git a/tstest/integration/vms/vm_setup_test.go b/tstest/integration/vms/vm_setup_test.go index 04212a480..f61bdff77 100644 --- a/tstest/integration/vms/vm_setup_test.go +++ b/tstest/integration/vms/vm_setup_test.go @@ -49,6 +49,13 @@ func (vm *vmInstance) running() bool { } } +func (h *Harness) makeImage(t *testing.T, d Distro, cdir string) string { + if !strings.HasPrefix(d.Name, "nixos") { + t.Fatal("image generation for non-nixos is not implemented") + } + return h.makeNixOSImage(t, d, cdir) +} + // mkVM makes a KVM-accelerated virtual machine and prepares it for introduction // to the testcontrol server. The function it returns is for killing the virtual // machine when it is time for it to die. @@ -67,7 +74,14 @@ func (h *Harness) mkVM(t *testing.T, n int, d Distro, sshKey, hostURL, tdir stri t.Fatal(err) } - mkLayeredQcow(t, tdir, d, fetchDistro(t, d)) + var qcowPath string + if d.HostGenerated { + qcowPath = h.makeImage(t, d, cdir) + } else { + qcowPath = fetchDistro(t, d) + } + + mkLayeredQcow(t, tdir, d, qcowPath) mkSeed(t, d, sshKey, hostURL, tdir, port) driveArg := fmt.Sprintf("file=%s,if=virtio", filepath.Join(tdir, d.Name+".qcow2"))