Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/tasst/selftest/static_ifup.py | 20 ++++++++++++++++++++ test/tasst/snh.py | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/test/tasst/selftest/static_ifup.py b/test/tasst/selftest/static_ifup.py index 0c6375d4..2627b579 100644 --- a/test/tasst/selftest/static_ifup.py +++ b/test/tasst/selftest/static_ifup.py @@ -38,3 +38,23 @@ def setup_ns(): def test_addr(): with setup_ns() as ns: exeter.assert_eq(set(ns.addrs(IFNAME, scope='global')), TEST_IPS) + + +(a)exeter.test +def test_routes4(): + with setup_ns() as ns: + expected_routes = set(i.network for i in TEST_IPS + if isinstance(i, ipaddress.IPv4Interface)) + actual_routes = set(ipaddress.ip_interface(r['dst']).network + for r in ns.routes4(dev=IFNAME)) + exeter.assert_eq(expected_routes, actual_routes) + + +(a)exeter.test +def test_routes6(): + with setup_ns() as ns: + expected_routes = set(i.network for i in TEST_IPS + if isinstance(i, ipaddress.IPv6Interface)) + actual_routes = set(ipaddress.ip_interface(r['dst']).network + for r in ns.routes6(dev=IFNAME)) + exeter.assert_eq(expected_routes, actual_routes) diff --git a/test/tasst/snh.py b/test/tasst/snh.py index a1225ff0..4ddcbb16 100644 --- a/test/tasst/snh.py +++ b/test/tasst/snh.py @@ -157,6 +157,19 @@ class SimNetHost(contextlib.AbstractContextManager): if addrs: return addrs + def _routes(self, ipv, **criteria): + routes = json.loads(self.output('ip', '-j', f'-{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) + # Internal tests def test_true(self): with self as snh: -- 2.45.2