]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test/test-execute: skip PrivateNetwork tests if kernel has no dummy netdevice support 29407/head
authorMax Kellermann <max.kellermann@ionos.com>
Mon, 2 Oct 2023 12:24:56 +0000 (14:24 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Mon, 2 Oct 2023 13:32:04 +0000 (15:32 +0200)
src/test/test-execute.c

index 68796ce1ac2b544104508fa0b0fb0d67aee7c929..417e484fc985e99616b79ebfa0b6c47f0be81e49 100644 (file)
@@ -38,6 +38,7 @@
 
 static char *user_runtime_unit_dir = NULL;
 static bool can_unshare;
+static bool have_net_dummy;
 static unsigned n_ran_tests = 0;
 
 STATIC_DESTRUCTOR_REGISTER(user_runtime_unit_dir, freep);
@@ -1074,6 +1075,9 @@ static void test_exec_ambientcapabilities(Manager *m) {
 static void test_exec_privatenetwork(Manager *m) {
         int r;
 
+        if (!have_net_dummy)
+                return (void)log_notice("Skipping %s, dummy network interface not available", __func__);
+
         r = find_executable("ip", NULL);
         if (r < 0) {
                 log_notice_errno(r, "Skipping %s, could not find ip binary: %m", __func__);
@@ -1087,6 +1091,9 @@ static void test_exec_privatenetwork(Manager *m) {
 static void test_exec_networknamespacepath(Manager *m) {
         int r;
 
+        if (!have_net_dummy)
+                return (void)log_notice("Skipping %s, dummy network interface not available", __func__);
+
         r = find_executable("ip", NULL);
         if (r < 0) {
                 log_notice_errno(r, "Skipping %s, could not find ip binary: %m", __func__);
@@ -1424,18 +1431,23 @@ static int intro(void) {
                 return log_tests_skipped("/sys is mounted read-only");
 
         /* Create dummy network interface for testing PrivateNetwork=yes */
-        (void) system("ip link add dummy-test-exec type dummy");
+        have_net_dummy = system("ip link add dummy-test-exec type dummy") == 0;
 
-        /* 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");
+        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");
+        }
 
         return EXIT_SUCCESS;
 }
 
 static int outro(void) {
-        (void) system("ip link del dummy-test-exec");
-        (void) system("ip netns del test-execute-netns");
+        if (have_net_dummy) {
+                (void) system("ip link del dummy-test-exec");
+                (void) system("ip netns del test-execute-netns");
+        }
+
         (void) rmdir(PRIVATE_UNIT_DIR);
 
         return EXIT_SUCCESS;