summaryrefslogtreecommitdiffstats
path: root/nixos/tests/garage/with-3node-replication.nix
blob: 5abdc4b412fccff7368e31b5433918642d233dde (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
{
  lib,
  mkNode,
  package,
  testScriptSetup,
  ...
}:
let
  extraSettings =
    if (lib.versionAtLeast package.version "2") then
      {
        replication_factor = 3;
        consistency_mode = "consistent";
      }
    else
      {
        replication_mode = "3";
      };
in
{
  name = "garage-${package.version}-3node-replication";

  nodes = {
    node1 = mkNode {
      inherit extraSettings;
      publicV6Address = "fc00:1::1";
    };
    node2 = mkNode {
      inherit extraSettings;
      publicV6Address = "fc00:1::2";
    };
    node3 = mkNode {
      inherit extraSettings;
      publicV6Address = "fc00:1::3";
    };
    node4 = mkNode {
      inherit extraSettings;
      publicV6Address = "fc00:1::4";
    };
  };

  testScript = # python
    ''
      ${testScriptSetup}

      with subtest("Garage works as a multi-node S3 storage"):
        nodes = ('node1', 'node2', 'node3', 'node4')
        rev_machines = {m.name: m for m in machines}
        def get_machine(key): return rev_machines[key]
        for key in nodes:
          node = get_machine(key)
          node.wait_for_unit("garage.service")
          node.wait_for_open_port(3900)

        # Garage is initialized on all nodes.
        node_ids = {key: get_node_fqn(get_machine(key)) for key in nodes}

        for key in nodes:
          for other_key in nodes:
            if other_key != key:
              other_id = node_ids[other_key]
              get_machine(key).succeed(f"garage node connect {other_id.node_id}@{other_id.host}")

        # Provide multiple zones for the nodes.
        zones = ["nixcon", "nixcon", "paris_meetup", "fosdem"]
        apply_garage_layout(node1,
        [
          f'{ndata.node_id} -z {zones[index]} -c 1G'
          for index, ndata in enumerate(node_ids.values())
        ])
        # Now Garage is operational.
        test_bucket_writes(node1)
        for node in nodes:
           test_bucket_over_http(get_machine(node))
    '';
}