Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- avocado/tasst/meta/static_ifup.py | 13 +++++++++++++ avocado/tasst/site.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/avocado/tasst/meta/static_ifup.py b/avocado/tasst/meta/static_ifup.py index eba8fef..ce6ecaf 100644 --- a/avocado/tasst/meta/static_ifup.py +++ b/avocado/tasst/meta/static_ifup.py @@ -44,3 +44,16 @@ class StaticNetTasst(Tasst): def test_addr(self): with self.setup_ns() as ns: self.assertCountEqual(ns.addrs(self.IFNAME, scope='global'), self.TEST_IPS) + + def _test_routes(self, class_): + expected_routes = [i.network for i in TEST_IPS + if isinstance(i, class_)] + actual_routes = [class_(r['dst']).network + for r in self.ns.routes(dev=self.IFNAME))] + self.assertCountEqual(expected_routes, actual_routes) + + def test_routes4(self): + self._test_routes(IPv4Interface) + + def test_routes6(self): + self._test_routes(IPv6Interface) diff --git a/avocado/tasst/site.py b/avocado/tasst/site.py index f064a22..f9cac86 100644 --- a/avocado/tasst/site.py +++ b/avocado/tasst/site.py @@ -104,6 +104,19 @@ class Site(contextlib.AbstractContextManager): if addrs: return addrs + def _routes(self, ipv, **filter): + routes = json.loads(self.output('ip -j -{} route'.format(ipv))) + for key, value in filter.items(): + routes = [r for r in routes if key in r and r[key] == value] + + return routes + + def routes4(self, **filter): + return self._routes('4', **filter) + + def routes6(self, **filter): + return self._routes('6', **filter) + class SiteTasst(Tasst): """ -- 2.40.1