Fix fake libvirt XML generation for disks

The fake libvirt driver generates disk xml for disks of various types,
but assumes file type for the source attribute. This causes a parse
failure for block devices.

No tests currently rely on this. I encountered it whilst writing a test
which did use a fake block volume, and it was a severe headscratcher
when the resulting parsed configuration had an empty source_path: being
a block device it was looking for source/dev, not source/file. I
ultimately didn't use that test, but would like to save somebody the
hairloss in the future.

Change-Id: I5cf594cb0cc8310ccfa4f31d981803ce152a69d5
This commit is contained in:
Matthew Booth 2018-01-03 08:03:02 +00:00
parent 0010e230cc
commit 3664dd2253
1 changed files with 7 additions and 2 deletions

View File

@ -809,12 +809,17 @@ class Domain(object):
def XMLDesc(self, flags):
disks = ''
for disk in self._def['devices']['disks']:
if disk['type'] == 'file':
source_attr = 'file'
else:
source_attr = 'dev'
disks += '''<disk type='%(type)s' device='%(device)s'>
<driver name='%(driver_name)s' type='%(driver_type)s'/>
<source file='%(source)s'/>
<source %(source_attr)s='%(source)s'/>
<target dev='%(target_dev)s' bus='%(target_bus)s'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>''' % disk
</disk>''' % dict(source_attr=source_attr, **disk)
nics = ''
for nic in self._def['devices']['nics']: