Fixes bug #
1004382
When attach a volume , the volume status is "available -> attaching ->
in-use", But when detaching a volume , the volume status is "in-use ->
available". So We need 'detaching' volume status, it make the change of
state of the volume more clearly.
Change-Id: Idf8c38413135bf8e8cd025f11937f8c7250557c1
self.volume_api.unreserve_volume(context, volume)
return webob.Response(status_int=202)
+ @wsgi.action('os-begin_detaching')
+ def _begin_detaching(self, req, id, body):
+ """Update volume status to 'detaching'."""
+ context = req.environ['cinder.context']
+ volume = self.volume_api.get(context, id)
+ self.volume_api.begin_detaching(context, volume)
+ return webob.Response(status_int=202)
+
+ @wsgi.action('os-roll_detaching')
+ def _roll_detaching(self, req, id, body):
+ """Roll back volume status to 'in-use'."""
+ context = req.environ['cinder.context']
+ volume = self.volume_api.get(context, id)
+ self.volume_api.roll_detaching(context, volume)
+ return webob.Response(status_int=202)
+
@wsgi.action('os-initialize_connection')
def _initialize_connection(self, req, id, body):
"""Initialize volume attachment."""
"volume:detach": [],
"volume:reserve_volume": [],
"volume:unreserve_volume": [],
+ "volume:begin_detaching": [],
+ "volume:roll_detaching": [],
"volume:check_attach": [],
"volume:check_detach": [],
"volume:initialize_connection": [],
self.assertTrue('created_at' in payload)
self.volume.delete_volume(self.context, volume_id)
+ def test_begin_roll_detaching_volume(self):
+ """Test begin_detaching and roll_detaching functions."""
+ volume = self._create_volume()
+ volume_api = cinder.volume.api.API()
+ volume_api.begin_detaching(self.context, volume)
+ volume = db.volume_get(self.context, volume['id'])
+ self.assertEqual(volume['status'], "detaching")
+ volume_api.roll_detaching(self.context, volume)
+ volume = db.volume_get(self.context, volume['id'])
+ self.assertEqual(volume['status'], "in-use")
+
class DriverTestCase(test.TestCase):
"""Base Test class for Drivers."""
if volume['status'] == "attaching":
self.update(context, volume, {"status": "available"})
+ @wrap_check_policy
+ def begin_detaching(self, context, volume):
+ self.update(context, volume, {"status": "detaching"})
+
+ @wrap_check_policy
+ def roll_detaching(self, context, volume):
+ if volume['status'] == "detaching":
+ self.update(context, volume, {"status": "in-use"})
+
@wrap_check_policy
def attach(self, context, volume, instance_uuid, mountpoint):
host = volume['host']