From a2b774c0ce2a1aaa9cdfc7d7c4c4d642f1bfc3d1 Mon Sep 17 00:00:00 2001 From: Subramanian Neelakantan Date: Wed, 9 Oct 2013 03:53:52 -0700 Subject: [PATCH] VMware: Fixed upload-to-image for available volume Cinder generally does not allow upload-to-image operation on a volume that is 'in-use'. This can however be over-ridden using the '--force True' flag. The VMware driver cannot support upload-to-image when the volume is in-use. This is a restriction for the VMware driver alone. When the user forces an upload on a volume that is 'in-use' the Cinder api layer sets the volume status to 'uploading' and calls into the driver code to upload. In this scenario the VMware driver needs to fail the operation. The current driver code here does this check wrongly by looking for volume status of 'in-use'. Fixing this check to identify an in-use volume correctly. Fixes bug: 1237338 Change-Id: If54edfdc242a7a1bff442b6bb4c5a9865eede1dc --- cinder/tests/test_vmware_vmdk.py | 8 +++++--- cinder/volume/drivers/vmware/vmdk.py | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cinder/tests/test_vmware_vmdk.py b/cinder/tests/test_vmware_vmdk.py index dcdac9840..ca4e5fd0f 100644 --- a/cinder/tests/test_vmware_vmdk.py +++ b/cinder/tests/test_vmware_vmdk.py @@ -1376,7 +1376,8 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): image_meta['disk_format'] = 'novmdk' volume = FakeObject() volume['name'] = 'vol-name' - volume['status'] = 'available' + volume['instance_uuid'] = None + volume['attached_host'] = None m.ReplayAll() self.assertRaises(exception.ImageUnacceptable, @@ -1390,7 +1391,7 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): """Test copy_volume_to_image when volume is attached.""" m = self.mox volume = FakeObject() - volume['status'] = 'in-use' + volume['instance_uuid'] = 'my_uuid' m.ReplayAll() self.assertRaises(exception.InvalidVolume, @@ -1421,7 +1422,8 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): volume = FakeObject() volume['name'] = vol_name volume['project_id'] = project_id - volume['status'] = 'available' + volume['instance_uuid'] = None + volume['attached_host'] = None # volumeops.get_backing backing = FakeMor("VirtualMachine", "my_vm") m.StubOutWithMock(self._volumeops, 'get_backing') diff --git a/cinder/volume/drivers/vmware/vmdk.py b/cinder/volume/drivers/vmware/vmdk.py index 7f407d686..1681498c4 100644 --- a/cinder/volume/drivers/vmware/vmdk.py +++ b/cinder/volume/drivers/vmware/vmdk.py @@ -682,10 +682,10 @@ class VMwareEsxVmdkDriver(driver.VolumeDriver): 4. Delete the coalesced .vmdk and -flat.vmdk created. """ - if volume['status'] != 'available': - msg = _("Upload to glance of volume not supported in state: %s.") - LOG.error(msg % volume['status']) - raise exception.InvalidVolume(msg % volume['status']) + if volume['instance_uuid'] or volume['attached_host']: + msg = _("Upload to glance of attached volume is not supported.") + LOG.error(msg) + raise exception.InvalidVolume(msg) LOG.debug(_("Copy Volume: %s to new image.") % volume['name']) VMwareEsxVmdkDriver._validate_disk_format(image_meta['disk_format']) -- 2.45.2