summaryrefslogtreecommitdiffstats
path: root/nixos/tests/atticd.nix
blob: ac4b7a7375126d28962142e03744307342939d61 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{ lib, pkgs, ... }:

let
  accessKey = "GKaaaaaaaaaaaaaaaaaaaaaaaa";
  secretKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  s3Addr = "127.0.0.1:9000";

  environmentFile = pkgs.runCommand "atticd-env" { } ''
    echo ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64="$(${lib.getExe pkgs.openssl} genrsa -traditional 4096 | ${pkgs.coreutils}/bin/base64 -w0)" > $out
  '';
in

{
  name = "atticd";

  nodes = {
    local = {
      nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)

      services.atticd = {
        enable = true;

        inherit environmentFile;
      };

      environment.systemPackages = [
        pkgs.attic-client
      ];
    };

    s3 = {
      nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)

      services.atticd = {
        enable = true;
        settings = {
          storage = {
            type = "s3";
            bucket = "attic";
            region = "garage";
            endpoint = "http://${s3Addr}";

            credentials = {
              access_key_id = accessKey;
              secret_access_key = secretKey;
            };
          };
        };

        inherit environmentFile;
      };

      services.garage = {
        enable = true;
        package = pkgs.garage_2;
        settings = {
          rpc_bind_addr = "127.0.0.1:3901";
          rpc_public_addr = "127.0.0.1:3901";
          rpc_secret = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
          replication_factor = 1;

          s3_api = {
            s3_region = "garage";
            api_bind_addr = s3Addr;
          };
        };
      };

      environment.systemPackages = [
        pkgs.attic-client
      ];
    };
  };

  testScript = # python
    ''
      start_all()

      with subtest("local storage push"):
          local.wait_for_unit("atticd.service")
          token = local.succeed("atticd-atticadm make-token --sub stop --validity 1y --create-cache '*' --pull '*' --push '*' --delete '*' --configure-cache '*' --configure-cache-retention '*'").strip()

          local.succeed(f"attic login local http://localhost:8080 {token}")
          local.succeed("attic cache create test-cache")
          local.succeed("attic push test-cache ${environmentFile}")

      with subtest("s3 storage push"):
          s3.wait_for_unit("garage.service")
          s3.wait_for_open_port(3901)
          garage_node_id = s3.succeed("garage status | tail -n1 | awk '{ print $1 }'")
          s3.succeed(
              f"garage layout assign -c 100MB -z garage {garage_node_id}",
              "garage layout apply --version 1",
              "garage key import ${accessKey} ${secretKey} --yes",
              "garage bucket create attic",
              "garage bucket allow --read --write --owner attic --key ${accessKey}"
          )

          s3.wait_for_unit("atticd.service")
          s3.wait_for_open_port(9000)
          token = s3.succeed("atticd-atticadm make-token --sub stop --validity 1y --create-cache '*' --pull '*' --push '*' --delete '*' --configure-cache '*' --configure-cache-retention '*'").strip()

          s3.succeed(f"attic login s3 http://localhost:8080 {token}")
          s3.succeed("attic cache create test-cache")
          s3.succeed("attic push test-cache ${environmentFile}")
    '';
}