From: Ryan McNair Date: Thu, 3 Jul 2014 04:35:05 +0000 (+0000) Subject: Fix begin_detach logic X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=87cd23419bdd5724e742eda21bc23876b558e0d1;p=openstack-build%2Fcinder-build.git Fix begin_detach logic Fix begin_detach logic so it checks that a volume is in-use AND attached. Change-Id: I6f0e584070a5fc02c55c26ea92cb8b0c2a2cda3e Closes-Bug: #1337088 --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 9784714e3..febe19ab6 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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.""" diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 39e9d9fc5..4739b4614 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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'],