diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 9699001af6..b44f8c32a3 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -145,6 +145,44 @@ testQemuDiskXMLToPropsClear(struct testQemuDiskXMLToJSONData *data) } +static int +testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) +{ + qemuDomainStorageSourcePrivatePtr srcpriv; + + if (!src->privateData && + !(src->privateData = qemuDomainStorageSourcePrivateNew())) + return -1; + + srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); + + if (src->auth) { + if (VIR_ALLOC(srcpriv->secinfo) < 0) + return -1; + + srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; + if (VIR_STRDUP(srcpriv->secinfo->s.aes.username, src->auth->username) < 0) + return -1; + + if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias", + NULLSTR(src->nodestorage)) < 0) + return -1; + } + + if (src->encryption) { + if (VIR_ALLOC(srcpriv->encinfo) < 0) + return -1; + + srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; + if (virAsprintf(&srcpriv->encinfo->s.aes.alias, "%s-encalias", + NULLSTR(src->nodeformat)) < 0) + return -1; + } + + return 0; +} + + static const char *testQemuDiskXMLToJSONPath = abs_srcdir "/qemublocktestdata/xml2json/"; static int @@ -180,6 +218,9 @@ testQemuDiskXMLToProps(const void *opaque) goto cleanup; for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { + if (testQemuDiskXMLToJSONFakeSecrets(n) < 0) + goto cleanup; + if (!(props = qemuBlockStorageSourceGetBlockdevProps(n))) { if (!data->fail) { VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n"); @@ -419,6 +460,7 @@ mymain(void) TEST_DISK_TO_JSON("dir-fat-floppy"); TEST_DISK_TO_JSON("file-raw-aio_native"); TEST_DISK_TO_JSON("file-backing_basic-aio_threads"); + TEST_DISK_TO_JSON("file-raw-luks"); cleanup: virHashFree(diskxmljsondata.schema); diff --git a/tests/qemublocktestdata/xml2json/file-raw-luks.json b/tests/qemublocktestdata/xml2json/file-raw-luks.json new file mode 100644 index 0000000000..e3d9c4c26b --- /dev/null +++ b/tests/qemublocktestdata/xml2json/file-raw-luks.json @@ -0,0 +1,13 @@ +{ + "node-name": "test1", + "read-only": false, + "driver": "luks", + "key-secret": "test1-encalias", + "file": { + "driver": "file", + "filename": "/path/luks.img", + "node-name": "test2", + "read-only": false, + "discard": "unmap" + } +} diff --git a/tests/qemublocktestdata/xml2json/file-raw-luks.xml b/tests/qemublocktestdata/xml2json/file-raw-luks.xml new file mode 100644 index 0000000000..f446b03bdb --- /dev/null +++ b/tests/qemublocktestdata/xml2json/file-raw-luks.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +