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