diff options
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/all-tests.nix | 2 | ||||
-rw-r--r-- | nixos/tests/hardened.nix | 1 | ||||
-rwxr-xr-x | nixos/tests/hydra/create-trivial-project.sh | 2 | ||||
-rw-r--r-- | nixos/tests/hydra/default.nix | 23 | ||||
-rw-r--r-- | nixos/tests/minidlna.nix | 39 | ||||
-rw-r--r-- | nixos/tests/os-prober.nix | 119 |
6 files changed, 179 insertions, 7 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 60762de76d33..5643da99e557 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -162,6 +162,7 @@ in metabase = handleTest ./metabase.nix {}; miniflux = handleTest ./miniflux.nix {}; minio = handleTest ./minio.nix {}; + minidlna = handleTest ./minidlna.nix {}; misc = handleTest ./misc.nix {}; mongodb = handleTest ./mongodb.nix {}; moodle = handleTest ./moodle.nix {}; @@ -204,6 +205,7 @@ in # openstack-image-userdata doesn't work in a sandbox as the simulated openstack instance needs network access #openstack-image-userdata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).userdata or {}; openstack-image-metadata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).metadata or {}; + os-prober = handleTestOn ["x86_64-linux"] ./os-prober.nix {}; osquery = handleTest ./osquery.nix {}; osrm-backend = handleTest ./osrm-backend.nix {}; ostree = handleTest ./ostree.nix {}; diff --git a/nixos/tests/hardened.nix b/nixos/tests/hardened.nix index 90f9793b370c..cbf76f9e5587 100644 --- a/nixos/tests/hardened.nix +++ b/nixos/tests/hardened.nix @@ -10,6 +10,7 @@ import ./make-test.nix ({ pkgs, ...} : { { users.users.alice = { isNormalUser = true; extraGroups = [ "proc" ]; }; users.users.sybil = { isNormalUser = true; group = "wheel"; }; imports = [ ../modules/profiles/hardened.nix ]; + environment.memoryAllocator.provider = "graphene-hardened"; nix.useSandbox = false; virtualisation.emptyDiskImages = [ 4096 ]; boot.initrd.postDeviceCommands = '' diff --git a/nixos/tests/hydra/create-trivial-project.sh b/nixos/tests/hydra/create-trivial-project.sh index 39122c9b473a..5aae2d5bf90d 100755 --- a/nixos/tests/hydra/create-trivial-project.sh +++ b/nixos/tests/hydra/create-trivial-project.sh @@ -44,6 +44,8 @@ cat >data.json <<EOF "enabled": "1", "visible": "1", "keepnr": "1", + "enableemail": true, + "emailoverride": "hydra@localhost", "nixexprinput": "trivial", "nixexprpath": "trivial.nix", "inputs": { diff --git a/nixos/tests/hydra/default.nix b/nixos/tests/hydra/default.nix index f99b367ac9b7..6ca05a2c7797 100644 --- a/nixos/tests/hydra/default.nix +++ b/nixos/tests/hydra/default.nix @@ -8,8 +8,10 @@ let trivialJob = pkgs.writeTextDir "trivial.nix" '' { trivial = builtins.derivation { name = "trivial"; - system = "x86_64-linux"; + system = "${system}"; builder = "/bin/sh"; + allowSubstitutes = false; + preferLocalBuild = true; args = ["-c" "echo success > $out; exit 0"]; }; } @@ -53,11 +55,16 @@ let notificationSender = "example@example.com"; package = pkgs.hydra.override { inherit nix; }; + + extraConfig = '' + email_notification = 1 + ''; }; + services.postfix.enable = true; nix = { buildMachines = [{ hostName = "localhost"; - systems = [ "x86_64-linux" ]; + systems = [ system ]; }]; binaryCaches = []; @@ -68,12 +75,12 @@ let # let the system boot up $machine->waitForUnit("multi-user.target"); # test whether the database is running - $machine->succeed("systemctl status postgresql.service"); + $machine->waitForUnit("postgresql.service"); # test whether the actual hydra daemons are running - $machine->succeed("systemctl status hydra-queue-runner.service"); - $machine->succeed("systemctl status hydra-init.service"); - $machine->succeed("systemctl status hydra-evaluator.service"); - $machine->succeed("systemctl status hydra-send-stats.service"); + $machine->waitForUnit("hydra-init.service"); + $machine->requireActiveUnit("hydra-queue-runner.service"); + $machine->requireActiveUnit("hydra-evaluator.service"); + $machine->requireActiveUnit("hydra-notify.service"); $machine->succeed("hydra-create-user admin --role admin --password admin"); @@ -84,6 +91,8 @@ let $machine->succeed("create-trivial-project.sh"); $machine->waitUntilSucceeds('curl -L -s http://localhost:3000/build/1 -H "Accept: application/json" | jq .buildstatus | xargs test 0 -eq'); + + $machine->waitUntilSucceeds('journalctl -eu hydra-notify.service -o cat | grep -q "sending mail notification to hydra@localhost"'); ''; }))); diff --git a/nixos/tests/minidlna.nix b/nixos/tests/minidlna.nix new file mode 100644 index 000000000000..7bf1bed69d06 --- /dev/null +++ b/nixos/tests/minidlna.nix @@ -0,0 +1,39 @@ +import ./make-test.nix ({ pkgs, ... }: { + name = "minidlna"; + + nodes = { + server = + { ... }: + { + imports = [ ../modules/profiles/minimal.nix ]; + networking.firewall.allowedTCPPorts = [ 8200 ]; + services.minidlna = { + enable = true; + loglevel = "error"; + mediaDirs = [ + "PV,/tmp/stuff" + ]; + friendlyName = "rpi3"; + rootContainer = "B"; + extraConfig = + '' + album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg + album_art_names=AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg + album_art_names=Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg + notify_interval=60 + ''; + }; + }; + client = { ... }: { }; + }; + + testScript = + '' + startAll; + $server->succeed("mkdir -p /tmp/stuff && chown minidlna: /tmp/stuff"); + $server->waitForUnit("minidlna"); + $server->waitForOpenPort("8200"); + $server->succeed("curl --fail http://localhost:8200/"); + $client->succeed("curl --fail http://server:8200/"); + ''; +}) diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix new file mode 100644 index 000000000000..9cd9f4ecd150 --- /dev/null +++ b/nixos/tests/os-prober.nix @@ -0,0 +1,119 @@ +import ./make-test.nix ({pkgs, lib, ...}: +let + # A filesystem image with a (presumably) bootable debian + debianImage = pkgs.vmTools.diskImageFuns.debian9i386 { + # os-prober cannot detect systems installed on disks without a partition table + # so we create the disk ourselves + createRootFS = with pkgs; '' + ${parted}/bin/parted --script /dev/vda mklabel msdos + ${parted}/sbin/parted --script /dev/vda -- mkpart primary ext2 1M -1s + mkdir /mnt + ${e2fsprogs}/bin/mkfs.ext4 /dev/vda1 + ${utillinux}/bin/mount -t ext4 /dev/vda1 /mnt + + if test -e /mnt/.debug; then + exec ${bash}/bin/sh + fi + touch /mnt/.debug + + mkdir /mnt/proc /mnt/dev /mnt/sys + ''; + extraPackages = [ + # /etc/os-release + "base-files" + # make the disk bootable-looking + "grub2" "linux-image-686" + ]; + # install grub + postInstall = '' + ln -sf /proc/self/mounts > /etc/mtab + PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \ + grub-install /dev/vda --force + PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \ + update-grub + ''; + }; + + # options to add the disk to the test vm + QEMU_OPTS = "-drive index=2,file=${debianImage}/disk-image.qcow2,read-only,if=virtio"; + + # a part of the configuration of the test vm + simpleConfig = { + boot.loader.grub = { + enable = true; + useOSProber = true; + device = "/dev/vda"; + # vda is a filesystem without partition table + forceInstall = true; + }; + nix.binaryCaches = lib.mkForce [ ]; + nix.extraOptions = '' + hashed-mirrors = + connect-timeout = 1 + ''; + services.udisks2.enable = lib.mkForce false; + }; + # /etc/nixos/configuration.nix for the vm + configFile = pkgs.writeText "configuration.nix" '' + {config, pkgs, ...}: ({ + imports = + [ ./hardware-configuration.nix + <nixpkgs/nixos/modules/testing/test-instrumentation.nix> + ]; + } // (builtins.fromJSON (builtins.readFile ${ + pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig) + }))) + ''; +in { + name = "os-prober"; + + machine = { config, pkgs, ... }: (simpleConfig // { + imports = [ ../modules/profiles/installation-device.nix + ../modules/profiles/base.nix ]; + virtualisation.memorySize = 1024; + # The test cannot access the network, so any packages + # nixos-rebuild needs must be included in the VM. + system.extraDependencies = with pkgs; + [ sudo + libxml2.bin + libxslt.bin + desktop-file-utils + docbook5 + docbook_xsl_ns + unionfs-fuse + ntp + nixos-artwork.wallpapers.simple-dark-gray-bottom + perlPackages.XMLLibXML + perlPackages.ListCompare + shared-mime-info + texinfo + xorg.lndir + grub2 + + # add curl so that rather than seeing the test attempt to download + # curl's tarball, we see what it's trying to download + curl + ]; + }); + + testScript = '' + # hack to add the secondary disk + $machine->{startCommand} = "QEMU_OPTS=\"\$QEMU_OPTS \"${lib.escapeShellArg QEMU_OPTS} ".$machine->{startCommand}; + + $machine->start; + $machine->succeed("udevadm settle"); + $machine->waitForUnit("multi-user.target"); + + # check that os-prober works standalone + $machine->succeed("${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1"); + + # rebuild and test that debian is available in the grub menu + $machine->succeed("nixos-generate-config"); + $machine->copyFileFromHost( + "${configFile}", + "/etc/nixos/configuration.nix"); + $machine->succeed("nixos-rebuild boot >&2"); + + $machine->succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg"); + ''; +}) |