From: Nick Rosbrook Date: Tue, 9 Jan 2024 16:40:52 +0000 (-0500) Subject: test: skip test_exec_networknamespacepath if netns setup fails X-Git-Tag: v256-rc1~1217 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=76808638b6f1e7e257c3b09eccdb5a8cfe855f83;p=thirdparty%2Fsystemd.git test: skip test_exec_networknamespacepath if netns setup fails 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. --- diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 6d51ad7b53e..126ca14c660 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -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;