at 23.05-pre 3.3 kB view raw
1# This test does a basic functionality check for all bird variants and demonstrates a use 2# of the preCheckConfig option. 3 4{ system ? builtins.currentSystem 5, pkgs ? import ../.. { inherit system; config = { }; } 6}: 7 8let 9 inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest; 10 inherit (pkgs.lib) optionalString; 11 12 makeBird2Host = hostId: { pkgs, ... }: { 13 virtualisation.vlans = [ 1 ]; 14 15 environment.systemPackages = with pkgs; [ jq ]; 16 17 networking = { 18 useNetworkd = true; 19 useDHCP = false; 20 firewall.enable = false; 21 }; 22 23 systemd.network.networks."01-eth1" = { 24 name = "eth1"; 25 networkConfig.Address = "10.0.0.${hostId}/24"; 26 }; 27 28 services.bird2 = { 29 enable = true; 30 31 config = '' 32 log syslog all; 33 34 debug protocols all; 35 36 router id 10.0.0.${hostId}; 37 38 protocol device { 39 } 40 41 protocol kernel kernel4 { 42 ipv4 { 43 import none; 44 export all; 45 }; 46 } 47 48 protocol static static4 { 49 ipv4; 50 include "static4.conf"; 51 } 52 53 protocol ospf v2 ospf4 { 54 ipv4 { 55 export all; 56 }; 57 area 0 { 58 interface "eth1" { 59 hello 5; 60 wait 5; 61 }; 62 }; 63 } 64 65 protocol kernel kernel6 { 66 ipv6 { 67 import none; 68 export all; 69 }; 70 } 71 72 protocol static static6 { 73 ipv6; 74 include "static6.conf"; 75 } 76 77 protocol ospf v3 ospf6 { 78 ipv6 { 79 export all; 80 }; 81 area 0 { 82 interface "eth1" { 83 hello 5; 84 wait 5; 85 }; 86 }; 87 } 88 ''; 89 90 preCheckConfig = '' 91 echo "route 1.2.3.4/32 blackhole;" > static4.conf 92 echo "route fd00::/128 blackhole;" > static6.conf 93 ''; 94 }; 95 96 systemd.tmpfiles.rules = [ 97 "f /etc/bird/static4.conf - - - - route 10.10.0.${hostId}/32 blackhole;" 98 "f /etc/bird/static6.conf - - - - route fdff::${hostId}/128 blackhole;" 99 ]; 100 }; 101in 102makeTest { 103 name = "bird2"; 104 105 nodes.host1 = makeBird2Host "1"; 106 nodes.host2 = makeBird2Host "2"; 107 108 testScript = '' 109 start_all() 110 111 host1.wait_for_unit("bird2.service") 112 host2.wait_for_unit("bird2.service") 113 host1.succeed("systemctl reload bird2.service") 114 115 with subtest("Waiting for advertised IPv4 routes"): 116 host1.wait_until_succeeds("ip --json r | jq -e 'map(select(.dst == \"10.10.0.2\")) | any'") 117 host2.wait_until_succeeds("ip --json r | jq -e 'map(select(.dst == \"10.10.0.1\")) | any'") 118 with subtest("Waiting for advertised IPv6 routes"): 119 host1.wait_until_succeeds("ip --json -6 r | jq -e 'map(select(.dst == \"fdff::2\")) | any'") 120 host2.wait_until_succeeds("ip --json -6 r | jq -e 'map(select(.dst == \"fdff::1\")) | any'") 121 122 with subtest("Check fake routes in preCheckConfig do not exists"): 123 host1.fail("ip --json r | jq -e 'map(select(.dst == \"1.2.3.4\")) | any'") 124 host2.fail("ip --json r | jq -e 'map(select(.dst == \"1.2.3.4\")) | any'") 125 126 host1.fail("ip --json -6 r | jq -e 'map(select(.dst == \"fd00::\")) | any'") 127 host2.fail("ip --json -6 r | jq -e 'map(select(.dst == \"fd00::\")) | any'") 128 ''; 129}