From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6E2355A026F for ; Tue, 27 Jun 2023 04:54:46 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Qqq7K0mnhz4wqt; Tue, 27 Jun 2023 12:54:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1687834477; bh=nlD02FyZbb8ZN4L89ZHLJGdw6TBm9nvw0LxoDipYr2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VwD1lSJw0VYCqRbfc7SnxYvTwMGu4+yj2bd6TFRQb9+PT6GHH3cNTHPTw/CCSKYVk pO9NlTQ2/FGS8b2v3EeWqXyCebnFz6P714YhXOeMWJYdYX+0pFEZ7uf+KMeEnQ1S5S Le6nSJapQZo4XcmRO3MIyy079xdAa4kSb1WHl5Ks= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 20/27] tasst: Add helpers for getting a site's routes Date: Tue, 27 Jun 2023 12:54:21 +1000 Message-ID: <20230627025429.2209702-21-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230627025429.2209702-1-david@gibson.dropbear.id.au> References: <20230627025429.2209702-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 4KUBC3SV2E3GCEP3CGDAMBC3FQIHBTMC X-Message-ID-Hash: 4KUBC3SV2E3GCEP3CGDAMBC3FQIHBTMC X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: crosa@redhat.com, jarichte@redhat.com, David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: David Gibson --- 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