Fix processing of libvirt disk.info in non-disk-image cases

In Idfc16f54049aaeab31ac1c1d8d79a129acc9fb87 a change was made
that caused non-disk-image backends to fall over because of an
undefined variable because they skipped processing of the disk.info
file. This adds a check for that case to make sure we don't run
that path in the non-disk-image backend case.

Closes-Bug: #1555287

Change-Id: I02f8a5f0e29816336e500a8fe8dcc9ece15968e9
This commit is contained in:
Matthew Booth 2016-03-09 17:27:03 +00:00 committed by Tristan Cacqueray
parent f302bf04ab
commit 2d7166db25
2 changed files with 22 additions and 13 deletions

View File

@ -11671,12 +11671,19 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
mock_path.return_value = instance_base
mock_shared.return_value = False
self.drvr.migrate_disk_and_power_off(context.get_admin_context(),
instance, mock.sentinel,
flavor_obj, None)
src_disk_info_path = os.path.join(instance_base + '_resize',
'disk.info')
with mock.patch.object(os.path, 'exists', autospec=True) \
as mock_exists:
# disk.info exists on the source
mock_exists.side_effect = \
lambda path: path == src_disk_info_path
self.drvr.migrate_disk_and_power_off(context.get_admin_context(),
instance, mock.sentinel,
flavor_obj, None)
self.assertTrue(mock_exists.called)
dst_disk_info_path = os.path.join(instance_base, 'disk.info')
mock_copy.assert_any_call(src_disk_info_path, dst_disk_info_path,
host=mock.sentinel, on_execute=mock.ANY,

View File

@ -6338,6 +6338,11 @@ class LibvirtDriver(driver.ComputeDriver):
dest = None
utils.execute('mkdir', '-p', inst_base)
on_execute = lambda process: \
self.job_tracker.add_job(instance, process.pid)
on_completion = lambda process: \
self.job_tracker.remove_job(instance, process.pid)
active_flavor = instance.get_flavor()
for info in disk_info:
# assume inst_base == dirname(info['path'])
@ -6357,11 +6362,6 @@ class LibvirtDriver(driver.ComputeDriver):
# finish_migration/_create_image to re-create it for us.
continue
on_execute = lambda process: self.job_tracker.add_job(
instance, process.pid)
on_completion = lambda process: self.job_tracker.remove_job(
instance, process.pid)
if info['type'] == 'qcow2' and info['backing_file']:
tmp_path = from_path + "_rbase"
# merge backing file
@ -6384,10 +6384,12 @@ class LibvirtDriver(driver.ComputeDriver):
# Ensure disk.info is written to the new path to avoid disks being
# reinspected and potentially changing format.
src_disk_info_path = os.path.join(inst_base_resize, 'disk.info')
dst_disk_info_path = os.path.join(inst_base, 'disk.info')
libvirt_utils.copy_image(src_disk_info_path, dst_disk_info_path,
host=dest, on_execute=on_execute,
on_completion=on_completion)
if os.path.exists(src_disk_info_path):
dst_disk_info_path = os.path.join(inst_base, 'disk.info')
libvirt_utils.copy_image(src_disk_info_path,
dst_disk_info_path,
host=dest, on_execute=on_execute,
on_completion=on_completion)
except Exception:
with excutils.save_and_reraise_exception():
self._cleanup_remote_migration(dest, inst_base,