From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: Cleber Rosa <crosa@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v3 10/15] tasst/veth: Helpers for constructing veth devices between namespaces
Date: Mon, 26 Aug 2024 12:09:37 +1000 [thread overview]
Message-ID: <20240826020942.545155-11-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240826020942.545155-1-david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
test/tasst/__main__.py | 1 +
test/tasst/veth.py | 80 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100644 test/tasst/veth.py
diff --git a/test/tasst/__main__.py b/test/tasst/__main__.py
index e7456e8b..4eab9157 100644
--- a/test/tasst/__main__.py
+++ b/test/tasst/__main__.py
@@ -19,6 +19,7 @@ MODULES = [
'cmdsite',
'ip',
'unshare',
+ 'veth',
]
diff --git a/test/tasst/veth.py b/test/tasst/veth.py
new file mode 100644
index 00000000..7fa5cbb5
--- /dev/null
+++ b/test/tasst/veth.py
@@ -0,0 +1,80 @@
+#! /usr/bin/env python3
+
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright Red Hat
+# Author: David Gibson <david@gibson.dropbear.id.au>
+
+"""
+Test A Simple Socket Transport
+
+selftest/veth.py - Test various veth configurations
+"""
+
+import contextlib
+from typing import Iterator, Literal
+import ipaddress
+
+import exeter
+
+from . import cmdsite, ip, unshare
+
+
+@contextlib.contextmanager
+def veth(site: cmdsite.CmdSite, ifname: str,
+ peername: str, peer: unshare.Unshare | None = None) -> Iterator[None]:
+ site.fg('ip', 'link', 'add', ifname, 'type', 'veth',
+ 'peer', 'name', peername, privilege=True)
+ if peer is not None:
+ site.fg('ip', 'link', 'set', peername,
+ 'netns', f'{peer.relative_pid(site)}', privilege=True)
+ yield
+ site.fg('ip', 'link', 'del', ifname, privilege=True)
+
+
+def selftests() -> None:
+ @contextlib.contextmanager
+ def veth_setup() -> Iterator[tuple[cmdsite.CmdSite, cmdsite.CmdSite]]:
+ with unshare.unshare('ns1', '-Un') as ns1:
+ with unshare.unshare('ns2', '-n', parent=ns1,
+ privilege=True) as ns2:
+ with veth(ns1, 'vetha', 'vethb', ns2):
+ yield (ns1, ns2)
+
+ @exeter.test
+ def test_ifs() -> None:
+ with veth_setup() as (ns1, ns2):
+ exeter.assert_eq(set(ip.ifs(ns1)), set(['lo', 'vetha']))
+ exeter.assert_eq(set(ip.ifs(ns2)), set(['lo', 'vethb']))
+
+ @exeter.test
+ def test_mtu() -> None:
+ with veth_setup() as (ns1, ns2):
+ exeter.assert_eq(ip.mtu(ns1, 'vetha'), 1500)
+ exeter.assert_eq(ip.mtu(ns2, 'vethb'), 1500)
+
+ def test_slaac(dad: Literal['disable', 'optimistic', None]) -> None:
+ TESTMAC = '02:aa:bb:cc:dd:ee'
+ TESTIP = ipaddress.ip_interface('fe80::aa:bbff:fecc:ddee/64')
+
+ with veth_setup() as (ns1, ns2):
+ ns1.fg('ip', 'link', 'set', 'dev', 'vetha', 'address', TESTMAC,
+ privilege=True)
+
+ ip.ifup(ns1, 'vetha', dad=dad)
+ ip.ifup(ns2, 'vethb')
+
+ addrs = ip.addr_wait(ns1, 'vetha', family='inet6', scope='link')
+ exeter.assert_eq(addrs, [TESTIP])
+
+ @exeter.test
+ def test_dad() -> None:
+ test_slaac(dad=None)
+
+ @exeter.test
+ def test_optimistic_dad() -> None:
+ test_slaac(dad='optimistic')
+
+ @exeter.test
+ def test_no_dad() -> None:
+ test_slaac(dad='disable')
--
@@ -0,0 +1,80 @@
+#! /usr/bin/env python3
+
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright Red Hat
+# Author: David Gibson <david@gibson.dropbear.id.au>
+
+"""
+Test A Simple Socket Transport
+
+selftest/veth.py - Test various veth configurations
+"""
+
+import contextlib
+from typing import Iterator, Literal
+import ipaddress
+
+import exeter
+
+from . import cmdsite, ip, unshare
+
+
+@contextlib.contextmanager
+def veth(site: cmdsite.CmdSite, ifname: str,
+ peername: str, peer: unshare.Unshare | None = None) -> Iterator[None]:
+ site.fg('ip', 'link', 'add', ifname, 'type', 'veth',
+ 'peer', 'name', peername, privilege=True)
+ if peer is not None:
+ site.fg('ip', 'link', 'set', peername,
+ 'netns', f'{peer.relative_pid(site)}', privilege=True)
+ yield
+ site.fg('ip', 'link', 'del', ifname, privilege=True)
+
+
+def selftests() -> None:
+ @contextlib.contextmanager
+ def veth_setup() -> Iterator[tuple[cmdsite.CmdSite, cmdsite.CmdSite]]:
+ with unshare.unshare('ns1', '-Un') as ns1:
+ with unshare.unshare('ns2', '-n', parent=ns1,
+ privilege=True) as ns2:
+ with veth(ns1, 'vetha', 'vethb', ns2):
+ yield (ns1, ns2)
+
+ @exeter.test
+ def test_ifs() -> None:
+ with veth_setup() as (ns1, ns2):
+ exeter.assert_eq(set(ip.ifs(ns1)), set(['lo', 'vetha']))
+ exeter.assert_eq(set(ip.ifs(ns2)), set(['lo', 'vethb']))
+
+ @exeter.test
+ def test_mtu() -> None:
+ with veth_setup() as (ns1, ns2):
+ exeter.assert_eq(ip.mtu(ns1, 'vetha'), 1500)
+ exeter.assert_eq(ip.mtu(ns2, 'vethb'), 1500)
+
+ def test_slaac(dad: Literal['disable', 'optimistic', None]) -> None:
+ TESTMAC = '02:aa:bb:cc:dd:ee'
+ TESTIP = ipaddress.ip_interface('fe80::aa:bbff:fecc:ddee/64')
+
+ with veth_setup() as (ns1, ns2):
+ ns1.fg('ip', 'link', 'set', 'dev', 'vetha', 'address', TESTMAC,
+ privilege=True)
+
+ ip.ifup(ns1, 'vetha', dad=dad)
+ ip.ifup(ns2, 'vethb')
+
+ addrs = ip.addr_wait(ns1, 'vetha', family='inet6', scope='link')
+ exeter.assert_eq(addrs, [TESTIP])
+
+ @exeter.test
+ def test_dad() -> None:
+ test_slaac(dad=None)
+
+ @exeter.test
+ def test_optimistic_dad() -> None:
+ test_slaac(dad='optimistic')
+
+ @exeter.test
+ def test_no_dad() -> None:
+ test_slaac(dad='disable')
--
2.46.0
next prev parent reply other threads:[~2024-08-26 2:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 2:09 [PATCH v3 00/15] RFC: Proof-of-concept based exeter+Avocado tests David Gibson
2024-08-26 2:09 ` [PATCH v3 01/15] test: run static checkers with Avocado and JSON definitions David Gibson
2024-08-26 2:09 ` [PATCH v3 02/15] test: Adjust how we invoke tests with run_avocado David Gibson
2024-08-26 2:09 ` [PATCH v3 03/15] test: Extend make targets to run Avocado tests David Gibson
2024-08-26 2:09 ` [PATCH v3 04/15] test: Exeter based static tests David Gibson
2024-08-26 2:09 ` [PATCH v3 05/15] tasst: Support library and linters for tests in Python David Gibson
2024-08-26 2:09 ` [PATCH v3 06/15] tasst/cmdsite: Base helpers for running shell commands in various places David Gibson
2024-08-26 2:09 ` [PATCH v3 07/15] test: Add exeter+Avocado based build tests David Gibson
2024-08-26 2:09 ` [PATCH v3 08/15] tasst/unshare: Add helpers to run commands in Linux unshared namespaces David Gibson
2024-08-26 2:09 ` [PATCH v3 09/15] tasst/ip: Helpers for configuring IPv4 and IPv6 David Gibson
2024-08-26 2:09 ` David Gibson [this message]
2024-08-26 2:09 ` [PATCH v3 11/15] tasst: Helpers to test transferring data between sites David Gibson
2024-08-26 2:09 ` [PATCH v3 12/15] tasst: Helpers for testing NDP behaviour David Gibson
2024-08-26 2:09 ` [PATCH v3 13/15] tasst: Helpers for testing DHCP & DHCPv6 behaviour David Gibson
2024-08-26 2:09 ` [PATCH v3 14/15] tasst: Helpers to construct a simple network environment for tests David Gibson
2024-08-26 2:09 ` [PATCH v3 15/15] avocado: Convert basic pasta tests David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240826020942.545155-11-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=crosa@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).