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 8E63C5A028E for ; Tue, 16 May 2023 04:01:52 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QKzxd2GLkz4y0C; Tue, 16 May 2023 12:01:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1684202501; bh=PzV/yhLqN5bfLsa8y4yLbNe7kwJ2tTjdSzGWYeY2nP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gXJDBCPrd9WDZDGuT/FEp2Gh8XApXrY3n0qBaDEZnmquCM0OWHpc3mFS5imBVVtpu snIVNgNAeip6MqLPsu7GGylODS/uVzs+2v6qg5NWALCyJ1VZg7gUl47OykAjCrI48e tNlEarGPL4yqiqzwbrnYPMVcyUZRZjFOSKGAdP1E= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 12/21] avocado/tasst: Helper for creating veth devices between namespaces Date: Tue, 16 May 2023 12:01:26 +1000 Message-Id: <20230516020135.1901256-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516020135.1901256-1-david@gibson.dropbear.id.au> References: <20230516020135.1901256-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: KVLUP5TEZWVTFEVMKBCVMWLIO2RR7WSN X-Message-ID-Hash: KVLUP5TEZWVTFEVMKBCVMWLIO2RR7WSN 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: jarichte@redhat.com, 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 --- avocado/tasst/meta/__init__.py | 16 +++++++++++++ avocado/tasst/meta/veth.py | 43 ++++++++++++++++++++++++++++++++++ avocado/tasst/nstool.py | 10 ++++++++ 3 files changed, 69 insertions(+) create mode 100644 avocado/tasst/meta/__init__.py create mode 100644 avocado/tasst/meta/veth.py diff --git a/avocado/tasst/meta/__init__.py b/avocado/tasst/meta/__init__.py new file mode 100644 index 0000000..6582554 --- /dev/null +++ b/avocado/tasst/meta/__init__.py @@ -0,0 +1,16 @@ +#! /usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# tasst - Test A Simple Socket Transport +# library of test helpers for passt & pasta +# +# tasst/meta - Test pieces of the test infrastructure. +# +# Usually, tests for the test infrastructure should go next to the +# implementation of the thing being tested. Sometimes that's not +# possible (usually because it would cause a circular module +# dependency). In that case those tests can go here. +# +# Copyright Red Hat +# Author: David Gibson diff --git a/avocado/tasst/meta/veth.py b/avocado/tasst/meta/veth.py new file mode 100644 index 0000000..48ef88b --- /dev/null +++ b/avocado/tasst/meta/veth.py @@ -0,0 +1,43 @@ +#! /usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# tasst - Test A Simple Socket Transport +# library of test helpers for passt & pasta +# +# tasst/metatest/veth - Test the veth creation helper +# +# These test code from tasst.site, but require additional support from +# tasst.nstool. +# +# Copyright Red Hat +# Author: David Gibson + +import avocado + +from tasst import Tasst +from tasst.site import REAL_HOST +from tasst.nstool import UnshareSite + + +class VethTasst(Tasst): + """ + Test helpers for creating veths between namespaces + + :avocado: tags=meta + """ + def setUp(self): + super().setUp() + self.ns1 = UnshareSite(type(self).__name__ + '.1', '-Un') + self.ns2 = UnshareSite(type(self).__name__ + '.2', '-n', + parent=self.ns1, sudo=True) + self.ns1.veth('veth1', 'veth2', self.ns2) + + def tearDown(self): + self.ns2.close() + self.ns1.close() + super().tearDown() + + def test_ifs(self): + self.assertCountEqual(self.ns1.ifs(), ['lo', 'veth1']) + self.assertCountEqual(self.ns2.ifs(), ['lo', 'veth2']) diff --git a/avocado/tasst/nstool.py b/avocado/tasst/nstool.py index 5da2ffc..bfd7cf7 100644 --- a/avocado/tasst/nstool.py +++ b/avocado/tasst/nstool.py @@ -61,6 +61,16 @@ class NsToolSite(Site): def bg(self, cmd, sudo=False, **kwargs): return REAL_HOST.bg(self._nst_cmd(cmd, sudo), **kwargs) + def veth(self, ifname, peername, peer=None): + self.fg('ip link add {} type veth peer name {}'.format(ifname, peername), + sudo=True) + if peer is not None: + if not isinstance(peer, NsToolSite): + raise TypeError + self.fg('ip link set {} netns {}'.format(peername, + peer.relative_pid(self)), + sudo=True) + # Create path for temporary nstool Unix socket # -- 2.40.1