Commit ba8aec28 authored by Ondřej Zajíček's avatar Ondřej Zajíček

Tests: Minor cleanups

Add 'table' argument to more functions to make it work.
Rename 'ip' argument to 'family', to be consistent with ip tools doc.
Switch default of 'loc' argument to be more meaningful.
Replace "temp" constant with existing cf.tempdir.
Move 'table' keyword of get_stdout_bird from callee to caller.
Remove 'pref' from ip-route output, as it is reported by some versions of ip tools.
parent d6d18d3e
#!/bin/sh
. tests/strip_output
cd $1 && ./birdc -l show route table $2 \
cd $1 && ./birdc -l show route $2 \
| strip_version \
| strip_timestamp \
| strip_addresses \
......
......@@ -5,5 +5,6 @@ if [ $1 = "IPv4" ]; then variant=4; fi
if [ $1 = "IPv6" ]; then variant=6; fi
ip "-$variant" route show $2 \
| strip_interfaces_dev \
| strip_addresses
\ No newline at end of file
| strip_addresses \
| strip_interfaces_via \
| strip_nexthop_pref
......@@ -6,30 +6,25 @@ import subprocess
import tests.config as cf
def test_krt_routes(key: str, dev: str, ip: str) -> None:
def test_krt_routes(key: str, dev: str, family: str, table: str = "main") -> None:
if cf.save:
save_krt_routes(key, dev, ip, cf.datadir)
save_krt_routes(key, dev, family, table)
else:
check_krt_routes_timeout(key, dev, ip)
check_krt_routes_timeout(key, dev, family, table)
def save_krt_routes(
key: str, dev: str, ip: str, loc: str = "temp", table: str = "main"
) -> None:
os.system(
f"""\
def save_krt_routes(key: str, dev: str, family: str, table: str, loc: str = cf.datadir) -> None:
os.system(f""" \
ip netns exec {dev} \
./tests/get_stdout_krt '{ip}'\
'table {table}' > \
{loc}/{key}-{dev}
"""
)
./tests/get_stdout_krt '{family}' 'table {table}' \
> {loc}/{key}-{dev} \
""")
def check_krt_routes_timeout(key: str, dev: str, ip: str) -> None:
def check_krt_routes_timeout(key: str, dev: str, family: str, table: str) -> None:
timeout = 60
for sec in range(timeout):
if check_krt_routes(key, dev, ip):
if check_krt_routes(key, dev, family, table):
assert 1
elif sec == timeout - 1:
assert 0
......@@ -37,9 +32,9 @@ def check_krt_routes_timeout(key: str, dev: str, ip: str) -> None:
time.sleep(1)
def check_krt_routes(key: str, dev: str, ip: str) -> None:
save_krt_routes(key, dev, ip)
current_table = read_file(f"temp/{key}-{dev}")
def check_krt_routes(key: str, dev: str, family: str, table: str) -> None:
save_krt_routes(key, dev, family, table, cf.tempdir)
current_table = read_file(f"{cf.tempdir}/{key}-{dev}")
saved_table = read_file(f"{cf.datadir}/{key}-{dev}")
for _ in current_table:
......@@ -48,18 +43,16 @@ def check_krt_routes(key: str, dev: str, ip: str) -> None:
def test_bird_routes(key: str, dev: str, table: str) -> None:
if cf.save:
save_bird_routes(key, dev, table, cf.datadir)
save_bird_routes(key, dev, table)
else:
check_bird_routes_timeout(key, dev, table)
def save_bird_routes(key: str, dev: str, table: str, loc: str = "temp") -> None:
os.system(
f"""\
./tests/get_stdout_bird '{dev}' \
{table} > {loc}/{key}-{dev}
"""
)
def save_bird_routes(key: str, dev: str, table: str, loc: str = cf.datadir) -> None:
os.system(f""" \
./tests/get_stdout_bird '{dev}' 'table {table}' \
> {loc}/{key}-{dev} \
""")
def check_bird_routes_timeout(key: str, dev: str, table: str) -> None:
......@@ -74,8 +67,8 @@ def check_bird_routes_timeout(key: str, dev: str, table: str) -> None:
def check_bird_routes(key: str, dev: str, table: str) -> None:
save_bird_routes(key, dev, table)
current_table = read_file(f"temp/{key}-{dev}")
save_bird_routes(key, dev, table, cf.tempdir)
current_table = read_file(f"{cf.tempdir}/{key}-{dev}")
saved_table = read_file(f"{cf.datadir}/{key}-{dev}")
for _ in current_table:
......
......@@ -14,11 +14,16 @@ strip_addresses() {
}
strip_interfaces_on() {
# remove the cast link-local addresses
# remove the name of interfaces for link-local nexthops, after 'on'
sed -E "s/(fe80::<removed> on) [[:alnum:]]*/\1 <removed>/"
}
strip_interfaces_dev() {
# remove the name of interfaces
sed -E "s/(nexthop via fe80::.* dev) [[:alnum:]]* /\1 <removed> /"
strip_interfaces_via() {
# remove the name of interfaces for link-local nexthops, after 'via'
sed -E "s/(nexthop via fe80::.* dev) [[:alnum:]]*/\1 <removed>/"
}
strip_nexthop_pref() {
# remove 'pref' value for ECMP nexthops reported in some version of ip/kernel
sed -E "s/(nexthop via .*) pref [[:alnum:]]*/\1 /"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment