1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

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.
This commit is contained in:
Nick Rosbrook 2024-01-09 11:40:52 -05:00 committed by Luca Boccassi
parent a795ec8100
commit 76808638b6

View 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;