nixos/tests: add test for static routes

This commit is contained in:
rnhmjoj 2017-07-28 16:45:58 +02:00
parent d00c91c5da
commit f41111c4da
No known key found for this signature in database
GPG key ID: 91BE884FBA4B591A
3 changed files with 72 additions and 8 deletions

View file

@ -210,12 +210,13 @@ let
${flip concatMapStrings (i.ipv4Routes ++ i.ipv6Routes) (route:
let
cidr = "${route.address}/${toString route.prefixLength}";
nextHop = optionalString (route.nextHop != null) ''via "${route.nextHop}"'';
via = optionalString (route.via != null) ''via "${route.via}"'';
options = concatStrings (mapAttrsToList (name: val: "${name} ${val} ") route.options);
in
''
echo "${cidr}" >> $state
echo -n "adding route ${cidr}... "
if out=$(ip route add "${cidr}" ${route.options} ${nextHop} dev "${i.name}" 2>&1); then
if out=$(ip route add "${cidr}" ${options} ${via} dev "${i.name}" 2>&1); then
echo "done"
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
echo "failed"