[v3] zdtm: cleanup zdtmtst and zdtmtst.defaultroot cgroups after finishing test

Submitted by Pavel Tikhomirov on Aug. 8, 2018, 9:50 a.m.

Details

Message ID 20180808095008.23858-1-ptikhomirov@virtuozzo.com
State Accepted
Series "zdtm: cleanup zdtmtst and zdtmtst.defaultroot cgroups after finishing test"
Headers show

Commit Message

Pavel Tikhomirov Aug. 8, 2018, 9:50 a.m.
After running criu test, docker on the node becomes unusable, as it is
confused by our leftover cgroups. Surely docker should be fixed to
ignore custom cgroups (https://github.com/moby/moby/issues/37601), but
we should not leave them after test also.

v2: rmdir the holder only if it exists, remove racy wait and remove
wrongly added cleanup method in class criu
v3: bring back missed semicolon

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 test/zdtm.py             | 11 +++++++++++
 test/zdtm_umount_cgroups | 16 ++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100755 test/zdtm_umount_cgroups

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index c0ea65b2e..dc7c6ebe4 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -569,6 +569,10 @@  flavors_codes = dict(zip(range(len(flavors)), sorted(flavors.keys())))
 			subprocess.check_call(["make", "-C", "zdtm/"])
 		subprocess.check_call(["flock", "zdtm_mount_cgroups.lock", "./zdtm_mount_cgroups"])
 
+	@staticmethod
+	def cleanup():
+		subprocess.check_call(["flock", "zdtm_mount_cgroups.lock", "./zdtm_umount_cgroups"])
+
 
 class inhfd_test:
 	def __init__(self, name, desc, flavor, freezer):
@@ -674,6 +678,10 @@  flavors_codes = dict(zip(range(len(flavors)), sorted(flavors.keys())))
 	def available():
 		pass
 
+	@staticmethod
+	def cleanup():
+		pass
+
 
 class groups_test(zdtm_test):
 	def __init__(self, name, desc, flavor, freezer):
@@ -2226,3 +2234,6 @@  criu.available()
 	tst.available()
 
 opts['action'](opts)
+
+for tst in test_classes.values():
+	tst.cleanup()
diff --git a/test/zdtm_umount_cgroups b/test/zdtm_umount_cgroups
new file mode 100755
index 000000000..75a8ea28f
--- /dev/null
+++ b/test/zdtm_umount_cgroups
@@ -0,0 +1,16 @@ 
+#!/bin/sh
+
+# Lets delete all test controllers after executing tests.
+
+cat /proc/self/cgroup | grep -q zdtmtst.defaultroot || exit 0
+
+tdir=`mktemp -d zdtm.XXXXXX`
+for i in "zdtmtst" "zdtmtst.defaultroot"; do
+	mount -t cgroup -o none,name=$i zdtm $tdir || { rmdir $tdir; exit 1; }
+	# remove a fake group if exists
+	if [ -d "$tdir/holder" ]; then
+		rmdir $tdir/holder || { umount -l $tdir && rmdir $tdir; exit 1; }
+	fi
+	umount -l $tdir || exit 1;
+done
+rmdir $tdir

Comments

Andrey Vagin Aug. 16, 2018, 10:49 p.m.
Applied, thanks!

On Wed, Aug 08, 2018 at 12:50:08PM +0300, Pavel Tikhomirov wrote:
> After running criu test, docker on the node becomes unusable, as it is
> confused by our leftover cgroups. Surely docker should be fixed to
> ignore custom cgroups (https://github.com/moby/moby/issues/37601), but
> we should not leave them after test also.
> 
> v2: rmdir the holder only if it exists, remove racy wait and remove
> wrongly added cleanup method in class criu
> v3: bring back missed semicolon
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> ---
>  test/zdtm.py             | 11 +++++++++++
>  test/zdtm_umount_cgroups | 16 ++++++++++++++++
>  2 files changed, 27 insertions(+)
>  create mode 100755 test/zdtm_umount_cgroups
> 
> diff --git a/test/zdtm.py b/test/zdtm.py
> index c0ea65b2e..dc7c6ebe4 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -569,6 +569,10 @@ flavors_codes = dict(zip(range(len(flavors)), sorted(flavors.keys())))
>  			subprocess.check_call(["make", "-C", "zdtm/"])
>  		subprocess.check_call(["flock", "zdtm_mount_cgroups.lock", "./zdtm_mount_cgroups"])
>  
> +	@staticmethod
> +	def cleanup():
> +		subprocess.check_call(["flock", "zdtm_mount_cgroups.lock", "./zdtm_umount_cgroups"])
> +
>  
>  class inhfd_test:
>  	def __init__(self, name, desc, flavor, freezer):
> @@ -674,6 +678,10 @@ flavors_codes = dict(zip(range(len(flavors)), sorted(flavors.keys())))
>  	def available():
>  		pass
>  
> +	@staticmethod
> +	def cleanup():
> +		pass
> +
>  
>  class groups_test(zdtm_test):
>  	def __init__(self, name, desc, flavor, freezer):
> @@ -2226,3 +2234,6 @@ criu.available()
>  	tst.available()
>  
>  opts['action'](opts)
> +
> +for tst in test_classes.values():
> +	tst.cleanup()
> diff --git a/test/zdtm_umount_cgroups b/test/zdtm_umount_cgroups
> new file mode 100755
> index 000000000..75a8ea28f
> --- /dev/null
> +++ b/test/zdtm_umount_cgroups
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +
> +# Lets delete all test controllers after executing tests.
> +
> +cat /proc/self/cgroup | grep -q zdtmtst.defaultroot || exit 0
> +
> +tdir=`mktemp -d zdtm.XXXXXX`
> +for i in "zdtmtst" "zdtmtst.defaultroot"; do
> +	mount -t cgroup -o none,name=$i zdtm $tdir || { rmdir $tdir; exit 1; }
> +	# remove a fake group if exists
> +	if [ -d "$tdir/holder" ]; then
> +		rmdir $tdir/holder || { umount -l $tdir && rmdir $tdir; exit 1; }
> +	fi
> +	umount -l $tdir || exit 1;
> +done
> +rmdir $tdir
> -- 
> 2.17.1
>