at 21.11-pre 4.3 kB view raw
1# This test runs podman and checks if simple container starts 2 3import ./make-test-python.nix ( 4 { pkgs, lib, ... }: { 5 name = "podman"; 6 meta = { 7 maintainers = lib.teams.podman.members; 8 }; 9 10 nodes = { 11 podman = 12 { pkgs, ... }: 13 { 14 virtualisation.podman.enable = true; 15 16 users.users.alice = { 17 isNormalUser = true; 18 home = "/home/alice"; 19 description = "Alice Foobar"; 20 }; 21 22 }; 23 }; 24 25 testScript = '' 26 import shlex 27 28 29 def su_cmd(cmd): 30 cmd = shlex.quote(cmd) 31 return f"su alice -l -c {cmd}" 32 33 34 podman.wait_for_unit("sockets.target") 35 start_all() 36 37 with subtest("Run container as root with runc"): 38 podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg") 39 podman.succeed( 40 "podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 41 ) 42 podman.succeed("podman ps | grep sleeping") 43 podman.succeed("podman stop sleeping") 44 podman.succeed("podman rm sleeping") 45 46 with subtest("Run container as root with crun"): 47 podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg") 48 podman.succeed( 49 "podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 50 ) 51 podman.succeed("podman ps | grep sleeping") 52 podman.succeed("podman stop sleeping") 53 podman.succeed("podman rm sleeping") 54 55 with subtest("Run container as root with the default backend"): 56 podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg") 57 podman.succeed( 58 "podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 59 ) 60 podman.succeed("podman ps | grep sleeping") 61 podman.succeed("podman stop sleeping") 62 podman.succeed("podman rm sleeping") 63 64 # create systemd session for rootless 65 podman.succeed("loginctl enable-linger alice") 66 67 with subtest("Run container rootless with runc"): 68 podman.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg")) 69 podman.succeed( 70 su_cmd( 71 "podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 72 ) 73 ) 74 podman.succeed(su_cmd("podman ps | grep sleeping")) 75 podman.succeed(su_cmd("podman stop sleeping")) 76 podman.succeed(su_cmd("podman rm sleeping")) 77 78 with subtest("Run container rootless with crun"): 79 podman.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg")) 80 podman.succeed( 81 su_cmd( 82 "podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 83 ) 84 ) 85 podman.succeed(su_cmd("podman ps | grep sleeping")) 86 podman.succeed(su_cmd("podman stop sleeping")) 87 podman.succeed(su_cmd("podman rm sleeping")) 88 89 with subtest("Run container rootless with the default backend"): 90 podman.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg")) 91 podman.succeed( 92 su_cmd( 93 "podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 94 ) 95 ) 96 podman.succeed(su_cmd("podman ps | grep sleeping")) 97 podman.succeed(su_cmd("podman stop sleeping")) 98 podman.succeed(su_cmd("podman rm sleeping")) 99 100 with subtest("Run container with init"): 101 podman.succeed( 102 "tar cv -C ${pkgs.pkgsStatic.busybox} . | podman import - busybox" 103 ) 104 pid = podman.succeed("podman run --rm busybox readlink /proc/self").strip() 105 assert pid == "1" 106 pid = podman.succeed("podman run --rm --init busybox readlink /proc/self").strip() 107 assert pid == "2" 108 ''; 109 } 110)