]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add 'detaching' to volume status
authorRongze Zhu <zrzhit@gmail.com>
Tue, 21 Aug 2012 15:07:02 +0000 (15:07 +0000)
committerRongze Zhu <zrzhit@gmail.com>
Thu, 23 Aug 2012 16:49:23 +0000 (16:49 +0000)
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

cinder/api/openstack/volume/contrib/volume_actions.py
cinder/tests/policy.json
cinder/tests/test_volume.py
cinder/volume/api.py

index 30fb1c250920ad5910e871543b9a54f83d1798dc..5c6276646cea81ff56dd6edc3a44e9a4d851c643 100644 (file)
@@ -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."""
index 93162d445f742f017363b3f3dd95b40f5ee20e90..43ec1a19a0910db8465656f6c390bfd58e58f511 100644 (file)
@@ -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": [],
index 4f117902d7a9a53c44f3da05ddc9ead39da8e21d..45ffa73b9d233a40a3f7db50bb2b7ad4dbee10ea 100644 (file)
@@ -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."""
index 79132a63be1f148f819d7e3715d90a7a6a594072..480086c7d00ff23e0dd45eea76c3aca73f14c9c6 100644 (file)
@@ -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']