From 3664dd22539dca0e9663ff0686e1c657176d9e8c Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Wed, 3 Jan 2018 08:03:02 +0000 Subject: [PATCH] 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 --- nova/tests/unit/virt/libvirt/fakelibvirt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/fakelibvirt.py b/nova/tests/unit/virt/libvirt/fakelibvirt.py index c64ad32ef643..f4e437e07cba 100644 --- a/nova/tests/unit/virt/libvirt/fakelibvirt.py +++ b/nova/tests/unit/virt/libvirt/fakelibvirt.py @@ -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 + ''' % dict(source_attr=source_attr, **disk) nics = '' for nic in self._def['devices']['nics']: