Merge pull request #178842 from Ma27/vrf-test-json
nixos/systemd-networkd-vrf: check routing tables via `ip --json`
This commit is contained in:
commit
cb009ecbc7
1 changed files with 32 additions and 18 deletions
|
@ -138,18 +138,18 @@ in {
|
|||
};
|
||||
|
||||
testScript = ''
|
||||
def compare_tables(expected, actual):
|
||||
assert (
|
||||
expected == actual
|
||||
), """
|
||||
Routing tables don't match!
|
||||
Expected:
|
||||
{}
|
||||
Actual:
|
||||
{}
|
||||
""".format(
|
||||
expected, actual
|
||||
)
|
||||
import json
|
||||
|
||||
def compare(raw_json, to_compare):
|
||||
data = json.loads(raw_json)
|
||||
assert len(raw_json) >= len(to_compare)
|
||||
for i, row in enumerate(to_compare):
|
||||
actual = data[i]
|
||||
assert len(row.keys()) > 0
|
||||
for key, value in row.items():
|
||||
assert value == actual[key], f"""
|
||||
In entry {i}, value {key}: got: {actual[key]}, expected {value}
|
||||
"""
|
||||
|
||||
|
||||
start_all()
|
||||
|
@ -178,14 +178,28 @@ in {
|
|||
# Check that networkd properly configures the main routing table
|
||||
# and the routing tables for the VRF.
|
||||
with subtest("check vrf routing tables"):
|
||||
compare_tables(
|
||||
client_ipv4_table, client.succeed("ip -4 route list | head -n2").strip()
|
||||
compare(
|
||||
client.succeed("ip --json -4 route list"),
|
||||
[
|
||||
{"dst": "192.168.1.2", "dev": "vrf1", "metric": 100},
|
||||
{"dst": "192.168.2.3", "dev": "vrf2", "metric": 100}
|
||||
]
|
||||
)
|
||||
compare_tables(
|
||||
vrf1_table, client.succeed("ip -4 route list table 23 | head -n4").strip()
|
||||
compare(
|
||||
client.succeed("ip --json -4 route list table 23"),
|
||||
[
|
||||
{"dst": "192.168.1.0/24", "dev": "eth1", "prefsrc": "192.168.1.1"},
|
||||
{"type": "local", "dst": "192.168.1.1", "dev": "eth1", "prefsrc": "192.168.1.1"},
|
||||
{"type": "broadcast", "dev": "eth1", "prefsrc": "192.168.1.1", "dst": "192.168.1.255"}
|
||||
]
|
||||
)
|
||||
compare_tables(
|
||||
vrf2_table, client.succeed("ip -4 route list table 42 | head -n4").strip()
|
||||
compare(
|
||||
client.succeed("ip --json -4 route list table 42"),
|
||||
[
|
||||
{"dst": "192.168.2.0/24", "dev": "eth2", "prefsrc": "192.168.2.1"},
|
||||
{"type": "local", "dst": "192.168.2.1", "dev": "eth2", "prefsrc": "192.168.2.1"},
|
||||
{"type": "broadcast", "dev": "eth2", "prefsrc": "192.168.2.1", "dst": "192.168.2.255"}
|
||||
]
|
||||
)
|
||||
|
||||
# Ensure that other nodes are reachable via ICMP through the VRF.
|
||||
|
|
Loading…
Reference in a new issue