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 02d9650..3e4694b 100644 --- a/avocado/tasst/meta/static_ifup.py +++ b/avocado/tasst/meta/static_ifup.py @@ -45,3 +45,16 @@ class StaticNetTasst(Tasst): def test_addr(self): self.assertCountEqual(self.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 3197839..d9920d1 100644 --- a/avocado/tasst/site.py +++ b/avocado/tasst/site.py @@ -107,6 +107,19 @@ class Site: 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 BaseSiteTasst(Tasst): """ -- 2.40.1