]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: skip test_exec_networknamespacepath if netns setup fails
authorNick Rosbrook <enr0n@ubuntu.com>
Tue, 9 Jan 2024 16:40:52 +0000 (11:40 -0500)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 10 Jan 2024 08:59:22 +0000 (08:59 +0000)
In some environments, such as a LXD container, the netns setup might
fail because ip netns exec fails trying to mount /sys:

 $ systemd-detect-virt
 lxc
 $ ip link add dummy-test-exec type dummy
 $ ip netns add test-execute-netns
 $ ip netns exec test-execute-netns ip link add dummy-test-ns type dummy
 mount of /sys failed: Operation not permitted

If this setup fails, test_exec_networknamespacepath will fail, so check
the exit codes for these setup calls and skip the test if necessary.

src/test/test-execute.c

index 6d51ad7b53e2374715fc7e2e912e8c2362ab1148..126ca14c66055a796ae4c05049a35edb872def1b 100644 (file)
@@ -39,6 +39,7 @@
 static char *user_runtime_unit_dir = NULL;
 static bool can_unshare;
 static bool have_net_dummy;
+static bool have_netns;
 static unsigned n_ran_tests = 0;
 
 STATIC_DESTRUCTOR_REGISTER(user_runtime_unit_dir, freep);
@@ -1111,6 +1112,9 @@ static void test_exec_networknamespacepath(Manager *m) {
         if (!have_net_dummy)
                 return (void)log_notice("Skipping %s, dummy network interface not available", __func__);
 
+        if (!have_netns)
+                return (void)log_notice("Skipping %s, network namespace not available", __func__);
+
         r = find_executable("ip", NULL);
         if (r < 0) {
                 log_notice_errno(r, "Skipping %s, could not find ip binary: %m", __func__);
@@ -1452,8 +1456,8 @@ static int intro(void) {
 
         if (have_net_dummy) {
                 /* Create a network namespace and a dummy interface in it for NetworkNamespacePath= */
-                (void) system("ip netns add test-execute-netns");
-                (void) system("ip netns exec test-execute-netns ip link add dummy-test-ns type dummy");
+                have_netns = system("ip netns add test-execute-netns") == 0;
+                have_netns = have_netns && system("ip netns exec test-execute-netns ip link add dummy-test-ns type dummy") == 0;
         }
 
         return EXIT_SUCCESS;