mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-02 23:23:51 +00:00
tests: be more explicit on qcow2 versions in virstoragetest
While working on v1.0.5-maint (the branch in use on Fedora 19) with the host at Fedora 20, I got a failure in virstoragetest. I traced it to the fact that we were using qemu-img to create a qcow2 file, but qemu-img changed from creating v2 files by default in F19 to creating v3 files in F20. Rather than leaving it up to qemu-img, it is better to write the test to force testing of BOTH file formats (better code coverage and all). This patch alone does not fix all the failures in v1.0.5-maint; for that, we must decide to either teach the older branch to understand v3 files, or to reject them outright as unsupported. But for upstream, making the test less dependent on changing qemu-img defaults is always a good thing. * tests/virstoragetest.c (testPrepImages): Simplify creation of raw file; check if qemu supports compat and if so use it. Signed-off-by: Eric Blake <eblake@redhat.com> (cherry picked from commit 974e5914522099ba4d463e24941289b785fe2096) Conflicts: tests/virstoragetest.c - hardcode test to v2, since this branch doesn't handle v3 correctly
This commit is contained in:
parent
2dd4b39394
commit
979d1bac9f
@ -85,6 +85,8 @@ testPrepImages(void)
|
||||
{
|
||||
int ret = EXIT_FAILURE;
|
||||
virCommandPtr cmd = NULL;
|
||||
char *buf = NULL;
|
||||
bool compat = false;
|
||||
|
||||
qemuimg = virFindFileInPath("kvm-img");
|
||||
if (!qemuimg)
|
||||
@ -92,6 +94,18 @@ testPrepImages(void)
|
||||
if (!qemuimg)
|
||||
goto skip;
|
||||
|
||||
/* See if qemu-img supports '-o compat=xxx'. If so, we force the
|
||||
* use of v2 files. FIXME - should we handle v3 gracefully on
|
||||
* maintenance branches? */
|
||||
cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2",
|
||||
"-o?", "/dev/null", NULL);
|
||||
virCommandSetOutputBuffer(cmd, &buf);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto skip;
|
||||
if (strstr(buf, "compat "))
|
||||
compat = true;
|
||||
VIR_FREE(buf);
|
||||
|
||||
if (virAsprintf(&absraw, "%s/raw", datadir) < 0 ||
|
||||
virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 ||
|
||||
virAsprintf(&abswrap, "%s/wrap", datadir) < 0 ||
|
||||
@ -111,10 +125,8 @@ testPrepImages(void)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* I'm lazy enough to use a shell one-liner instead of open/write/close */
|
||||
virCommandFree(cmd);
|
||||
cmd = virCommandNewArgList("sh", "-c", "printf %1024d 0 > raw", NULL);
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
if (virAsprintf(&buf, "%1024d", 0) < 0 ||
|
||||
virFileWriteStr("raw", buf, 0600) < 0) {
|
||||
fprintf(stderr, "unable to create raw file\n");
|
||||
goto cleanup;
|
||||
}
|
||||
@ -126,9 +138,10 @@ testPrepImages(void)
|
||||
/* Create a qcow2 wrapping relative raw; later on, we modify its
|
||||
* metadata to test other configurations */
|
||||
virCommandFree(cmd);
|
||||
cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2",
|
||||
"-obacking_file=raw,backing_fmt=raw", "qcow2",
|
||||
NULL);
|
||||
cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL);
|
||||
virCommandAddArgFormat(cmd, "-obacking_file=raw,backing_fmt=raw%s",
|
||||
compat ? ",compat=0.10" : "");
|
||||
virCommandAddArg(cmd, "qcow2");
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto skip;
|
||||
/* Make sure our later uses of 'qemu-img rebase' will work */
|
||||
@ -146,8 +159,8 @@ testPrepImages(void)
|
||||
* can correctly avoid insecure probing. */
|
||||
virCommandFree(cmd);
|
||||
cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL);
|
||||
virCommandAddArgFormat(cmd, "-obacking_file=%s,backing_fmt=qcow2",
|
||||
absqcow2);
|
||||
virCommandAddArgFormat(cmd, "-obacking_file=%s,backing_fmt=qcow2%s",
|
||||
absqcow2, compat ? ",compat=0.10" : "");
|
||||
virCommandAddArg(cmd, "wrap");
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto skip;
|
||||
@ -172,6 +185,7 @@ testPrepImages(void)
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(buf);
|
||||
virCommandFree(cmd);
|
||||
if (ret)
|
||||
testCleanupImages();
|
||||
|
Loading…
x
Reference in New Issue
Block a user