提交 73470fe2 编写于 作者: E Eric Blake

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: NEric Blake <eblake@redhat.com>
(cherry picked from commit 974e5914)

Conflicts:
	tests/virstoragetest.c - hardcode test to v2, since this branch doesn't handle v3 correctly
上级 2d2bd72d
...@@ -87,6 +87,8 @@ testPrepImages(void) ...@@ -87,6 +87,8 @@ testPrepImages(void)
{ {
int ret = EXIT_FAILURE; int ret = EXIT_FAILURE;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
char *buf = NULL;
bool compat = false;
qemuimg = virFindFileInPath("kvm-img"); qemuimg = virFindFileInPath("kvm-img");
if (!qemuimg) if (!qemuimg)
...@@ -94,6 +96,18 @@ testPrepImages(void) ...@@ -94,6 +96,18 @@ testPrepImages(void)
if (!qemuimg) if (!qemuimg)
goto skip; 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 || if (virAsprintf(&absraw, "%s/raw", datadir) < 0 ||
virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 || virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 ||
virAsprintf(&abswrap, "%s/wrap", datadir) < 0 || virAsprintf(&abswrap, "%s/wrap", datadir) < 0 ||
...@@ -113,10 +127,8 @@ testPrepImages(void) ...@@ -113,10 +127,8 @@ testPrepImages(void)
goto cleanup; goto cleanup;
} }
/* I'm lazy enough to use a shell one-liner instead of open/write/close */ if (virAsprintf(&buf, "%1024d", 0) < 0 ||
virCommandFree(cmd); virFileWriteStr("raw", buf, 0600) < 0) {
cmd = virCommandNewArgList("sh", "-c", "printf %1024d 0 > raw", NULL);
if (virCommandRun(cmd, NULL) < 0) {
fprintf(stderr, "unable to create raw file\n"); fprintf(stderr, "unable to create raw file\n");
goto cleanup; goto cleanup;
} }
...@@ -128,9 +140,10 @@ testPrepImages(void) ...@@ -128,9 +140,10 @@ testPrepImages(void)
/* Create a qcow2 wrapping relative raw; later on, we modify its /* Create a qcow2 wrapping relative raw; later on, we modify its
* metadata to test other configurations */ * metadata to test other configurations */
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL);
"-obacking_file=raw,backing_fmt=raw", "qcow2", virCommandAddArgFormat(cmd, "-obacking_file=raw,backing_fmt=raw%s",
NULL); compat ? ",compat=0.10" : "");
virCommandAddArg(cmd, "qcow2");
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto skip; goto skip;
/* Make sure our later uses of 'qemu-img rebase' will work */ /* Make sure our later uses of 'qemu-img rebase' will work */
...@@ -148,8 +161,8 @@ testPrepImages(void) ...@@ -148,8 +161,8 @@ testPrepImages(void)
* can correctly avoid insecure probing. */ * can correctly avoid insecure probing. */
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL); cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL);
virCommandAddArgFormat(cmd, "-obacking_file=%s,backing_fmt=qcow2", virCommandAddArgFormat(cmd, "-obacking_file=%s,backing_fmt=qcow2%s",
absqcow2); absqcow2, compat ? ",compat=0.10" : "");
virCommandAddArg(cmd, "wrap"); virCommandAddArg(cmd, "wrap");
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto skip; goto skip;
...@@ -174,6 +187,7 @@ testPrepImages(void) ...@@ -174,6 +187,7 @@ testPrepImages(void)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(buf);
virCommandFree(cmd); virCommandFree(cmd);
if (ret) if (ret)
testCleanupImages(); testCleanupImages();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册