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