mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 10:03:49 +03:00
tests: qemublock: Add test for raw luks disk format
Apart from adding test data add a function which sets up fake secrets for the test. The top level disk image would generate the following '-drive' cmdline: -drive file=/path/luks.img,key-secret=test1-encalias,format=luks,if=none,id=drive-dummy -device virtio-blk-pci,scsi=off,drive=drive-dummy,id=dummy Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
ac71f4e6d5
commit
23a7f94893
@ -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 const char *testQemuDiskXMLToJSONPath = abs_srcdir "/qemublocktestdata/xml2json/";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -180,6 +218,9 @@ testQemuDiskXMLToProps(const void *opaque)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
||||||
|
if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!(props = qemuBlockStorageSourceGetBlockdevProps(n))) {
|
if (!(props = qemuBlockStorageSourceGetBlockdevProps(n))) {
|
||||||
if (!data->fail) {
|
if (!data->fail) {
|
||||||
VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n");
|
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("dir-fat-floppy");
|
||||||
TEST_DISK_TO_JSON("file-raw-aio_native");
|
TEST_DISK_TO_JSON("file-raw-aio_native");
|
||||||
TEST_DISK_TO_JSON("file-backing_basic-aio_threads");
|
TEST_DISK_TO_JSON("file-backing_basic-aio_threads");
|
||||||
|
TEST_DISK_TO_JSON("file-raw-luks");
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virHashFree(diskxmljsondata.schema);
|
virHashFree(diskxmljsondata.schema);
|
||||||
|
13
tests/qemublocktestdata/xml2json/file-raw-luks.json
Normal file
13
tests/qemublocktestdata/xml2json/file-raw-luks.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
15
tests/qemublocktestdata/xml2json/file-raw-luks.xml
Normal file
15
tests/qemublocktestdata/xml2json/file-raw-luks.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<disk device='disk'>
|
||||||
|
<driver name='qemu' type='raw'/>
|
||||||
|
<source file='/path/luks.img'>
|
||||||
|
<encryption format='luks'>
|
||||||
|
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f'/>
|
||||||
|
</encryption>
|
||||||
|
<privateData>
|
||||||
|
<nodenames>
|
||||||
|
<nodename type='storage' name='test2'/>
|
||||||
|
<nodename type='format' name='test1'/>
|
||||||
|
</nodenames>
|
||||||
|
</privateData>
|
||||||
|
</source>
|
||||||
|
<target dev='vda'/>
|
||||||
|
</disk>
|
Loading…
x
Reference in New Issue
Block a user