From: Rongze Zhu Date: Tue, 21 Aug 2012 15:07:02 +0000 (+0000) Subject: Add 'detaching' to volume status X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5475debcf706e87b1df926d489b72074662614f3;p=openstack-build%2Fcinder-build.git Add 'detaching' to volume status 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 --- diff --git a/cinder/api/openstack/volume/contrib/volume_actions.py b/cinder/api/openstack/volume/contrib/volume_actions.py index 30fb1c250..5c6276646 100644 --- a/cinder/api/openstack/volume/contrib/volume_actions.py +++ b/cinder/api/openstack/volume/contrib/volume_actions.py @@ -110,6 +110,22 @@ class VolumeActionsController(wsgi.Controller): 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.""" diff --git a/cinder/tests/policy.json b/cinder/tests/policy.json index 93162d445..43ec1a19a 100644 --- a/cinder/tests/policy.json +++ b/cinder/tests/policy.json @@ -11,6 +11,8 @@ "volume:detach": [], "volume:reserve_volume": [], "volume:unreserve_volume": [], + "volume:begin_detaching": [], + "volume:roll_detaching": [], "volume:check_attach": [], "volume:check_detach": [], "volume:initialize_connection": [], diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 4f117902d..45ffa73b9 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -614,6 +614,17 @@ class VolumeTestCase(test.TestCase): 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.""" diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 79132a63b..480086c7d 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -313,6 +313,15 @@ class API(base.Base): 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']