summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Gibizer <balazs.gibizer@est.tech>2020-07-02 12:13:29 +0200
committerElod Illes <elod.illes@est.tech>2021-06-25 16:37:09 +0000
commite926ec75e29dcdf3b671811533587bba246a8c45 (patch)
treeca38c509eecccb42c3240af223d8c773c1b18c9f
parent7acb9fc562b104c0e2d443e2efd6ab364dfffc8f (diff)
downloadnova-e926ec75e29dcdf3b671811533587bba246a8c45.tar.gz
Use absolute path during qemu img rebase
During an assisted volume snapshot delete request from Cinder nova removes the snapshot from the backing file chain. During that nova checks the existence of such file. However in some cases (see the bug report) the path is relative and therefore os.path.exists fails. This patch makes sure that nova uses the volume absolute path to make the backing file path absolute as well. Closes-Bug #1885528 Change-Id: I58dca95251b607eaff602783fee2fc38e2421944 (cherry picked from commit b9333125790682f9d60bc74fdbb12a098565e7c2) (cherry picked from commit 831abc9f83a2d3f517030f881e7da724417fea93) (cherry picked from commit c2044d4bd0919860aa2d49687ba9c6ef6f7d37e8)
-rw-r--r--nova/tests/unit/virt/libvirt/test_driver.py28
-rw-r--r--nova/virt/libvirt/driver.py11
2 files changed, 33 insertions, 6 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index d6e241c8e6..38a24c1ee7 100644
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -24564,8 +24564,23 @@ class LibvirtVolumeSnapshotTestCase(test.NoDBTestCase):
not running should trigger a blockRebase using qemu-img not libvirt.
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(
- self.dom_xml)
+ dom_xml)
instance = objects.Instance(**self.inst)
snapshot_id = 'snapshot-1234'
@@ -24576,10 +24591,13 @@ class LibvirtVolumeSnapshotTestCase(test.NoDBTestCase):
self.delete_info_1)
mock_disk_op_sema.__enter__.assert_called_once()
- mock_qemu_img_info.assert_called_once_with("snap.img")
- mock_execute.assert_called_once_with('qemu-img', 'rebase',
- '-b', 'snap.img', '-F',
- 'fake_fmt', 'disk1_file')
+ mock_qemu_img_info.assert_called_once_with(
+ "/var/lib/nova/instances/%s/snap.img" % instance.uuid)
+ mock_execute.assert_called_once_with(
+ '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(host.Host, "has_min_version",
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index c9e48b3971..e04d74c806 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -2880,7 +2880,16 @@ class LibvirtDriver(driver.ComputeDriver):
# If the rebased image is going to have a backing file then
# explicitly set the backing file format to avoid any security
# 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
qemu_img_extra_arg = ['-F', b_file_fmt]