summaryrefslogtreecommitdiffstats
path: root/nixos/tests/komodo-periphery.nix
blob: 1503493c81f09483092604bfdf3e465917d20adc (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ lib, ... }:
{
  name = "komodo-periphery";
  meta = {
    maintainers = with lib.maintainers; [ channinghe ];
  };

  nodes = {
    periphery =
      { ... }:
      {
        virtualisation.docker.enable = true;
        services.komodo-periphery = {
          enable = true;
          inbound.bindIp = "127.0.0.1";
          inbound.port = 8120;
          inbound.ssl.enable = false;
          inbound.serverEnabled = true;
          disableTerminals = true;
          disableContainerTerminals = true;
          statsPollingRate = "10-sec";
          containerStatsPollingRate = "1-min";
          logging.level = "debug";
          extraSettings = {
            secrets.TEST_SECRET = "test-value";
          };
          auth.privateKey = "file:/var/lib/komodo-periphery/keys/test.key";
          auth.corePublicKeys = [ "MCowBQYDK2VuAyEATZgrjGHeF0KJUe0+n77+qAWOg3YzEzXOmQWaRgO3OGQ=" ];
        };
      };

    peripheryOutbound =
      { ... }:
      {
        virtualisation.docker.enable = true;
        services.komodo-periphery = {
          enable = true;
          inbound.ssl.enable = false;
          logging.level = "debug";
          outbound.coreAddress = "core.invalid";
          outbound.connectAs = "test-server";
        };
      };
  };

  testScript = ''
    def with_unit_path(node, cmd):
        """Run cmd with the PATH systemd hands to komodo-periphery.service."""
        unit_path = "$(systemctl show -p Environment --value komodo-periphery | grep -o 'PATH=[^ ]*' | cut -d= -f2)"
        node.succeed(f"export PATH={unit_path}; {cmd}")

    start_all()

    with subtest("Inbound periphery starts and serves /version"):
        periphery.wait_for_unit("komodo-periphery.service")
        periphery.wait_for_open_port(8120)
        periphery.succeed("curl -fsS --max-time 10 http://127.0.0.1:8120/version")

    with subtest("Periphery creates managed directories"):
        periphery.succeed("test -d /var/lib/komodo-periphery")
        periphery.succeed("test -d /var/lib/komodo-periphery/repos")
        periphery.succeed("test -d /var/lib/komodo-periphery/stacks")
        periphery.succeed("test -d /var/lib/komodo-periphery/builds")
        periphery.succeed("test -d /var/lib/komodo-periphery/keys")
        periphery.succeed("test -d /var/lib/komodo-periphery/ssl")

    with subtest("Service PATH provides docker, docker compose and git"):
        with_unit_path(periphery, "command -v docker && command -v git && docker compose version")

    with subtest("Outbound periphery stays active despite unreachable core"):
        peripheryOutbound.wait_for_unit("komodo-periphery.service")
        peripheryOutbound.sleep(15)
        peripheryOutbound.succeed("systemctl is-active komodo-periphery")

    with subtest("Terminal-enabled periphery sees system-wide tools on PATH"):
        with_unit_path(peripheryOutbound, "command -v bash")
  '';
}