From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 42EBD5A026D for ; Wed, 31 May 2023 03:59:03 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QWC9S3k1Jz4x4r; Wed, 31 May 2023 11:58:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1685498332; bh=dCPjQIkCGdlK92ZO4X8TANpQPfOeawnvsoHgKLu9gFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6vEM50Enx59GO0l8SK7vilOY1/vTYJ6EwrmbNXITLL6lNRc9sK2EPTWm1RgFV7d+ +W9kiCtuuOPXLxw1S4pI/3sY5NdncmMOuifftNumq3GTbtMD6E9btN1WeHHYoSTFhJ 2DJGqq6L21PPLFp1S5HInfDACBs6vldHq4wAwLVg= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v3 14/20] avocado/tasst: Add helpers for getting a site's routes Date: Wed, 31 May 2023 11:58:43 +1000 Message-Id: <20230531015849.3229596-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531015849.3229596-1-david@gibson.dropbear.id.au> References: <20230531015849.3229596-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ZRJ63HEPJCRSIFYSA5PYTY6LWP7HSPZZ X-Message-ID-Hash: ZRJ63HEPJCRSIFYSA5PYTY6LWP7HSPZZ 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 , 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 --- 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