Add ability to register callback for virCommand dry run

To allow for fault injection of the virCommand dry run,
add the ability to register a callback. The callback will
be passed the argv, env and stdin buffer and is expected
to return the exit status and optionally fill stdout and
stderr buffers.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2014-03-07 11:39:48 +00:00
parent df3a681c03
commit 7b3f1f8c30
5 changed files with 59 additions and 18 deletions

View File

@@ -96,7 +96,7 @@ testKModLoad(const void *args)
bool useBlacklist = info->useBlacklist;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virCommandSetDryRun(&buf);
virCommandSetDryRun(&buf, NULL, NULL);
errbuf = virKModLoad(module, useBlacklist);
if (errbuf) {
@@ -110,7 +110,7 @@ testKModLoad(const void *args)
ret = 0;
cleanup:
virCommandSetDryRun(NULL);
virCommandSetDryRun(NULL, NULL, NULL);
VIR_FREE(errbuf);
return ret;
}
@@ -125,7 +125,7 @@ testKModUnload(const void *args)
const char *module = info->module;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virCommandSetDryRun(&buf);
virCommandSetDryRun(&buf, NULL, NULL);
errbuf = virKModUnload(module);
if (errbuf) {
@@ -139,7 +139,7 @@ testKModUnload(const void *args)
ret = 0;
cleanup:
virCommandSetDryRun(NULL);
virCommandSetDryRun(NULL, NULL, NULL);
VIR_FREE(errbuf);
return ret;
}

View File

@@ -77,7 +77,7 @@ testVirNetDevBandwidthSet(const void *data)
if (!iface)
iface = "eth0";
virCommandSetDryRun(&buf);
virCommandSetDryRun(&buf, NULL, NULL);
if (virNetDevBandwidthSet(iface, band, info->hierarchical_class) < 0)
goto cleanup;
@@ -101,6 +101,7 @@ testVirNetDevBandwidthSet(const void *data)
ret = 0;
cleanup:
virCommandSetDryRun(NULL, NULL, NULL);
virNetDevBandwidthFree(band);
virBufferFreeAndReset(&buf);
VIR_FREE(actual_cmd);