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

(cherry picked from commit a2b774c0ce)

Change-Id: If54edfdc242a7a1bff442b6bb4c5a9865eede1dc
This commit is contained in:
Subramanian Neelakantan 2013-10-09 03:53:52 -07:00 committed by Gerrit Code Review
parent 2b8f7ae980
commit 62d4e54a24
2 changed files with 9 additions and 7 deletions

View 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')

View 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'])