]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix begin_detach logic
authorRyan McNair <rdmcnair@us.ibm.com>
Thu, 3 Jul 2014 04:35:05 +0000 (04:35 +0000)
committerRyan McNair <rdmcnair@us.ibm.com>
Thu, 3 Jul 2014 04:36:29 +0000 (04:36 +0000)
Fix begin_detach logic so it checks that a volume is in-use AND
attached.

Change-Id: I6f0e584070a5fc02c55c26ea92cb8b0c2a2cda3e
Closes-Bug: #1337088

cinder/tests/test_volume.py
cinder/volume/api.py

index 9784714e3e7594755628933a07d948d1aef31806..febe19ab6d83c14340b5fa537adec52b1272d2ac 100644 (file)
@@ -2199,6 +2199,14 @@ class VolumeTestCase(BaseVolumeTestCase):
         volume = tests_utils.create_volume(self.context, **self.volume_params)
         self.assertRaises(exception.InvalidVolume, volume_api.begin_detaching,
                           self.context, volume)
+        volume['status'] = "in-use"
+        volume['attach_status'] = "detached"
+        # Should raise an error since not attached
+        self.assertRaises(exception.InvalidVolume, volume_api.begin_detaching,
+                          self.context, volume)
+        volume['attach_status'] = "attached"
+        # Ensure when attached no exception raised
+        volume_api.begin_detaching(self.context, volume)
 
     def test_begin_roll_detaching_volume(self):
         """Test begin_detaching and roll_detaching functions."""
index 39e9d9fc51d834537dbc950b892c049c60247256..4739b46147c9ad9602267dd0c62f608ad07a1dfe 100644 (file)
@@ -392,10 +392,10 @@ class API(base.Base):
         if volume['migration_status']:
             return
 
-        if (volume['status'] != 'in-use' and
+        if (volume['status'] != 'in-use' or
                 volume['attach_status'] != 'attached'):
             msg = (_("Unable to detach volume. Volume status must be 'in-use' "
-                     "and attached_status must be 'attached' to detach. "
+                     "and attach_status must be 'attached' to detach. "
                      "Currently: status: '%(status)s', "
                      "attach_status: '%(attach_status)s'") %
                    {'status': volume['status'],