[libvirt PATCH 08/17] tests: use virfirewallmock instead of hasNetfilterTools

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tests/networkxml2firewalltest.c  | 16 ++--------------
 tests/nwfilterebiptablestest.c   | 15 +--------------
 tests/nwfilterxml2firewalltest.c | 14 +-------------
 tests/virfirewalltest.c          | 15 ++-------------
 4 files changed, 6 insertions(+), 54 deletions(-)

diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c
index 80ba510d14..91336a0c55 100644
--- a/tests/networkxml2firewalltest.c
+++ b/tests/networkxml2firewalltest.c
@@ -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__) */
 
diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c
index 5f504cbe64..65b63959fb 100644
--- a/tests/nwfilterebiptablestest.c
+++ b/tests/nwfilterebiptablestest.c
@@ -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"))
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index 560372b802..6709cc15fd 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -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__) */
 
diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c
index 8e65fa8524..ac039f3bbf 100644
--- a/tests/virfirewalltest.c
+++ b/tests/virfirewalltest.c
@@ -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__) */
 
-- 
2.30.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux