From cb658b5e0437d72b1929f7bcbed79795288f5d13 Mon Sep 17 00:00:00 2001 From: Vipin Balachandran Date: Mon, 30 Mar 2015 06:29:03 -0700 Subject: [PATCH] VMware: Fix instance_uuid access in volume retype Retype implementation still uses volume['instance_uuid'] to check in-use volumes. This patch replaces it with a check for non-empty volume['volume_attachment'] list. Change-Id: I268d30ed259a04f8bcf05fb0d45ba1d8e8332c34 Closes-Bug: #1438185 --- cinder/tests/test_vmware_vmdk.py | 19 +++++++++++++++++-- cinder/volume/drivers/vmware/vmdk.py | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_vmware_vmdk.py b/cinder/tests/test_vmware_vmdk.py index e32719c1f..5f8715480 100644 --- a/cinder/tests/test_vmware_vmdk.py +++ b/cinder/tests/test_vmware_vmdk.py @@ -1223,6 +1223,20 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): get_volume_group_folder, generate_uuid, delete_temp_backing) + def test_in_use(self): + # Test with in-use volume. + vol = {'size': 1, 'status': 'in-use', 'name': 'vol-1', + 'volume_type_id': 'def'} + vol['volume_attachment'] = [mock.sentinel.volume_attachment] + self.assertTrue(self._driver._in_use(vol)) + + # Test with available volume. + vol['status'] = 'available' + vol['volume_attachment'] = None + self.assertFalse(self._driver._in_use(vol)) + vol['volume_attachment'] = [] + self.assertFalse(self._driver._in_use(vol)) + def _test_retype(self, ds_sel, vops, get_volume_type_extra_specs, get_volume_group_folder, genereate_uuid, delete_temp_backing): @@ -1234,13 +1248,14 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): # Test with in-use volume. vol = {'size': 1, 'status': 'retyping', 'name': 'vol-1', - 'volume_type_id': 'def', 'instance_uuid': '583a8dbb'} + 'volume_type_id': 'def'} + vol['volume_attachment'] = [mock.sentinel.volume_attachment] self.assertFalse(self._driver.retype(context, vol, new_type, diff, host)) # Test with no backing. vops.get_backing.return_value = None - vol['instance_uuid'] = None + vol['volume_attachment'] = None self.assertTrue(self._driver.retype(context, vol, new_type, diff, host)) diff --git a/cinder/volume/drivers/vmware/vmdk.py b/cinder/volume/drivers/vmware/vmdk.py index a9b3c47c8..8c2cad192 100644 --- a/cinder/volume/drivers/vmware/vmdk.py +++ b/cinder/volume/drivers/vmware/vmdk.py @@ -1350,7 +1350,8 @@ class VMwareEsxVmdkDriver(driver.VolumeDriver): def _in_use(self, volume): """Check if the given volume is in use.""" - return volume['instance_uuid'] is not None + return (volume['volume_attachment'] and + len(volume['volume_attachment']) > 0) def retype(self, ctxt, volume, new_type, diff, host): """Convert the volume to be of the new type. -- 2.45.2