|
| 1 | +{ lib, ... }: |
| 2 | +{ |
| 3 | + _class = "nixosTest"; |
| 4 | + |
| 5 | + name = "easytier-modular"; |
| 6 | + |
| 7 | + nodes = |
| 8 | + let |
| 9 | + genPeer = |
| 10 | + hostConfig: |
| 11 | + { pkgs, ... }: |
| 12 | + lib.mkMerge [ |
| 13 | + { |
| 14 | + networking.useDHCP = false; |
| 15 | + networking.firewall.allowedTCPPorts = [ |
| 16 | + 11010 |
| 17 | + 11011 |
| 18 | + ]; |
| 19 | + networking.firewall.allowedUDPPorts = [ |
| 20 | + 11010 |
| 21 | + 11011 |
| 22 | + ]; |
| 23 | + |
| 24 | + system.services."easytier-default" = { |
| 25 | + imports = [ pkgs.easytier.services.default ]; |
| 26 | + easytier.settings = { |
| 27 | + instance_name = "default"; |
| 28 | + dev_name = "et_def"; |
| 29 | + rpc_portal = "0.0.0.0:11000"; |
| 30 | + network_identity = { |
| 31 | + network_name = "easytier_test"; |
| 32 | + network_secret = "easytier_test_secret"; |
| 33 | + }; |
| 34 | + }; |
| 35 | + }; |
| 36 | + } |
| 37 | + hostConfig |
| 38 | + ]; |
| 39 | + in |
| 40 | + { |
| 41 | + relay = |
| 42 | + { pkgs, ... }@args: |
| 43 | + lib.mkMerge [ |
| 44 | + (genPeer { |
| 45 | + virtualisation.vlans = [ |
| 46 | + 1 |
| 47 | + 2 |
| 48 | + ]; |
| 49 | + networking.interfaces.eth1.ipv4.addresses = [ |
| 50 | + { |
| 51 | + address = "192.168.1.11"; |
| 52 | + prefixLength = 24; |
| 53 | + } |
| 54 | + ]; |
| 55 | + networking.interfaces.eth2.ipv4.addresses = [ |
| 56 | + { |
| 57 | + address = "192.168.2.11"; |
| 58 | + prefixLength = 24; |
| 59 | + } |
| 60 | + ]; |
| 61 | + |
| 62 | + system.services."easytier-default".easytier.settings = { |
| 63 | + ipv4 = "10.144.144.1"; |
| 64 | + listeners = [ |
| 65 | + "tcp://0.0.0.0:11010" |
| 66 | + "wss://0.0.0.0:11011" |
| 67 | + ]; |
| 68 | + }; |
| 69 | + } args) |
| 70 | + |
| 71 | + { |
| 72 | + networking.firewall.allowedTCPPorts = [ 11020 ]; |
| 73 | + networking.firewall.allowedUDPPorts = [ 11020 ]; |
| 74 | + |
| 75 | + system.services."easytier-second" = { |
| 76 | + imports = [ pkgs.easytier.services.default ]; |
| 77 | + easytier = { |
| 78 | + peers = [ |
| 79 | + "tcp://192.168.1.11:11010" |
| 80 | + "tcp://192.168.2.11:11010" |
| 81 | + ]; |
| 82 | + settings = { |
| 83 | + instance_name = "second"; |
| 84 | + ipv4 = "10.144.144.4"; |
| 85 | + |
| 86 | + rpc_portal = "0.0.0.0:11001"; |
| 87 | + |
| 88 | + network_identity = { |
| 89 | + network_name = "easytier_test"; |
| 90 | + network_secret = "easytier_test_secret"; |
| 91 | + }; |
| 92 | + |
| 93 | + listeners = [ "tcp://0.0.0.0:11020" ]; |
| 94 | + flags = { |
| 95 | + bind_device = false; |
| 96 | + no_tun = true; |
| 97 | + }; |
| 98 | + }; |
| 99 | + }; |
| 100 | + }; |
| 101 | + } |
| 102 | + ]; |
| 103 | + |
| 104 | + peer1 = genPeer { |
| 105 | + virtualisation.vlans = [ 1 ]; |
| 106 | + system.services."easytier-default".easytier = { |
| 107 | + settings.ipv4 = "10.144.144.2"; |
| 108 | + peers = [ "tcp://192.168.1.11:11010" ]; |
| 109 | + }; |
| 110 | + }; |
| 111 | + |
| 112 | + peer2 = genPeer { |
| 113 | + virtualisation.vlans = [ 2 ]; |
| 114 | + system.services."easytier-default".easytier = { |
| 115 | + settings.ipv4 = "10.144.144.3"; |
| 116 | + peers = [ "wss://192.168.2.11:11011" ]; |
| 117 | + }; |
| 118 | + }; |
| 119 | + }; |
| 120 | + |
| 121 | + testScript = '' |
| 122 | + start_all() |
| 123 | +
|
| 124 | + with subtest("Waiting for all services..."): |
| 125 | + relay.wait_for_unit("easytier-default.service") |
| 126 | + relay.wait_for_unit("easytier-second.service") |
| 127 | + peer1.wait_for_unit("easytier-default.service") |
| 128 | + peer2.wait_for_unit("easytier-default.service") |
| 129 | +
|
| 130 | + with subtest("relay is accessible by the other hosts"): |
| 131 | + peer1.succeed("ping -c5 192.168.1.11") |
| 132 | + peer2.succeed("ping -c5 192.168.2.11") |
| 133 | +
|
| 134 | + with subtest("The other hosts are in separate vlans"): |
| 135 | + peer1.fail("ping -c5 192.168.2.11") |
| 136 | + peer2.fail("ping -c5 192.168.1.11") |
| 137 | +
|
| 138 | + with subtest("Each host can ping themselves through EasyTier"): |
| 139 | + relay.succeed("ping -c5 10.144.144.1") |
| 140 | + peer1.succeed("ping -c5 10.144.144.2") |
| 141 | + peer2.succeed("ping -c5 10.144.144.3") |
| 142 | +
|
| 143 | + with subtest("Relay is accessible by the other hosts through EasyTier"): |
| 144 | + peer1.succeed("ping -c5 10.144.144.1") |
| 145 | + peer2.succeed("ping -c5 10.144.144.1") |
| 146 | +
|
| 147 | + with subtest("Relay can access the other hosts through EasyTier"): |
| 148 | + relay.succeed("ping -c5 10.144.144.2") |
| 149 | + relay.succeed("ping -c5 10.144.144.3") |
| 150 | +
|
| 151 | + with subtest("The other hosts in separate vlans can access each other through EasyTier"): |
| 152 | + peer1.succeed("ping -c5 10.144.144.3") |
| 153 | + peer2.succeed("ping -c5 10.144.144.2") |
| 154 | +
|
| 155 | + with subtest("Relay Second is accessible through EasyTier"): |
| 156 | + peer1.succeed("ping -c5 10.144.144.4") |
| 157 | + peer2.succeed("ping -c5 10.144.144.4") |
| 158 | + ''; |
| 159 | + |
| 160 | + meta.maintainers = with lib.maintainers; [ moraxyc ]; |
| 161 | +} |
0 commit comments