mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Convert nwfilter ebtablesRemoveBasicRules to virFirewall
Convert the nwfilter ebtablesRemoveBasicRules method to use the virFirewall object APIs instead of creating shell scripts using virBuffer APIs. This provides a performance improvement through allowing direct use of firewalld dbus APIs and will facilitate automated testing. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@@ -167,6 +167,55 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque ATTRIBUTE_UNUSED)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testNWFilterEBIPTablesRemoveBasicRules(const void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
const char *expected =
|
||||
"ebtables -t nat -D PREROUTING -i vnet0 -j libvirt-I-vnet0\n"
|
||||
"ebtables -t nat -D POSTROUTING -o vnet0 -j libvirt-O-vnet0\n"
|
||||
"ebtables -t nat -L libvirt-I-vnet0\n"
|
||||
"ebtables -t nat -L libvirt-O-vnet0\n"
|
||||
"ebtables -t nat -F libvirt-I-vnet0\n"
|
||||
"ebtables -t nat -X libvirt-I-vnet0\n"
|
||||
"ebtables -t nat -F libvirt-O-vnet0\n"
|
||||
"ebtables -t nat -X libvirt-O-vnet0\n"
|
||||
"ebtables -t nat -D PREROUTING -i vnet0 -j libvirt-J-vnet0\n"
|
||||
"ebtables -t nat -D POSTROUTING -o vnet0 -j libvirt-P-vnet0\n"
|
||||
"ebtables -t nat -L libvirt-J-vnet0\n"
|
||||
"ebtables -t nat -L libvirt-P-vnet0\n"
|
||||
"ebtables -t nat -F libvirt-J-vnet0\n"
|
||||
"ebtables -t nat -X libvirt-J-vnet0\n"
|
||||
"ebtables -t nat -F libvirt-P-vnet0\n"
|
||||
"ebtables -t nat -X libvirt-P-vnet0\n";
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
|
||||
virCommandSetDryRun(&buf, NULL, NULL);
|
||||
|
||||
if (ebiptables_driver.removeBasicRules("vnet0") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virBufferError(&buf))
|
||||
goto cleanup;
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
virtTestClearCommandPath(actual);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virtTestDifference(stderr, actual, expected);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virCommandSetDryRun(NULL, NULL, NULL);
|
||||
virBufferFreeAndReset(&buf);
|
||||
VIR_FREE(actual);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
@@ -187,6 +236,11 @@ mymain(void)
|
||||
NULL) < 0)
|
||||
ret = -1;
|
||||
|
||||
if (virtTestRun("ebiptablesRemoveBasicRules",
|
||||
testNWFilterEBIPTablesRemoveBasicRules,
|
||||
NULL) < 0)
|
||||
ret = -1;
|
||||
|
||||
cleanup:
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user