Skip to content

Commit d86bb10

Browse files
kk7dskarelyatin
authored andcommitted
Remove AMI snapshot format special case
Note that this includes seemingly-unrelated test changes because we were actually skipping the snapshot_running test for libvirt, which has been a bug for years. In that test case, when we went to look for image_meta.disk_format, that attribute was not set on the o.vo object, which raised a NotImplementedError. That error is also checked by the test to skip the test for drivers that do not support snapshot, which meant that for libvirt, we haven't been running that case beyond the point at which we create snapshot metadata and trip that exception. Thus, once removing that, there are other mocks not in place that are required for the test to actually run. So, this adds mocks for qemu_img_info() calls that actually try to read the file on disk, as well as the privsep chown() that attempts to run after. Change-Id: Ie731045629f0899840a4680d21793a16ade9b98e (cherry picked from commit d5a631b) (cherry picked from commit 8c5929f) (cherry picked from commit d2d3b2c) (cherry picked from commit 77dfa4f) (cherry picked from commit e6f4503)
1 parent da19167 commit d86bb10

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8848,7 +8848,7 @@ def test_unquiesce(self, mock_has_min_version):
88488848

88498849
def test_create_snapshot_metadata(self):
88508850
base = objects.ImageMeta.from_dict(
8851-
{'disk_format': 'raw'})
8851+
{'disk_format': 'qcow2'})
88528852
instance_data = {'kernel_id': 'kernel',
88538853
'project_id': 'prj_id',
88548854
'ramdisk_id': 'ram_id',
@@ -8880,10 +8880,12 @@ def test_create_snapshot_metadata(self):
88808880
{'disk_format': 'ami',
88818881
'container_format': 'test_container'})
88828882
expected['properties']['os_type'] = instance['os_type']
8883-
expected['disk_format'] = base.disk_format
8883+
# The disk_format of the snapshot should be the *actual* format of the
8884+
# thing we upload, regardless of what type of image we booted from.
8885+
expected['disk_format'] = img_fmt
88848886
expected['container_format'] = base.container_format
88858887
ret = drvr._create_snapshot_metadata(base, instance, img_fmt, snp_name)
8886-
self.assertEqual(ret, expected)
8888+
self.assertEqual(expected, ret)
88878889

88888890
def test_get_volume_driver(self):
88898891
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
@@ -28225,7 +28227,8 @@ def test_ami(self):
2822528227
utils.get_system_metadata_from_image(
2822628228
{'disk_format': 'ami'})
2822728229

28228-
self._test_snapshot(disk_format='ami')
28230+
# If we're uploading a qcow2, we must set the disk_format as such
28231+
self._test_snapshot(disk_format='qcow2')
2822928232

2823028233
@mock.patch('nova.virt.libvirt.utils.get_disk_type_from_path',
2823128234
new=mock.Mock(return_value=None))

nova/tests/unit/virt/test_virt_drivers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ def setUp(self):
838838
# since we don't care about it.
839839
self.stub_out('os_vif.unplug', lambda a, kw: None)
840840
self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
841+
self.stub_out('nova.virt.libvirt.utils.get_disk_size',
842+
lambda *a, **k: 123456)
843+
self.stub_out('nova.virt.libvirt.utils.get_disk_backing_file',
844+
lambda *a, **k: None)
845+
self.stub_out('nova.privsep.path.chown', lambda *a, **k: None)
841846

842847
def test_init_host_image_type_rbd_force_raw_images_true(self):
843848
CONF.set_override('images_type', 'rbd', group='libvirt')

nova/virt/libvirt/driver.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,11 +2929,7 @@ def _create_snapshot_metadata(self, image_meta, instance,
29292929
if instance.os_type:
29302930
metadata['properties']['os_type'] = instance.os_type
29312931

2932-
# NOTE(vish): glance forces ami disk format to be ami
2933-
if image_meta.disk_format == 'ami':
2934-
metadata['disk_format'] = 'ami'
2935-
else:
2936-
metadata['disk_format'] = img_fmt
2932+
metadata['disk_format'] = img_fmt
29372933

29382934
if image_meta.obj_attr_is_set("container_format"):
29392935
metadata['container_format'] = image_meta.container_format

0 commit comments

Comments
 (0)