Skip to content

Commit

Permalink
Add 'detaching' to volume status
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zhurongze committed Aug 23, 2012
1 parent 4e81c90 commit 5475deb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cinder/api/openstack/volume/contrib/volume_actions.py
Expand Up @@ -110,6 +110,22 @@ def _unreserve(self, req, id, body):
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."""
Expand Down
2 changes: 2 additions & 0 deletions cinder/tests/policy.json
Expand Up @@ -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": [],
Expand Down
11 changes: 11 additions & 0 deletions cinder/tests/test_volume.py
Expand Up @@ -614,6 +614,17 @@ def test_create_volume_usage_notification(self):
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."""
Expand Down
9 changes: 9 additions & 0 deletions cinder/volume/api.py
Expand Up @@ -313,6 +313,15 @@ def unreserve_volume(self, context, volume):
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']
Expand Down

0 comments on commit 5475deb

Please sign in to comment.