diff options
author | T0astBread <tb@t0ast.cc> | 2022-06-22 04:11:23 +0200 |
---|---|---|
committer | T0astBread <tb@t0ast.cc> | 2022-07-02 15:37:08 +0200 |
commit | 5249031660b21610e291272fd2a9ebd172fda812 (patch) | |
tree | 793fe26446e4672ba010338cc33397140819d1c9 /nixos/tests/swap-partition.nix | |
parent | 4c77ffb38fcdb2accf3760966e4e6bc8628316b4 (diff) |
nixos/tests: add swap-partition test
Diffstat (limited to 'nixos/tests/swap-partition.nix')
-rw-r--r-- | nixos/tests/swap-partition.nix | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/nixos/tests/swap-partition.nix b/nixos/tests/swap-partition.nix new file mode 100644 index 0000000000000..2279630b57b8f --- /dev/null +++ b/nixos/tests/swap-partition.nix @@ -0,0 +1,48 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: +{ + name = "swap-partition"; + + nodes.machine = + { config, pkgs, lib, ... }: + { + virtualisation.useDefaultFilesystems = false; + + virtualisation.bootDevice = "/dev/vda1"; + + boot.initrd.postDeviceCommands = '' + if ! test -b /dev/vda1; then + ${pkgs.parted}/bin/parted --script /dev/vda -- mklabel msdos + ${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary 1MiB -250MiB + ${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary -250MiB 100% + sync + fi + + FSTYPE=$(blkid -o value -s TYPE /dev/vda1 || true) + if test -z "$FSTYPE"; then + ${pkgs.e2fsprogs}/bin/mke2fs -t ext4 -L root /dev/vda1 + ${pkgs.util-linux}/bin/mkswap --label swap /dev/vda2 + fi + ''; + + virtualisation.fileSystems = { + "/" = { + device = "/dev/disk/by-label/root"; + fsType = "ext4"; + }; + }; + + swapDevices = [ + { + device = "/dev/disk/by-label/swap"; + } + ]; + }; + + testScript = '' + machine.wait_for_unit("multi-user.target") + + with subtest("Swap is active"): + # Doesn't matter if the numbers reported by `free` are slightly off due to unit conversions. + machine.succeed("free -h | grep -E 'Swap:\s+2[45][0-9]Mi'") + ''; +}) |