[CRIU] [PATCH] zdtm: Test --external veth option (v3)
Andrei Vagin
avagin at virtuozzo.com
Tue Oct 25 10:31:19 PDT 2016
On Mon, Oct 24, 2016 at 08:02:08PM +0300, Pavel Emelyanov wrote:
> 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
>
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
>
> ---
>
>
> commit dc27cf8a1c87ef09ea64a9d4a34692d9b05a498e
> Author: Pavel Emelyanov <xemul at virtuozzo.com>
> Date: Sat Oct 22 00:14:31 2016 +0300
>
> --external veth test
>
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
>
> 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..15b6672
> --- /dev/null
> +++ b/test/zdtm/static/cr_veth.hook
> @@ -0,0 +1,37 @@
> +#!/bin/bash
> +
> +if [ "$1" == "--post-start" ]; then
> + set -e
> +
> + i=0
> + while [ -z "$(pidof -s cr_veth)" ]; do
Here is a few test processes and minimum one of them lives in
the host namespaces.
> + i=$(($i+1))
> + if [ "$i" -eq "10" ]; then
> + echo "failed to create veth test"
> + exit 1
> + fi
> + sleep 1
> + done
> +
> + ip link add zdtmvthc0 type veth peer name zdtmvthh0
> + ip link set zdtmvthc0 netns $(pidof -s cr_veth)
> +
> + 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
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list