Skip to content

Commit 5f82c5e

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use absolute path during qemu img rebase" into stable/victoria
2 parents 4a807fe + 831abc9 commit 5f82c5e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26638,8 +26638,23 @@ def test_volume_snapshot_delete_when_dom_not_running(self, mock_execute,
2663826638
not running should trigger a blockRebase using qemu-img not libvirt.
2663926639
In this test, we rebase the image with another image as backing file.
2664026640
"""
26641+
dom_xml = """
26642+
<domain type='kvm'>
26643+
<devices>
26644+
<disk type='file'>
26645+
<source file='/var/lib/nova/instances/%s/disk1_file'/>
26646+
<target dev='vda' bus='virtio'/>
26647+
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
26648+
</disk>
26649+
<disk type='block'>
26650+
<source dev='/path/to/dev/1'/>
26651+
<target dev='vdb' bus='virtio' serial='1234'/>
26652+
</disk>
26653+
</devices>
26654+
</domain>""" % self.inst['uuid']
26655+
2664126656
mock_domain, guest = self._setup_block_rebase_domain_and_guest_mocks(
26642-
self.dom_xml)
26657+
dom_xml)
2664326658

2664426659
instance = objects.Instance(**self.inst)
2664526660
snapshot_id = 'snapshot-1234'
@@ -26650,10 +26665,13 @@ def test_volume_snapshot_delete_when_dom_not_running(self, mock_execute,
2665026665
self.delete_info_1)
2665126666

2665226667
mock_disk_op_sema.__enter__.assert_called_once()
26653-
mock_qemu_img_info.assert_called_once_with("snap.img")
26654-
mock_execute.assert_called_once_with('qemu-img', 'rebase',
26655-
'-b', 'snap.img', '-F',
26656-
'fake_fmt', 'disk1_file')
26668+
mock_qemu_img_info.assert_called_once_with(
26669+
"/var/lib/nova/instances/%s/snap.img" % instance.uuid)
26670+
mock_execute.assert_called_once_with(
26671+
'qemu-img', 'rebase',
26672+
'-b', '/var/lib/nova/instances/%s/snap.img' % instance.uuid,
26673+
'-F', 'fake_fmt',
26674+
'/var/lib/nova/instances/%s/disk1_file' % instance.uuid)
2665726675

2665826676
@mock.patch.object(compute_utils, 'disk_ops_semaphore')
2665926677
@mock.patch.object(host.Host, "has_min_version",

nova/virt/libvirt/driver.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3012,7 +3012,16 @@ def _rebase_with_qemu_img(source_path, rebase_base):
30123012
# If the rebased image is going to have a backing file then
30133013
# explicitly set the backing file format to avoid any security
30143014
# concerns related to file format auto detection.
3015-
backing_file = rebase_base
3015+
if os.path.isabs(rebase_base):
3016+
backing_file = rebase_base
3017+
else:
3018+
# this is a probably a volume snapshot case where the
3019+
# rebase_base is relative. See bug
3020+
# https://bugs.launchpad.net/nova/+bug/1885528
3021+
backing_file_name = os.path.basename(rebase_base)
3022+
volume_path = os.path.dirname(source_path)
3023+
backing_file = os.path.join(volume_path, backing_file_name)
3024+
30163025
b_file_fmt = images.qemu_img_info(backing_file).file_format
30173026
qemu_img_extra_arg = ['-F', b_file_fmt]
30183027

0 commit comments

Comments
 (0)