mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
qemu: fix nbdkit command test for backing chains
Previously this test only tested the generated nbdkit command for the top level disk source. Update it to test the generated commmands for all sources in the chain. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
a883602c9a
commit
bdece5518d
tests
qemunbdkitdata
disk-cdrom-network.args.disk0-src0disk-cdrom-network.args.disk1-src0disk-cdrom-network.args.disk1-src0.pipe.778disk-cdrom-network.args.disk2-src0disk-cdrom-network.args.disk2-src0.pipe.780disk-network-http.args.disk0-src0disk-network-http.args.disk1-src0disk-network-http.args.disk2-src0disk-network-http.args.disk2-src0.pipe.778disk-network-http.args.disk3-src0disk-network-http.args.disk3-src0.pipe.780disk-network-source-curl-nbdkit-backing.args.disk0-src0disk-network-source-curl-nbdkit-backing.args.disk0-src0.pipe.778disk-network-source-curl-nbdkit-backing.args.disk0-src1disk-network-source-curl-nbdkit-backing.args.disk0-src1.pipe.780disk-network-source-curl.args.disk0-src0disk-network-source-curl.args.disk0-src0.pipe.778disk-network-source-curl.args.disk1-src0disk-network-source-curl.args.disk1-src0.pipe.780disk-network-source-curl.args.disk1-src0.pipe.782disk-network-source-curl.args.disk2-src0disk-network-source-curl.args.disk2-src0.pipe.784disk-network-source-curl.args.disk3-src0disk-network-source-curl.args.disk4-src0disk-network-ssh-key.args.disk0-src0disk-network-ssh-key.args.disk1-src0disk-network-ssh-password.args.disk0-src0disk-network-ssh-password.args.disk0-src0.pipe.778disk-network-ssh.args.disk0-src0
qemunbdkittest.c@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=ftp \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk1-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=ftps \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk2-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=https \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground curl \
|
||||
protocols=http,https \
|
||||
url=http://example.org:80/test.img \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk1-src0.socket \
|
||||
--foreground curl \
|
||||
protocols=https \
|
||||
url=https://example.org:443/test2.img
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk2-src0.socket \
|
||||
--foreground curl \
|
||||
protocols=http,https \
|
||||
url=http://example.org:1234/test3.img \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-3/nbdkit-test-disk-3.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk3-src0.socket \
|
||||
--foreground curl \
|
||||
protocols=https \
|
||||
'url=https://example.org:1234/test4.img?par=val&other=ble' \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=https \
|
@ -0,0 +1,7 @@
|
||||
nbdkit \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src1.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=https \
|
||||
url=https://https.example2.org:8444/path/to/backing.qcow2 \
|
||||
cookie=-779
|
@ -0,0 +1 @@
|
||||
cookie3=cookievalue3; cookie4=cookievalue4
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=https \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk1-src0.socket \
|
||||
--foreground curl \
|
||||
protocols=https \
|
||||
'url=https://https.example.org:8443/path/to/disk5.iso?foo=bar' \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk2-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=http,https \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-3/nbdkit-test-disk-3.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk3-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=ftp \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-4/nbdkit-test-disk-4.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk4-src0.socket \
|
||||
--foreground \
|
||||
--readonly curl \
|
||||
protocols=ftps \
|
@ -1,6 +1,6 @@
|
||||
SSH_AUTH_SOCK=/path/to/agent/socket \
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground ssh \
|
||||
host=example.org \
|
||||
port=2222 \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk1-src0.socket \
|
||||
--foreground ssh \
|
||||
host=example.org \
|
||||
port=2222 \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground ssh \
|
||||
host=example.org \
|
||||
port=2222 \
|
@ -1,5 +1,5 @@
|
||||
nbdkit \
|
||||
--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \
|
||||
--unix /tmp/domain-QEMUGuest1/nbdkit-disk0-src0.socket \
|
||||
--foreground ssh \
|
||||
host=example.org \
|
||||
port=2222 \
|
@ -174,7 +174,10 @@ testNbdkit(const void *data)
|
||||
const TestInfo *info = data;
|
||||
g_autoptr(virDomainDef) def = NULL;
|
||||
size_t i;
|
||||
size_t n;
|
||||
int ret = 0;
|
||||
virStorageSource *backing = NULL;
|
||||
g_autofree char *statedir = NULL;
|
||||
|
||||
/* restart mock pipe fds so tests are consistent */
|
||||
mockpipefd = PIPE_FD_START;
|
||||
@ -189,56 +192,61 @@ testNbdkit(const void *data)
|
||||
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
|
||||
return -1;
|
||||
|
||||
statedir = g_strdup_printf("/tmp/domain-%s", def->name);
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
virDomainDiskDef *disk = def->disks[i];
|
||||
g_autofree char *statedir = g_strdup_printf("/tmp/statedir-%zi", i);
|
||||
g_autofree char *alias = g_strdup_printf("test-disk-%zi", i);
|
||||
g_autofree char *cmdfile = g_strdup_printf("%s.args.disk%zi",
|
||||
info->outtemplate, i);
|
||||
for (n = 0, backing = disk->src; backing != NULL; n++, backing = backing->backingStore) {
|
||||
g_autofree char *alias = g_strdup_printf("disk%zi-src%zi", i, n);
|
||||
g_autofree char *cmdfile = g_strdup_printf("%s.args.%s",
|
||||
info->outtemplate, alias);
|
||||
|
||||
if (qemuNbdkitInitStorageSource(info->nbdkitcaps, disk->src, statedir,
|
||||
alias, 101, 101)) {
|
||||
qemuDomainStorageSourcePrivate *srcPriv =
|
||||
qemuDomainStorageSourcePrivateFetch(disk->src);
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
g_autofree char *actualCmdline = NULL;
|
||||
virCommandSendBuffer *sendbuffers;
|
||||
int nsendbuffers;
|
||||
size_t j;
|
||||
if (qemuNbdkitInitStorageSource(info->nbdkitcaps, backing, statedir,
|
||||
alias, 101, 101)) {
|
||||
qemuDomainStorageSourcePrivate *srcPriv =
|
||||
qemuDomainStorageSourcePrivateFetch(backing);
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
g_autofree char *actualCmdline = NULL;
|
||||
virCommandSendBuffer *sendbuffers;
|
||||
int nsendbuffers;
|
||||
size_t j;
|
||||
|
||||
virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
|
||||
cmd = qemuNbdkitProcessBuildCommand(srcPriv->nbdkitProcess);
|
||||
if (srcPriv->nbdkitProcess == NULL)
|
||||
continue;
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
virCommandPeekSendBuffers(cmd, &sendbuffers, &nsendbuffers);
|
||||
virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
|
||||
cmd = qemuNbdkitProcessBuildCommand(srcPriv->nbdkitProcess);
|
||||
|
||||
if (!(actualCmdline = virBufferContentAndReset(&buf))) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < 0)
|
||||
ret = -1;
|
||||
|
||||
for (j = 0; j < nsendbuffers; j++) {
|
||||
virCommandSendBuffer *buffer = &sendbuffers[j];
|
||||
g_autofree char *pipefile = g_strdup_printf("%s.pipe.%i",
|
||||
cmdfile,
|
||||
buffer->fd);
|
||||
|
||||
if (virTestCompareToFile((const char*)buffer->buffer, pipefile) < 0)
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
ret = -1;
|
||||
}
|
||||
} else {
|
||||
if (virFileExists(cmdfile)) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
"qemuNbdkitInitStorageSource() was not expected to fail");
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
virCommandPeekSendBuffers(cmd, &sendbuffers, &nsendbuffers);
|
||||
|
||||
if (!(actualCmdline = virBufferContentAndReset(&buf))) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < 0)
|
||||
ret = -1;
|
||||
|
||||
for (j = 0; j < nsendbuffers; j++) {
|
||||
virCommandSendBuffer *buffer = &sendbuffers[j];
|
||||
g_autofree char *pipefile = g_strdup_printf("%s.pipe.%i",
|
||||
cmdfile,
|
||||
buffer->fd);
|
||||
|
||||
if (virTestCompareToFile((const char*)buffer->buffer, pipefile) < 0)
|
||||
ret = -1;
|
||||
}
|
||||
} else {
|
||||
if (virFileExists(cmdfile)) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
"qemuNbdkitInitStorageSource() was not expected to fail");
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user