at 23.11-pre 1.4 kB view raw
1import ./make-test-python.nix ({ lib, pkgs, ... }: 2{ 3 name = "swap-partition"; 4 5 nodes.machine = 6 { config, pkgs, lib, ... }: 7 { 8 virtualisation.useDefaultFilesystems = false; 9 10 virtualisation.rootDevice = "/dev/vda1"; 11 12 boot.initrd.postDeviceCommands = '' 13 if ! test -b /dev/vda1; then 14 ${pkgs.parted}/bin/parted --script /dev/vda -- mklabel msdos 15 ${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary 1MiB -250MiB 16 ${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary -250MiB 100% 17 sync 18 fi 19 20 FSTYPE=$(blkid -o value -s TYPE /dev/vda1 || true) 21 if test -z "$FSTYPE"; then 22 ${pkgs.e2fsprogs}/bin/mke2fs -t ext4 -L root /dev/vda1 23 ${pkgs.util-linux}/bin/mkswap --label swap /dev/vda2 24 fi 25 ''; 26 27 virtualisation.fileSystems = { 28 "/" = { 29 device = "/dev/disk/by-label/root"; 30 fsType = "ext4"; 31 }; 32 }; 33 34 swapDevices = [ 35 { 36 device = "/dev/disk/by-label/swap"; 37 } 38 ]; 39 }; 40 41 testScript = '' 42 machine.wait_for_unit("multi-user.target") 43 44 with subtest("Swap is active"): 45 # Doesn't matter if the numbers reported by `free` are slightly off due to unit conversions. 46 machine.succeed("free -h | grep -E 'Swap:\s+2[45][0-9]Mi'") 47 ''; 48})