2020-04-20 08:37:53 +00:00
|
|
|
# This test runs podman and checks if simple container starts
|
|
|
|
|
|
|
|
import ./make-test-python.nix (
|
2020-04-20 11:35:36 +00:00
|
|
|
{ pkgs, lib, ... }: {
|
2020-04-20 08:37:53 +00:00
|
|
|
name = "podman";
|
2020-04-20 11:35:36 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.podman.members;
|
2020-04-20 08:37:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
podman =
|
|
|
|
{ pkgs, ... }:
|
2020-04-24 09:49:36 +00:00
|
|
|
{
|
|
|
|
virtualisation.podman.enable = true;
|
|
|
|
|
2021-05-25 08:26:28 +00:00
|
|
|
# To test docker socket support
|
|
|
|
virtualisation.podman.dockerSocket.enable = true;
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.docker-client
|
|
|
|
];
|
|
|
|
|
2020-04-24 09:49:36 +00:00
|
|
|
users.users.alice = {
|
|
|
|
isNormalUser = true;
|
|
|
|
home = "/home/alice";
|
|
|
|
description = "Alice Foobar";
|
2021-05-25 08:26:28 +00:00
|
|
|
extraGroups = [ "podman" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.mallory = {
|
|
|
|
isNormalUser = true;
|
|
|
|
home = "/home/mallory";
|
|
|
|
description = "Mallory Foobar";
|
2020-04-20 08:37:53 +00:00
|
|
|
};
|
2020-04-24 09:49:36 +00:00
|
|
|
|
|
|
|
};
|
2020-04-20 08:37:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2020-04-24 09:49:36 +00:00
|
|
|
import shlex
|
|
|
|
|
|
|
|
|
2021-05-25 08:26:28 +00:00
|
|
|
def su_cmd(cmd, user = "alice"):
|
2020-04-24 09:49:36 +00:00
|
|
|
cmd = shlex.quote(cmd)
|
2021-05-25 08:26:28 +00:00
|
|
|
return f"su {user} -l -c {cmd}"
|
2020-04-24 09:49:36 +00:00
|
|
|
|
2020-04-20 08:37:53 +00:00
|
|
|
|
|
|
|
podman.wait_for_unit("sockets.target")
|
2020-04-24 09:49:36 +00:00
|
|
|
start_all()
|
|
|
|
|
2020-05-13 05:12:59 +00:00
|
|
|
with subtest("Run container as root with runc"):
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg")
|
2020-04-24 09:49:36 +00:00
|
|
|
podman.succeed(
|
2020-05-13 05:12:59 +00:00
|
|
|
"podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
2020-04-24 09:49:36 +00:00
|
|
|
)
|
|
|
|
podman.succeed("podman ps | grep sleeping")
|
|
|
|
podman.succeed("podman stop sleeping")
|
2020-05-13 05:12:59 +00:00
|
|
|
podman.succeed("podman rm sleeping")
|
2020-04-24 09:49:36 +00:00
|
|
|
|
2020-05-13 05:12:59 +00:00
|
|
|
with subtest("Run container as root with crun"):
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg")
|
2020-05-13 05:12:59 +00:00
|
|
|
podman.succeed(
|
|
|
|
"podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
|
|
|
podman.succeed("podman ps | grep sleeping")
|
|
|
|
podman.succeed("podman stop sleeping")
|
|
|
|
podman.succeed("podman rm sleeping")
|
|
|
|
|
2020-11-19 23:15:31 +00:00
|
|
|
with subtest("Run container as root with the default backend"):
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg")
|
2020-11-19 23:15:31 +00:00
|
|
|
podman.succeed(
|
|
|
|
"podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
|
|
|
podman.succeed("podman ps | grep sleeping")
|
|
|
|
podman.succeed("podman stop sleeping")
|
|
|
|
podman.succeed("podman rm sleeping")
|
|
|
|
|
2021-01-18 23:16:13 +00:00
|
|
|
# create systemd session for rootless
|
|
|
|
podman.succeed("loginctl enable-linger alice")
|
|
|
|
|
|
|
|
with subtest("Run container rootless with runc"):
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed(su_cmd("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg"))
|
2021-01-18 23:16:13 +00:00
|
|
|
podman.succeed(
|
|
|
|
su_cmd(
|
|
|
|
"podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
podman.succeed(su_cmd("podman ps | grep sleeping"))
|
|
|
|
podman.succeed(su_cmd("podman stop sleeping"))
|
|
|
|
podman.succeed(su_cmd("podman rm sleeping"))
|
|
|
|
|
2020-11-19 23:15:31 +00:00
|
|
|
with subtest("Run container rootless with crun"):
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed(su_cmd("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg"))
|
2020-05-13 05:12:59 +00:00
|
|
|
podman.succeed(
|
|
|
|
su_cmd(
|
2020-11-19 23:15:31 +00:00
|
|
|
"podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
2020-05-13 05:12:59 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
podman.succeed(su_cmd("podman ps | grep sleeping"))
|
|
|
|
podman.succeed(su_cmd("podman stop sleeping"))
|
|
|
|
podman.succeed(su_cmd("podman rm sleeping"))
|
|
|
|
|
2020-11-19 23:15:31 +00:00
|
|
|
with subtest("Run container rootless with the default backend"):
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed(su_cmd("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg"))
|
2020-04-24 09:49:36 +00:00
|
|
|
podman.succeed(
|
|
|
|
su_cmd(
|
2020-11-19 23:15:31 +00:00
|
|
|
"podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
2020-04-24 09:49:36 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
podman.succeed(su_cmd("podman ps | grep sleeping"))
|
|
|
|
podman.succeed(su_cmd("podman stop sleeping"))
|
2020-05-13 05:12:59 +00:00
|
|
|
podman.succeed(su_cmd("podman rm sleeping"))
|
2021-03-21 20:12:32 +00:00
|
|
|
|
|
|
|
with subtest("Run container with init"):
|
|
|
|
podman.succeed(
|
2021-06-18 05:43:24 +00:00
|
|
|
"tar cvf busybox.tar -C ${pkgs.pkgsStatic.busybox} . && podman import busybox.tar busybox"
|
2021-03-21 20:12:32 +00:00
|
|
|
)
|
|
|
|
pid = podman.succeed("podman run --rm busybox readlink /proc/self").strip()
|
|
|
|
assert pid == "1"
|
|
|
|
pid = podman.succeed("podman run --rm --init busybox readlink /proc/self").strip()
|
|
|
|
assert pid == "2"
|
2021-05-25 08:26:28 +00:00
|
|
|
|
|
|
|
with subtest("A podman member can use the docker cli"):
|
|
|
|
podman.succeed(su_cmd("docker version"))
|
|
|
|
|
|
|
|
with subtest("Run container via docker cli"):
|
|
|
|
podman.succeed("docker network create default")
|
2021-06-18 05:43:24 +00:00
|
|
|
podman.succeed("tar cvf scratchimg.tar --files-from /dev/null && podman import scratchimg.tar scratchimg")
|
2021-05-25 08:26:28 +00:00
|
|
|
podman.succeed(
|
|
|
|
"docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
|
|
|
podman.succeed("docker ps | grep sleeping")
|
|
|
|
podman.succeed("podman ps | grep sleeping")
|
|
|
|
podman.succeed("docker stop sleeping")
|
|
|
|
podman.succeed("docker rm sleeping")
|
2021-05-25 15:39:23 +00:00
|
|
|
podman.succeed("docker network rm default")
|
2021-05-25 08:26:28 +00:00
|
|
|
|
|
|
|
with subtest("A podman non-member can not use the docker cli"):
|
|
|
|
podman.fail(su_cmd("docker version", user="mallory"))
|
|
|
|
|
|
|
|
# TODO: add docker-compose test
|
|
|
|
|
2020-04-20 08:37:53 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|