backupxml2xmltest: Call 'virDomainBackupAlignDisks' before formatting output

Call the post-processing function so that we can validate that it does
the correct thing.

virDomainBackupAlignDisks requires disk definitions to be present so
let's fake them by copying disks from the backup definition and add one
extra disk 'vdextradisk'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Peter Krempa 2020-07-07 16:38:00 +02:00
parent 1a7ce56ae1
commit 6f33e441e2
9 changed files with 50 additions and 1 deletions

View File

@ -26,5 +26,6 @@
</encryption>
</scratch>
</disk>
<disk name='vdextradisk' backup='no'/>
</disks>
</domainbackup>

View File

@ -26,6 +26,7 @@
</encryption>
</scratch>
</disk>
<disk name='vdextradisk' backup='no'/>
</disks>
<privateData>
<objects>

View File

@ -14,5 +14,6 @@
<seclabel model='dac' relabel='no'/>
</scratch>
</disk>
<disk name='vdextradisk' backup='no'/>
</disks>
</domainbackup>

View File

@ -6,5 +6,6 @@
<scratch file='/path/to/file'/>
</disk>
<disk name='hda' backup='no'/>
<disk name='vdextradisk' backup='no'/>
</disks>
</domainbackup>

View File

@ -25,5 +25,6 @@
</encryption>
</target>
</disk>
<disk name='vdextradisk' backup='no'/>
</disks>
</domainbackup>

View File

@ -13,5 +13,6 @@
<seclabel model='dac' relabel='no'/>
</target>
</disk>
<disk name='vdextradisk' backup='no'/>
</disks>
</domainbackup>

View File

@ -6,5 +6,6 @@
<target file='/path/to/file'/>
</disk>
<disk name='hda' backup='no'/>
<disk name='vdextradisk' backup='no'/>
</disks>
</domainbackup>

View File

@ -1 +1,7 @@
<domainbackup mode='push'/>
<domainbackup mode='push'>
<disks>
<disk name='vdextradisk' backup='yes' type='file'>
<target file='/fake/vdextradisk.qcow2.SUFFIX'/>
</disk>
</disks>
</domainbackup>

View File

@ -51,6 +51,23 @@ struct testCompareBackupXMLData {
};
static virDomainDiskDefPtr
testCompareBackupXMLGetFakeDomdisk(const char *dst)
{
virDomainDiskDefPtr domdisk = NULL;
if (!(domdisk = virDomainDiskDefNew(NULL)))
abort();
domdisk->dst = g_strdup(dst);
domdisk->src->type = VIR_STORAGE_TYPE_FILE;
domdisk->src->format = VIR_STORAGE_FILE_QCOW2;
domdisk->src->path = g_strdup_printf("/fake/%s.qcow2", dst);
return domdisk;
}
static int
testCompareBackupXML(const void *opaque)
{
@ -63,6 +80,8 @@ testCompareBackupXML(const void *opaque)
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *actual = NULL;
unsigned int parseFlags = 0;
g_autoptr(virDomainDef) fakedef = NULL;
size_t i;
if (data->internal)
parseFlags |= VIR_DOMAIN_BACKUP_PARSE_INTERNAL;
@ -80,6 +99,23 @@ testCompareBackupXML(const void *opaque)
return -1;
}
/* create a fake definition and fill it with disks */
if (!(fakedef = virDomainDefNew()))
return -1;
fakedef->ndisks = backup->ndisks + 1;
fakedef->disks = g_new0(virDomainDiskDefPtr, fakedef->ndisks);
for (i = 0; i < backup->ndisks; i++)
fakedef->disks[i] = testCompareBackupXMLGetFakeDomdisk(backup->disks[i].name);
fakedef->disks[fakedef->ndisks -1 ] = testCompareBackupXMLGetFakeDomdisk("vdextradisk");
if (virDomainBackupAlignDisks(backup, fakedef, "SUFFIX") < 0) {
VIR_TEST_VERBOSE("failed to align backup def '%s'", file_in);
return -1;
}
if (virDomainBackupDefFormat(&buf, backup, data->internal) < 0) {
VIR_TEST_VERBOSE("failed to format backup def '%s'", file_in);
return -1;