From aadfcc0900bb15dfda4b64ab3ffe768551f65d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 22 Dec 2019 07:45:31 +0000 Subject: [PATCH] nixos/keepalived: add test --- nixos/tests/all-tests.nix | 1 + nixos/tests/keepalived.nix | 42 ++++++++++++++++++++ pkgs/tools/networking/keepalived/default.nix | 4 +- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/keepalived.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 6413895c4c5..bcb1d1a47c2 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -132,6 +132,7 @@ in jellyfin = handleTest ./jellyfin.nix {}; jenkins = handleTest ./jenkins.nix {}; kafka = handleTest ./kafka.nix {}; + keepalived = handleTest ./keepalived.nix {}; kerberos = handleTest ./kerberos/default.nix {}; kernel-latest = handleTest ./kernel-latest.nix {}; kernel-lts = handleTest ./kernel-lts.nix {}; diff --git a/nixos/tests/keepalived.nix b/nixos/tests/keepalived.nix new file mode 100644 index 00000000000..d0bf9d46520 --- /dev/null +++ b/nixos/tests/keepalived.nix @@ -0,0 +1,42 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "keepalived"; + + nodes = { + node1 = { pkgs, ... }: { + networking.firewall.extraCommands = "iptables -A INPUT -p vrrp -j ACCEPT"; + services.keepalived.enable = true; + services.keepalived.vrrpInstances.test = { + interface = "eth1"; + state = "MASTER"; + priority = 50; + virtualIps = [{ addr = "192.168.1.200"; }]; + virtualRouterId = 1; + }; + environment.systemPackages = [ pkgs.tcpdump ]; + }; + node2 = { pkgs, ... }: { + networking.firewall.extraCommands = "iptables -A INPUT -p vrrp -j ACCEPT"; + services.keepalived.enable = true; + services.keepalived.vrrpInstances.test = { + interface = "eth1"; + state = "MASTER"; + priority = 100; + virtualIps = [{ addr = "192.168.1.200"; }]; + virtualRouterId = 1; + }; + environment.systemPackages = [ pkgs.tcpdump ]; + }; + }; + + testScript = '' + # wait for boot time delay to pass + for node in [node1, node2]: + node.wait_until_succeeds( + "systemctl show -p LastTriggerUSecMonotonic keepalived-boot-delay.timer | grep -vq 'LastTriggerUSecMonotonic=0'" + ) + node.wait_for_unit("keepalived") + node2.wait_until_succeeds("ip addr show dev eth1 | grep -q 192.168.1.200") + node1.fail("ip addr show dev eth1 | grep -q 192.168.1.200") + node1.succeed("ping -c1 192.168.1.200") + ''; +}) diff --git a/pkgs/tools/networking/keepalived/default.nix b/pkgs/tools/networking/keepalived/default.nix index 142e2e79bbf..87748211425 100644 --- a/pkgs/tools/networking/keepalived/default.nix +++ b/pkgs/tools/networking/keepalived/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitHub +{ stdenv, fetchFromGitHub, nixosTests , libnfnetlink, libnl, net-snmp, openssl , pkgconfig, autoreconfHook }: @@ -20,6 +20,8 @@ stdenv.mkDerivation rec { openssl ]; + passthru.tests.keepalived = nixosTests.keepalived; + nativeBuildInputs = [ pkgconfig autoreconfHook ]; configureFlags = [