mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
tests: use virfirewallmock instead of hasNetfilterTools
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>
This commit is contained in:
parent
e938ea5062
commit
50a021df33
@ -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__) */
|
||||
|
||||
|
@ -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"))
|
||||
|
@ -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__) */
|
||||
|
||||
|
@ -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__) */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user