From 869e71c31a6e2c1753796625b060fa39848af683 Mon Sep 17 00:00:00 2001 From: Vipin Balachandran Date: Thu, 15 Jan 2015 00:33:52 +0530 Subject: [PATCH] VMware: Fail immediately for images in a container Currently VMDK driver doesn't support images within a container such as OVA. Instead of throwing an error immediately, the driver tries to create a backing using the container as its vmdk. This will eventually fail with vCenter error. This patch fixes it. Change-Id: Ie97a3a63807d00880310f2a7e5f6d32ee89d2cd7 Closes-Bug: #1371478 --- cinder/tests/test_vmware_vmdk.py | 28 ++++++++++++++++++++++++++++ cinder/volume/drivers/vmware/vmdk.py | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/cinder/tests/test_vmware_vmdk.py b/cinder/tests/test_vmware_vmdk.py index 22afee25e..00503841d 100644 --- a/cinder/tests/test_vmware_vmdk.py +++ b/cinder/tests/test_vmware_vmdk.py @@ -1141,6 +1141,7 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): fake_volume_size = 1 + size_gb adapter_type = 'ide' fake_image_meta = {'disk_format': 'vmdk', 'size': size, + 'container_format': 'bare', 'properties': {'vmware_disktype': 'streamOptimized', 'vmware_adaptertype': adapter_type}} image_service = mock.Mock(glance.GlanceImageService) @@ -2461,6 +2462,33 @@ class VMwareVcVmdkDriverTestCase(VMwareEsxVmdkDriverTestCase): _extend_virtual_disk, download_image) + def test_copy_image_to_volume_with_ova_container(self): + image_service = mock.Mock(glance.GlanceImageService) + image_size = 2 * units.Gi + adapter_type = 'ide' + image_meta = {'disk_format': 'vmdk', 'size': image_size, + 'container_format': 'ova', + 'properties': {'vmware_disktype': 'streamOptimized', + 'vmware_adaptertype': adapter_type}} + image_service.show.return_value = image_meta + + context = mock.sentinel.context + vol_name = 'volume-51e47214-8e3c-475d-b44b-aea6cd3eef53' + vol_id = '51e47214-8e3c-475d-b44b-aea6cd3eef53' + display_name = 'foo' + volume_size = 4 + volume = {'name': vol_name, + 'id': vol_id, + 'display_name': display_name, + 'size': volume_size, + 'volume_type_id': None} + image_id = 'image-id' + + self.assertRaises( + cinder_exceptions.ImageUnacceptable, + self._driver.copy_image_to_volume, context, volume, image_service, + image_id) + @mock.patch.object(VMDK_DRIVER, '_delete_temp_backing') @mock.patch('oslo_utils.uuidutils.generate_uuid') @mock.patch.object(VMDK_DRIVER, '_get_volume_group_folder') diff --git a/cinder/volume/drivers/vmware/vmdk.py b/cinder/volume/drivers/vmware/vmdk.py index 02a87e87c..36e1ad3b4 100644 --- a/cinder/volume/drivers/vmware/vmdk.py +++ b/cinder/volume/drivers/vmware/vmdk.py @@ -1288,6 +1288,14 @@ class VMwareEsxVmdkDriver(driver.VolumeDriver): metadata = image_service.show(context, image_id) VMwareEsxVmdkDriver._validate_disk_format(metadata['disk_format']) + # Validate container format; only 'bare' is supported currently. + container_format = metadata.get('container_format') + if (container_format and container_format != 'bare'): + msg = _("Container format: %s is unsupported, only 'bare' is " + "supported.") % container_format + LOG.error(msg) + raise exception.ImageUnacceptable(image_id=image_id, reason=msg) + # Get the disk type, adapter type and size of vmdk image image_disk_type = ImageDiskType.PREALLOCATED image_adapter_type = volumeops.VirtualDiskAdapterType.LSI_LOGIC -- 2.45.2