mirror of
https://github.com/libvirt/libvirt.git
synced 2026-07-30 08:08:11 -05:00
virfirewalltest: Shuffle the code around to remove a loop
We are already looping over the arguments to construct the list, so we can add them to fwBuf right away rather than in an extra loop if we move some of the 'fwBuf' parts earlier and merge the two loops. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
+11
-14
@@ -108,23 +108,11 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync,
|
||||
char *item = NULL;
|
||||
bool isAdd = false;
|
||||
bool doError = false;
|
||||
size_t i;
|
||||
|
||||
g_variant_get(params, "(&sas)", &type, &iter);
|
||||
|
||||
nargs = g_variant_iter_n_children(iter);
|
||||
|
||||
while (g_variant_iter_loop(iter, "s", &item)) {
|
||||
/* Fake failure on the command with this IP addr */
|
||||
if (STREQ(item, "-A")) {
|
||||
isAdd = true;
|
||||
} else if (isAdd && STREQ(item, "192.168.122.255")) {
|
||||
doError = true;
|
||||
}
|
||||
|
||||
virStringListAdd(&args, item);
|
||||
}
|
||||
|
||||
if (fwBuf) {
|
||||
if (STREQ(type, "ipv4"))
|
||||
virBufferAddLit(fwBuf, IPTABLES_PATH);
|
||||
@@ -134,10 +122,19 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync,
|
||||
virBufferAddLit(fwBuf, EBTABLES_PATH);
|
||||
}
|
||||
|
||||
for (i = 0; i < nargs; i++) {
|
||||
while (g_variant_iter_loop(iter, "s", &item)) {
|
||||
/* Fake failure on the command with this IP addr */
|
||||
if (STREQ(item, "-A")) {
|
||||
isAdd = true;
|
||||
} else if (isAdd && STREQ(item, "192.168.122.255")) {
|
||||
doError = true;
|
||||
}
|
||||
|
||||
virStringListAdd(&args, item);
|
||||
|
||||
if (fwBuf) {
|
||||
virBufferAddLit(fwBuf, " ");
|
||||
virBufferEscapeShell(fwBuf, args[i]);
|
||||
virBufferEscapeShell(fwBuf, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user