platform/tests: fix bug in netns test which can cause mounting tmpfs over /run
authorThomas Haller <thaller@redhat.com>
Thu, 24 Mar 2016 16:05:39 +0000 (17:05 +0100)
committerThomas Haller <thaller@redhat.com>
Thu, 24 Mar 2016 16:49:15 +0000 (17:49 +0100)
The root-test "/general/netns/bind-to-path" mounts a tmpfs
over /var/run for the duration of the test and unmounts it at
the end.

Due to a bug, we first mount the tmpfs, then switch to another
namespace, and finally unmount /var/run on that other namespace.

That means, when you run the tests as root, it will bork /run
on your system.

Fixes: 46f5c07643e6cbf920a44bebe9ac9d3435a5a7b6

src/platform/tests/test-link.c

index 69627c4..94695ed 100644 (file)
@@ -2257,9 +2257,6 @@ test_netns_bind_to_path (gpointer fixture, gconstpointer test_data)
        if (_test_netns_check_skip ())
                return;
 
-       g_assert_cmpint (mount ("tmpfs", P_VAR_RUN, "tmpfs", MS_NOATIME | MS_NODEV | MS_NOSUID, "mode=0755,size=32K"), ==, 0);
-       g_assert_cmpint (mkdir (P_VAR_RUN_NETNS, 755), ==, 0);
-
        platforms[0] = platform_0 = g_object_new (NM_TYPE_LINUX_PLATFORM, NM_PLATFORM_NETNS_SUPPORT, TRUE, NULL);
        platforms[1] = platform_1 = _test_netns_create_platform ();
        platforms[2] = platform_2 = _test_netns_create_platform ();
@@ -2268,6 +2265,9 @@ test_netns_bind_to_path (gpointer fixture, gconstpointer test_data)
        if (i != 3)
                g_assert (nm_platform_netns_push (platforms[i], &netns_pop));
 
+       g_assert_cmpint (mount ("tmpfs", P_VAR_RUN, "tmpfs", MS_NOATIME | MS_NODEV | MS_NOSUID, "mode=0755,size=32K"), ==, 0);
+       g_assert_cmpint (mkdir (P_VAR_RUN_NETNS, 755), ==, 0);
+
        i = (nmtst_get_rand_int () % 2) + 1;
        netns = nm_platform_netns_get (platforms[i]);