From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 64F575A0320 for ; Mon, 05 Aug 2024 14:37:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1722861425; bh=HgctctUsNSzoUqB4RfcIqsqPviK+x6DQdEJeVeTqiGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aOIu4L2j5W+ro4umz7DfOYr1Qj/TI3oKNHCA7/eCRfaLRqOIxloYIRslmbEs7sWur 5In2SP3CLXGDrhI1UmF5RRZF90IgoBY/G67mUjO2ySu5f2BpVd+vgAYGMuQ0lRYDCr HnkjMcGvoV53IfUfw/IISycPHypeLlrm/09YA0qBeW6OFxMDRXYph6EDc6tYY6N6Mh AO9y4VSjQceIsCKG0tVxqCoODvfz04+1lkFM2DfUV1IgnXPSrSaRhVezHYuKyX5PnI CLaTgYgjh/NSn+XyUYa/uqOlLwvYTr6LopY+IhtqyPF312/5hMSm5PqkRCFiIRCvPS 04Vb4CrP2NBwg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WcwtT2nkNz4x87; Mon, 5 Aug 2024 22:37:05 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 16/22] tasst: Add helpers for getting a SimNetHost's routes Date: Mon, 5 Aug 2024 22:36:55 +1000 Message-ID: <20240805123701.1720730-17-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805123701.1720730-1-david@gibson.dropbear.id.au> References: <20240805123701.1720730-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 674W2SDJRI4Y4CAC4WIF7DBN2DL576HN X-Message-ID-Hash: 674W2SDJRI4Y4CAC4WIF7DBN2DL576HN 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: Cleber Rosa , 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/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) + + +@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) + + +@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