]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VMware: Fix instance_uuid access in volume retype
authorVipin Balachandran <vbala@vmware.com>
Mon, 30 Mar 2015 13:29:03 +0000 (06:29 -0700)
committerVipin Balachandran <vbala@vmware.com>
Tue, 31 Mar 2015 05:57:34 +0000 (22:57 -0700)
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
cinder/volume/drivers/vmware/vmdk.py

index e32719c1fcd7eddccd82d54ad0c745b5fbe650f7..5f8715480ac43ebd76237ed1a14413dc252e0ba7 100644 (file)
@@ -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))
 
index a9b3c47c80015a5e4c908bf0caeed94ce9c23b8b..8c2cad1927168b3e615d73d6a66d77def5b5a01f 100644 (file)
@@ -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.