提交 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)
{
int ret = EXIT_FAILURE;
virCommandPtr cmd = NULL;
char *buf = NULL;
bool compat = false;
qemuimg = virFindFileInPath("kvm-img");
if (!qemuimg)
......@@ -94,6 +96,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 ||
......@@ -113,10 +127,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;
}
......@@ -128,9 +140,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 */
......@@ -148,8 +161,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;
......@@ -174,6 +187,7 @@ testPrepImages(void)
ret = 0;
cleanup:
VIR_FREE(buf);
virCommandFree(cmd);
if (ret)
testCleanupImages();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册