summaryrefslogtreecommitdiffstats
path: root/nixos/tests/docker-autoprune.nix
blob: 2c7ab1d2eaf68dd4c3b0883bb534aac5cb5b32a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# This test validates the docker autoprune service, testing whether
# the default configuration cleans up images, while leaving volumes intact
# and whether the allVolumes option enables cleaning up volumes as well
{ pkgs, ... }:
{
  name = "docker";

  nodes = {
    prune =
      { pkgs, ... }:
      {
        virtualisation.docker = {
          enable = true;
          package = pkgs.docker;
          autoPrune = {
            enable = true;
          };
        };
      };
    prunevolumes =
      { pkgs, ... }:
      {
        virtualisation.docker = {
          enable = true;
          package = pkgs.docker;
          autoPrune = {
            enable = true;
            allVolumes.enable = true;
          };
        };
      };
  };

  testScript = ''
    start_all()

    with subtest("Check whether autoPrune works. Volumes should be left unpruned."):
      prune.wait_for_unit("sockets.target")
      prune.succeed("docker network create testnetwork")
      prune.succeed("docker network list --format json | grep testnetwork")
      prune.succeed("docker volume create testvolume")
      prune.succeed("docker volume list --format json | grep testvolume")

      prune.succeed("systemctl start -v docker-prune")
      prune.fail("docker network list --format json | grep testnetwork")
      # the volume has been left alone
      prune.succeed("docker volume list --format json | grep testvolume")

    with subtest("Check whether autoPrune including volumes works"):
      prunevolumes.wait_for_unit("sockets.target")
      prunevolumes.succeed("docker volume create testvolume")
      prunevolumes.succeed("docker volume list --format json | grep testvolume")

      prunevolumes.succeed("systemctl start -v docker-prune")
      prunevolumes.fail("docker volume list --format json | grep testvolume")
  '';
}