nixosTests.docker: migrate to runTest

Part of #386873
This commit is contained in:
Piotr Kwiecinski 2025-04-02 14:37:58 +02:00
parent 2f176b5def
commit d175fc3af4
No known key found for this signature in database
GPG key ID: EC0DE1CB9D5258B4
2 changed files with 48 additions and 51 deletions

View file

@ -369,7 +369,7 @@ in
dnscrypt-proxy2 = handleTestOn [ "x86_64-linux" ] ./dnscrypt-proxy2.nix { }; dnscrypt-proxy2 = handleTestOn [ "x86_64-linux" ] ./dnscrypt-proxy2.nix { };
dnsdist = import ./dnsdist.nix { inherit pkgs runTest; }; dnsdist = import ./dnsdist.nix { inherit pkgs runTest; };
doas = runTest ./doas.nix; doas = runTest ./doas.nix;
docker = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./docker.nix { }; docker = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./docker.nix;
docker-rootless = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./docker-rootless.nix { }; docker-rootless = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./docker-rootless.nix { };
docker-registry = handleTest ./docker-registry.nix { }; docker-registry = handleTest ./docker-registry.nix { };
docker-tools = handleTestOn [ "x86_64-linux" ] ./docker-tools.nix { }; docker-tools = handleTestOn [ "x86_64-linux" ] ./docker-tools.nix { };

View file

@ -1,59 +1,56 @@
# This test runs docker and checks if simple container starts # This test runs docker and checks if simple container starts
{ pkgs, ... }:
{
name = "docker";
meta = with pkgs.lib.maintainers; {
maintainers = [
nequissimus
offline
];
};
import ./make-test-python.nix ( nodes = {
{ pkgs, ... }: docker =
{ { pkgs, ... }:
name = "docker"; {
meta = with pkgs.lib.maintainers; { virtualisation.docker.enable = true;
maintainers = [ virtualisation.docker.autoPrune.enable = true;
nequissimus virtualisation.docker.package = pkgs.docker;
offline
];
};
nodes = { users.users = {
docker = noprivs = {
{ pkgs, ... }: isNormalUser = true;
{ description = "Can't access the docker daemon";
virtualisation.docker.enable = true; password = "foobar";
virtualisation.docker.autoPrune.enable = true; };
virtualisation.docker.package = pkgs.docker;
users.users = { hasprivs = {
noprivs = { isNormalUser = true;
isNormalUser = true; description = "Can access the docker daemon";
description = "Can't access the docker daemon"; password = "foobar";
password = "foobar"; extraGroups = [ "docker" ];
};
hasprivs = {
isNormalUser = true;
description = "Can access the docker daemon";
password = "foobar";
extraGroups = [ "docker" ];
};
}; };
}; };
}; };
};
testScript = '' testScript = ''
start_all() start_all()
docker.wait_for_unit("sockets.target") docker.wait_for_unit("sockets.target")
docker.succeed("tar cv --files-from /dev/null | docker import - scratchimg") docker.succeed("tar cv --files-from /dev/null | docker import - scratchimg")
docker.succeed( docker.succeed(
"docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" "docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
) )
docker.succeed("docker ps | grep sleeping") docker.succeed("docker ps | grep sleeping")
docker.succeed("sudo -u hasprivs docker ps") docker.succeed("sudo -u hasprivs docker ps")
docker.fail("sudo -u noprivs docker ps") docker.fail("sudo -u noprivs docker ps")
docker.succeed("docker stop sleeping") docker.succeed("docker stop sleeping")
# Must match version 4 times to ensure client and server git commits and versions are correct # Must match version 4 times to ensure client and server git commits and versions are correct
docker.succeed('[ $(docker version | grep ${pkgs.docker.version} | wc -l) = "4" ]') docker.succeed('[ $(docker version | grep ${pkgs.docker.version} | wc -l) = "4" ]')
docker.succeed("systemctl restart systemd-sysctl") docker.succeed("systemctl restart systemd-sysctl")
docker.succeed("grep 1 /proc/sys/net/ipv4/conf/all/forwarding") docker.succeed("grep 1 /proc/sys/net/ipv4/conf/all/forwarding")
docker.succeed("grep 1 /proc/sys/net/ipv4/conf/default/forwarding") docker.succeed("grep 1 /proc/sys/net/ipv4/conf/default/forwarding")
''; '';
} }
)