All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] tests: Run in separate network namespace, don't break connectivity
@ 2020-06-14 21:41 Stefano Brivio
  2020-06-14 22:03 ` Pablo Neira Ayuso
  2020-06-15 21:48 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 5+ messages in thread
From: Stefano Brivio @ 2020-06-14 21:41 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Phil Sutter, netfilter-devel

It might be convenient to run tests from a development branch that
resides on another host, and if we break connectivity on the test
host as tests are executed, we can't run them this way.

If kernel implementation (CONFIG_NET_NS), unshare(1), or Python
bindings for unshare() are not available, warn and continue.

Suggested-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tests/py/nft-test.py     | 6 ++++++
 tests/shell/run-tests.sh | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index 01ee6c980ad4..df97ed8eefb7 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -1394,6 +1394,12 @@ def main():
     # Change working directory to repository root
     os.chdir(TESTS_PATH + "/../..")
 
+    try:
+        import unshare
+        unshare.unshare(unshare.CLONE_NEWNET)
+    except:
+        print_warning("cannot run in own namespace, connectivity might break")
+
     check_lib_path = True
     if args.library is None:
         if args.host:
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index fcc87a8957c8..328c412e66f9 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -22,6 +22,15 @@ if [ "$(id -u)" != "0" ] ; then
 	msg_error "this requires root!"
 fi
 
+if [ "${1}" != "run" ]; then
+	if unshare -f -n true; then
+		unshare -n "${0}" run $@
+		exit $?
+	fi
+	msg_warn "cannot run in own namespace, connectivity might break"
+fi
+shift
+
 [ -z "$NFT" ] && NFT=$SRC_NFT
 ${NFT} > /dev/null 2>&1
 ret=$?
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-15 21:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-14 21:41 [PATCH nft] tests: Run in separate network namespace, don't break connectivity Stefano Brivio
2020-06-14 22:03 ` Pablo Neira Ayuso
2020-06-14 22:46   ` Stefano Brivio
2020-06-15 10:16   ` Phil Sutter
2020-06-15 21:48 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.