Merge "Use absolute path during qemu img rebase" into stable/ussuri

This commit is contained in:
Zuul 2021-03-31 10:39:52 +00:00 committed by Gerrit Code Review
commit 4c5556cec4
2 changed files with 33 additions and 6 deletions

View File

@ -25779,8 +25779,23 @@ class LibvirtVolumeSnapshotTestCase(test.NoDBTestCase):
not running should trigger a blockRebase using qemu-img not libvirt. not running should trigger a blockRebase using qemu-img not libvirt.
In this test, we rebase the image with another image as backing file. In this test, we rebase the image with another image as backing file.
""" """
dom_xml = """
<domain type='kvm'>
<devices>
<disk type='file'>
<source file='/var/lib/nova/instances/%s/disk1_file'/>
<target dev='vda' bus='virtio'/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>
<disk type='block'>
<source dev='/path/to/dev/1'/>
<target dev='vdb' bus='virtio' serial='1234'/>
</disk>
</devices>
</domain>""" % self.inst['uuid']
mock_domain, guest = self._setup_block_rebase_domain_and_guest_mocks( mock_domain, guest = self._setup_block_rebase_domain_and_guest_mocks(
self.dom_xml) dom_xml)
instance = objects.Instance(**self.inst) instance = objects.Instance(**self.inst)
snapshot_id = 'snapshot-1234' snapshot_id = 'snapshot-1234'
@ -25791,10 +25806,13 @@ class LibvirtVolumeSnapshotTestCase(test.NoDBTestCase):
self.delete_info_1) self.delete_info_1)
mock_disk_op_sema.__enter__.assert_called_once() mock_disk_op_sema.__enter__.assert_called_once()
mock_qemu_img_info.assert_called_once_with("snap.img") mock_qemu_img_info.assert_called_once_with(
mock_execute.assert_called_once_with('qemu-img', 'rebase', "/var/lib/nova/instances/%s/snap.img" % instance.uuid)
'-b', 'snap.img', '-F', mock_execute.assert_called_once_with(
'fake_fmt', 'disk1_file') 'qemu-img', 'rebase',
'-b', '/var/lib/nova/instances/%s/snap.img' % instance.uuid,
'-F', 'fake_fmt',
'/var/lib/nova/instances/%s/disk1_file' % instance.uuid)
@mock.patch.object(compute_utils, 'disk_ops_semaphore') @mock.patch.object(compute_utils, 'disk_ops_semaphore')
@mock.patch.object(host.Host, "has_min_version", @mock.patch.object(host.Host, "has_min_version",

View File

@ -2953,7 +2953,16 @@ class LibvirtDriver(driver.ComputeDriver):
# If the rebased image is going to have a backing file then # If the rebased image is going to have a backing file then
# explicitly set the backing file format to avoid any security # explicitly set the backing file format to avoid any security
# concerns related to file format auto detection. # concerns related to file format auto detection.
backing_file = rebase_base if os.path.isabs(rebase_base):
backing_file = rebase_base
else:
# this is a probably a volume snapshot case where the
# rebase_base is relative. See bug
# https://bugs.launchpad.net/nova/+bug/1885528
backing_file_name = os.path.basename(rebase_base)
volume_path = os.path.dirname(source_path)
backing_file = os.path.join(volume_path, backing_file_name)
b_file_fmt = images.qemu_img_info(backing_file).file_format b_file_fmt = images.qemu_img_info(backing_file).file_format
qemu_img_extra_arg = ['-F', b_file_fmt] qemu_img_extra_arg = ['-F', b_file_fmt]