]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: use virfirewallmock instead of hasNetfilterTools
authorPavel Hrdina <phrdina@redhat.com>
Wed, 14 Apr 2021 21:57:50 +0000 (23:57 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 21 Apr 2021 12:19:26 +0000 (14:19 +0200)
Instead of checking for specific error that the binaries are not
available mock the virFindFileInPath function. This way we don't have
to skip these tests on host where the binaries are missing.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tests/networkxml2firewalltest.c
tests/nwfilterebiptablestest.c
tests/nwfilterxml2firewalltest.c
tests/virfirewalltest.c

index 80ba510d14e2ff2f73783d63be8d31366098ccc0..91336a0c55c562312aecca11407a273c490ca4e6 100644 (file)
@@ -152,14 +152,6 @@ testCompareXMLToIPTablesHelper(const void *data)
     return result;
 }
 
-static bool
-hasNetfilterTools(void)
-{
-    return virFileIsExecutable(IPTABLES_PATH) &&
-        virFileIsExecutable(IP6TABLES_PATH) &&
-        virFileIsExecutable(EBTABLES_PATH);
-}
-
 
 static int
 mymain(void)
@@ -179,11 +171,6 @@ mymain(void)
     } while (0)
 
     if (virFirewallSetBackend(VIR_FIREWALL_BACKEND_DIRECT) < 0) {
-        if (!hasNetfilterTools()) {
-            fprintf(stderr, "iptables/ip6tables/ebtables tools not present");
-            return EXIT_AM_SKIP;
-        }
-
         return EXIT_FAILURE;
     }
 
@@ -203,7 +190,8 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virgdbus"))
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virgdbus"),
+                      VIR_TEST_MOCK("virfirewall"))
 
 #else /* ! defined (__linux__) */
 
index 5f504cbe64eeeb86b47311cbc6c93ec03f1f870c..65b63959fbce232f0585843035996b63a1c2357b 100644 (file)
@@ -482,14 +482,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED)
     return ret;
 }
 
-static bool
-hasNetfilterTools(void)
-{
-    return virFileIsExecutable(IPTABLES_PATH) &&
-        virFileIsExecutable(IP6TABLES_PATH) &&
-        virFileIsExecutable(EBTABLES_PATH);
-}
-
 
 static int
 mymain(void)
@@ -497,11 +489,6 @@ mymain(void)
     int ret = 0;
 
     if (virFirewallSetBackend(VIR_FIREWALL_BACKEND_DIRECT) < 0) {
-        if (!hasNetfilterTools()) {
-            fprintf(stderr, "iptables/ip6tables/ebtables tools not present");
-            return EXIT_AM_SKIP;
-        }
-
         return EXIT_FAILURE;
     }
 
@@ -543,4 +530,4 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virfirewall"))
index 560372b802ba236ca5111899a7de5bbb3df1d09e..6709cc15fd14b2cf3b76ba5018640866e925f3c7 100644 (file)
@@ -431,14 +431,6 @@ testCompareXMLToIPTablesHelper(const void *data)
     return result;
 }
 
-static bool
-hasNetfilterTools(void)
-{
-    return virFileIsExecutable(IPTABLES_PATH) &&
-        virFileIsExecutable(IP6TABLES_PATH) &&
-        virFileIsExecutable(EBTABLES_PATH);
-}
-
 
 static int
 mymain(void)
@@ -456,10 +448,6 @@ mymain(void)
     } while (0)
 
     if (virFirewallSetBackend(VIR_FIREWALL_BACKEND_DIRECT) < 0) {
-        if (!hasNetfilterTools()) {
-            fprintf(stderr, "iptables/ip6tables/ebtables tools not present");
-            return EXIT_AM_SKIP;
-        }
         return EXIT_FAILURE;
     }
 
@@ -506,7 +494,7 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virfirewall"))
 
 #else /* ! defined (__linux__) */
 
index 8e65fa8524bc15e4c4897b397b38f642e96192e6..ac039f3bbf156755e3cb6905fc49e282bc8c6bb4 100644 (file)
@@ -1034,24 +1034,12 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED)
     return ret;
 }
 
-static bool
-hasNetfilterTools(void)
-{
-    return virFileIsExecutable(IPTABLES_PATH) &&
-        virFileIsExecutable(IP6TABLES_PATH) &&
-        virFileIsExecutable(EBTABLES_PATH);
-}
 
 static int
 mymain(void)
 {
     int ret = 0;
 
-    if (!hasNetfilterTools()) {
-        fprintf(stderr, "iptables/ip6tables/ebtables tools not present");
-        return EXIT_AM_SKIP;
-    }
-
 # define RUN_TEST_DIRECT(name, method) \
     do { \
         struct testFirewallData data; \
@@ -1100,7 +1088,8 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virgdbus"))
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virgdbus"),
+                      VIR_TEST_MOCK("virfirewall"))
 
 #else /* ! defined (__linux__) */