diff options
author | markuskowa <markus.kowalewski@gmail.com> | 2021-06-16 10:54:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 10:54:23 +0200 |
commit | 5ad54b5bc9c705020cce51dbd91f81a019792628 (patch) | |
tree | 266123dae7e529371d26d11221b28cef1e49dff6 /nixos/tests | |
parent | b556e18c99d97a000423964c6d14e2ab885c2a37 (diff) | |
parent | 95ca79092e3275d1ac8e3fa4d97e7c1a111f7d14 (diff) | |
download | nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.tar nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.tar.gz nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.tar.bz2 nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.tar.lz nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.tar.xz nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.tar.zst nixlib-5ad54b5bc9c705020cce51dbd91f81a019792628.zip |
Merge pull request #126785 from oxzi/ucarp-1.5.2
ucarp: init at 1.5.2 / nixos/ucarp: init / nixos/test/ucarp: init
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/ucarp.nix | 66 |
2 files changed, 67 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index d8fcbde6bc0c..e8c86394831d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -433,6 +433,7 @@ in trilium-server = handleTestOn ["x86_64-linux"] ./trilium-server.nix {}; tuptime = handleTest ./tuptime.nix {}; turbovnc-headless-server = handleTest ./turbovnc-headless-server.nix {}; + ucarp = handleTest ./ucarp.nix {}; ucg = handleTest ./ucg.nix {}; udisks2 = handleTest ./udisks2.nix {}; unbound = handleTest ./unbound.nix {}; diff --git a/nixos/tests/ucarp.nix b/nixos/tests/ucarp.nix new file mode 100644 index 000000000000..1f60f770d3a8 --- /dev/null +++ b/nixos/tests/ucarp.nix @@ -0,0 +1,66 @@ +import ./make-test-python.nix ({ pkgs, lib, ...} : + +let + addrShared = "192.168.0.1"; + addrHostA = "192.168.0.10"; + addrHostB = "192.168.0.11"; + + mkUcarpHost = addr: { config, pkgs, lib, ... }: { + networking.interfaces.eth1.ipv4.addresses = lib.mkForce [ + { address = addr; prefixLength = 24; } + ]; + + networking.ucarp = { + enable = true; + interface = "eth1"; + srcIp = addr; + vhId = 1; + passwordFile = "${pkgs.writeText "ucarp-pass" "secure"}"; + addr = addrShared; + upscript = pkgs.writeScript "upscript" '' + #!/bin/sh + ${pkgs.iproute2}/bin/ip addr add "$2"/24 dev "$1" + ''; + downscript = pkgs.writeScript "downscript" '' + #!/bin/sh + ${pkgs.iproute2}/bin/ip addr del "$2"/24 dev "$1" + ''; + }; + }; +in { + name = "ucarp"; + meta.maintainers = with lib.maintainers; [ oxzi ]; + + nodes = { + hostA = mkUcarpHost addrHostA; + hostB = mkUcarpHost addrHostB; + }; + + testScript = '' + def is_master(host): + ipOutput = host.succeed("ip addr show dev eth1") + return "inet ${addrShared}/24" in ipOutput + + + start_all() + + # First, let both hosts start and let a master node be selected + for host, peer in [(hostA, "${addrHostB}"), (hostB, "${addrHostA}")]: + host.wait_for_unit("ucarp.service") + host.succeed(f"ping -c 1 {peer}") + + hostA.sleep(5) + + hostA_master, hostB_master = is_master(hostA), is_master(hostB) + assert hostA_master != hostB_master, "only one master node is allowed" + + master_host = hostA if hostA_master else hostB + backup_host = hostB if hostA_master else hostA + + # Let's crash the master host and let the backup take over + master_host.crash() + + backup_host.sleep(5) + assert is_master(backup_host), "backup did not take over" + ''; +}) |