summary refs log tree commit diff
path: root/nixos/tests/flannel.nix
blob: 7615732c20cac9c32ba567cb5b5e04bab9266013 (plain) (blame)
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
import ./make-test-python.nix ({ lib, ...} : {
  name = "flannel";

  meta = with lib.maintainers; {
    maintainers = [ offline ];
  };

  nodes = let
    flannelConfig = { pkgs, ... } : {
      services.flannel = {
        enable = true;
        backend = {
          Type = "udp";
          Port = 8285;
        };
        network = "10.1.0.0/16";
        iface = "eth1";
        etcd.endpoints = ["http://etcd:2379"];
      };

      networking.firewall.allowedUDPPorts = [ 8285 ];
    };
  in {
    etcd = { ... }: {
      services = {
        etcd = {
          enable = true;
          listenClientUrls = ["http://0.0.0.0:2379"]; # requires ip-address for binding
          listenPeerUrls = ["http://0.0.0.0:2380"]; # requires ip-address for binding
          advertiseClientUrls = ["http://etcd:2379"];
          initialAdvertisePeerUrls = ["http://etcd:2379"];
          initialCluster = ["etcd=http://etcd:2379"];
        };
      };

      networking.firewall.allowedTCPPorts = [ 2379 ];
    };

    node1 = flannelConfig;
    node2 = flannelConfig;
  };

  testScript = ''
    start_all()

    node1.wait_for_unit("flannel.service")
    node2.wait_for_unit("flannel.service")

    node1.wait_until_succeeds("ip l show dev flannel0")
    ip1 = node1.succeed("ip -4 addr show flannel0 | grep -oP '(?<=inet).*(?=/)'")
    node2.wait_until_succeeds("ip l show dev flannel0")
    ip2 = node2.succeed("ip -4 addr show flannel0 | grep -oP '(?<=inet).*(?=/)'")

    node1.wait_until_succeeds(f"ping -c 1 {ip2}")
    node2.wait_until_succeeds(f"ping -c 1 {ip1}")
  '';
})