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 A4AC65A027D for ; Tue, 27 Jun 2023 04:54:45 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Qqq7K0TGZz4wqn; 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=OITWkp/DRKonulrHxMHNHSM5Ln5Z0vwpcz7U0F8Zfnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k5hH6QIz53B9qS5hcB3rNJZdoPumGkWS2I+TW2nvIskR+4REzcx3uE9Cp5znE3n7H G7ChDbnQoTKEn31QI90eeWXadcorzZ+/d0YzykrW/koph01zf/WBE2pcvf8Eku6xCs jZbpmP1KfiwH/mGqUTLfV9ZLYmUMtilmILBOPZqE= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 17/27] tasst: Helper for creating veth devices between namespaces Date: Tue, 27 Jun 2023 12:54:18 +1000 Message-ID: <20230627025429.2209702-18-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: VC4TE3K2PTYDQ5P3FQERBCTUPKGX3VPR X-Message-ID-Hash: VC4TE3K2PTYDQ5P3FQERBCTUPKGX3VPR 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/meta/__init__.py | 16 ++++++++++++++++ test/tasst/meta/veth.py | 33 +++++++++++++++++++++++++++++++++ test/tasst/nstool.py | 9 +++++++++ 3 files changed, 58 insertions(+) create mode 100644 test/tasst/meta/__init__.py create mode 100644 test/tasst/meta/veth.py diff --git a/test/tasst/meta/__init__.py b/test/tasst/meta/__init__.py new file mode 100644 index 00000000..55039426 --- /dev/null +++ b/test/tasst/meta/__init__.py @@ -0,0 +1,16 @@ +#! /usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright Red Hat +# Author: David Gibson + +"""Test A Simple Socket Transport + +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 +inconvenient or impossible (usually because it would cause a circular +module dependency). In that case those tests can go here. +""" diff --git a/test/tasst/meta/veth.py b/test/tasst/meta/veth.py new file mode 100644 index 00000000..9cef6271 --- /dev/null +++ b/test/tasst/meta/veth.py @@ -0,0 +1,33 @@ +#! /usr/bin/env avocado-runner-avocado-classless + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright Red Hat +# Author: David Gibson + +""" +Test A Simple Socket Transport + +meta/veth.py - Test various veth configurations +""" + +import contextlib + +from avocado_classless.test import assert_eq_unordered, test + +from tasst.nstool import unshare_site + + +@contextlib.contextmanager +def unconfigured_veth(): + with unshare_site('ns1', '-Un') as ns1: + with unshare_site('ns2', '-n', parent=ns1, sudo=True) as ns2: + ns1.veth('veth1', 'veth2', ns2) + yield (ns1, ns2) + + +@test +def test_ifs(): + with unconfigured_veth() as (ns1, ns2): + assert_eq_unordered(ns1.ifs(), ['lo', 'veth1']) + assert_eq_unordered(ns2.ifs(), ['lo', 'veth2']) diff --git a/test/tasst/nstool.py b/test/tasst/nstool.py index 7fa46893..710c5ebd 100644 --- a/test/tasst/nstool.py +++ b/test/tasst/nstool.py @@ -66,6 +66,15 @@ class NsToolSite(Site): nst_args = '--keep-caps ' + nst_args return f'{NSTOOL_BIN} exec {nst_args} -- {cmd}', kwargs + def veth(self, ifname, peername, peer=None): + self.fg(f'ip link add {ifname} type veth peer name {peername}', + sudo=True) + if peer is not None: + if not isinstance(peer, NsToolSite): + raise TypeError + self.fg(f'ip link set {peername} netns {peer.relative_pid(self)}', + sudo=True) + @contextlib.contextmanager def unshare_site(nsname, unshare_opts, parent=REAL_HOST, sudo=False): -- 2.41.0