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 Dan Smith
parent 848de1f712
commit ccd6195e67
2 changed files with 23 additions and 14 deletions

View File

@ -14186,16 +14186,23 @@ 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,
on_completion=mock.ANY, compression=mock.ANY)
on_completion=mock.ANY)
def test_wait_for_running(self):
def fake_get_info(instance):

View File

@ -7194,6 +7194,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'])
@ -7212,10 +7217,6 @@ class LibvirtDriver(driver.ComputeDriver):
if not (fname == 'disk.swap' and
active_flavor.get('swap', 0) != flavor.get('swap', 0)):
on_execute = lambda process: self.job_tracker.add_job(
instance, process.pid)
on_completion = lambda process: self.job_tracker.\
remove_job(instance, process.pid)
compression = info['type'] not in NO_COMPRESSION_TYPES
libvirt_utils.copy_image(from_path, img_path, host=dest,
on_execute=on_execute,
@ -7225,11 +7226,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,
compression=compression)
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,