Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/tasst/exesite.py | 13 +++++++++++++ test/tasst/meta/static_ifup.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/test/tasst/exesite.py b/test/tasst/exesite.py index 423fccbd..1f34eee9 100644 --- a/test/tasst/exesite.py +++ b/test/tasst/exesite.py @@ -149,6 +149,19 @@ class Site(contextlib.AbstractContextManager): if addrs: return addrs + def _routes(self, ipv, **criteria): + routes = json.loads(self.output(f'ip -j -{ipv} route')) + for key, value in criteria.items(): + routes = [r for r in routes if key in r and r[key] == value] + + return routes + + def routes4(self, **criteria): + return self._routes('4', **criteria) + + def routes6(self, **criteria): + return self._routes('6', **criteria) + def test_site(sitefn): def test_true(s): diff --git a/test/tasst/meta/static_ifup.py b/test/tasst/meta/static_ifup.py index 0896c747..f5fcc14f 100644 --- a/test/tasst/meta/static_ifup.py +++ b/test/tasst/meta/static_ifup.py @@ -38,3 +38,23 @@ def setup_ns(): def test_addr(): with setup_ns() as ns: assert_eq_unordered(ns.addrs(IFNAME, scope='global'), TEST_IPS) + + +@test +def test_routes4(): + with setup_ns() as ns: + expected_routes = [i.network for i in TEST_IPS + if isinstance(i, ipaddress.IPv4Interface)] + actual_routes = [ipaddress.ip_interface(r['dst']).network + for r in ns.routes4(dev=IFNAME)] + assert_eq_unordered(expected_routes, actual_routes) + + +@test +def test_routes6(): + with setup_ns() as ns: + expected_routes = [i.network for i in TEST_IPS + if isinstance(i, ipaddress.IPv6Interface)] + actual_routes = [ipaddress.ip_interface(r['dst']).network + for r in ns.routes6(dev=IFNAME)] + assert_eq_unordered(expected_routes, actual_routes) -- 2.41.0