]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VMware: Fixed upload-to-image for available volume
authorSubramanian Neelakantan <subbu@ubuntu.(none)>
Wed, 9 Oct 2013 10:53:52 +0000 (03:53 -0700)
committerSubramanian Neelakantan <subramanian.neelakantan@gmail.com>
Sat, 12 Oct 2013 04:21:24 +0000 (09:51 +0530)
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
cinder/volume/drivers/vmware/vmdk.py

index dcdac98407748bafde90b6106941aca90ad075e9..ca4e5fd0fc214bf304cec7d374ec8bfe355f82c6 100644 (file)
@@ -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')
index 7f407d6868dfd99f2be0b23995faaa2cffac63f0..1681498c41cdc266b9c8cd559fc5053b814e368f 100644 (file)
@@ -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'])