From 979d1bac9f91bdbde440c3baeafa6bf5d117d946 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 17 Dec 2013 16:28:20 -0700 Subject: [PATCH] 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 (cherry picked from commit 974e5914522099ba4d463e24941289b785fe2096) Conflicts: tests/virstoragetest.c - hardcode test to v2, since this branch doesn't handle v3 correctly --- tests/virstoragetest.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 0e6ba9e75c..48eaa66ab1 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -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();