[CRIU] [PATCH 2/2] zdtm: Test --external veth option (v4)

Pavel Emelyanov xemul at virtuozzo.com
Wed Oct 26 01:52:21 PDT 2016


Inspired by Tycho's macvlan test, here's the same thing for
--external veth option. In master we still have the --veth-pair
one, but the plan is to move this all under the --external opt.

v2:
* Travis doesn't have /usr/bin/sed
* Added .checkskip hook for older environments

v3:
* Delete bridge hanging around after previous flavor
* Wait for host veth end to die after dump

v4:
* Get the pid of task to move veth into from .pid.inprogress file

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 test/zdtm.py                       |  1 +
 test/zdtm/.gitignore               |  1 +
 test/zdtm/static/Makefile          |  1 +
 test/zdtm/static/cr_veth.c         | 69 ++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/cr_veth.checkskip |  2 ++
 test/zdtm/static/cr_veth.desc      |  1 +
 test/zdtm/static/cr_veth.hook      | 36 ++++++++++++++++++++
 7 files changed, 111 insertions(+)
 create mode 100644 test/zdtm/static/cr_veth.c
 create mode 100755 test/zdtm/static/cr_veth.checkskip
 create mode 100644 test/zdtm/static/cr_veth.desc
 create mode 100755 test/zdtm/static/cr_veth.hook

diff --git a/test/zdtm.py b/test/zdtm.py
index 96eb73c..e032716 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -1010,6 +1010,7 @@ def cr(cr_api, test, opts):
 			sbs('pre-restore')
 			try_run_hook(test, ["--pre-restore"])
 			cr_api.restore()
+			try_run_hook(test, ["--post-restore"])
 			sbs('post-restore')
 
 		time.sleep(iters[1])
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index 920772b..5817013 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -10,3 +10,4 @@
 *.inprogress
 *.test
 *.test.*
+*.state
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index e2717a0..ec05b89 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -153,6 +153,7 @@ TST_NOFILE	:=				\
 		helper_zombie_child		\
 		clone_fs			\
 		macvlan			\
+		cr_veth				\
 #		jobctl00			\
 
 ifneq ($(SRCARCH),arm)
diff --git a/test/zdtm/static/cr_veth.c b/test/zdtm/static/cr_veth.c
new file mode 100644
index 0000000..deef735
--- /dev/null
+++ b/test/zdtm/static/cr_veth.c
@@ -0,0 +1,69 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <linux/limits.h>
+#include <signal.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include "zdtmtst.h"
+
+const char *test_doc	= "check that veth C/R-s right";
+const char *test_author	= "Pavel Emelyanov <xemul at virtuozzo.com>";
+
+#define IF_NAME "zdtmvthc0"
+
+static bool wait_for_veth(void)
+{
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		if (system("ip addr list dev " IF_NAME) == 0)
+			return true;
+
+		sleep(1);
+	}
+
+	return false;
+}
+
+int main(int argc, char **argv)
+{
+	int ret = 1;
+
+	test_init(argc, argv);
+
+	if (!wait_for_veth()) {
+		fail("failed to inject veth device\n");
+		return 1;
+	}
+
+	if (system("ip addr list dev " IF_NAME " | sed -e 's/@.*://' > cr_veth.dump.state")) {
+		fail("can't save net config");
+		goto out;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (system("ip addr list dev " IF_NAME " | sed -e 's/@.*://' > cr_veth.rst.state")) {
+		fail("can't get net config");
+		goto out;
+	}
+
+	if (system("diff cr_veth.rst.state cr_veth.dump.state")) {
+		fail("Net config differs after restore");
+		goto out;
+	}
+
+	pass();
+	ret = 0;
+
+out:
+	return ret;
+}
diff --git a/test/zdtm/static/cr_veth.checkskip b/test/zdtm/static/cr_veth.checkskip
new file mode 100755
index 0000000..2995e0c
--- /dev/null
+++ b/test/zdtm/static/cr_veth.checkskip
@@ -0,0 +1,2 @@
+#!/bin/bash
+unshare --net ip link add type veth
diff --git a/test/zdtm/static/cr_veth.desc b/test/zdtm/static/cr_veth.desc
new file mode 100644
index 0000000..407a7a8
--- /dev/null
+++ b/test/zdtm/static/cr_veth.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'deps': [ '/bin/sh', '/bin/sed', '/bin/grep', '/sbin/ip', '/usr/bin/diff'], 'flags': 'suid', 'ropts': '--external veth[zdtmvthc0]:zdtmvthh0 at zdtmbr0'}
diff --git a/test/zdtm/static/cr_veth.hook b/test/zdtm/static/cr_veth.hook
new file mode 100755
index 0000000..c7afd3e
--- /dev/null
+++ b/test/zdtm/static/cr_veth.hook
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+if [ "$1" == "--post-start" ]; then
+	set -e
+
+	PIDF="zdtm/static/cr_veth.pid.inprogress"
+	while [ ! -f "$PIDF" ]; do
+		sleep ".1"
+	done
+
+	TPID=$(cat $PIDF)
+	ps xaf
+	echo "-> $TPID"
+
+	ip link add zdtmvthc0 type veth peer name zdtmvthh0
+	ip link set zdtmvthc0 netns $TPID
+
+	ip link del zdtmbr0 || true # Ignore the failure
+	ip link add zdtmbr0 type bridge
+	ip link set zdtmbr0 up
+	ip link set zdtmvthh0 master zdtmbr0
+elif [ "$1" == "--post-restore" ]; then
+	ip link list zdtmvthh0
+
+	if ! ip link list zdtmvthh0 | fgrep -q 'master zdtmbr0'; then
+		echo "Device missing or not in bridge"
+		exit 1
+	fi
+
+	echo "Device OK"
+elif [ "$1" == "--pre-restore" ]; then
+	# Wait for the link to die
+	while ip l l zdtmvthh0 ; do
+		true
+	done
+fi
-- 
2.5.0



More information about the CRIU mailing list