Implement reset-state (os-reset_status) action

This change implements a reset-state method in the
cinderclient which exposes the extension: os-reset_status
from the Cinder API.

Fix bug 1190731

Change-Id: I8f631f0f19ca16e0fdd1e3adcf923cc684292887
This commit is contained in:
Brian Waldon 2013-06-13 15:55:16 -07:00 committed by John Griffith
parent 046ea37f93
commit 7571232c02
8 changed files with 66 additions and 2 deletions

View File

@ -234,8 +234,10 @@ class FakeHTTPClient(base_client.HTTPClient):
assert body[action] is None
elif action == 'os-roll_detaching':
assert body[action] is None
elif action == 'os-reset_status':
assert 'status' in body[action]
else:
raise AssertionError("Unexpected server action: %s" % action)
raise AssertionError("Unexpected action: %s" % action)
return (resp, {}, _body)
def post_volumes(self, **kw):

View File

@ -179,3 +179,13 @@ class ShellTest(utils.TestCase):
self.run_command('metadata 1234 unset key1 key2')
self.assert_called('DELETE', '/volumes/1234/metadata/key1')
self.assert_called('DELETE', '/volumes/1234/metadata/key2', pos=-2)
def test_reset_state(self):
self.run_command('reset-state 1234')
expected = {'os-reset_status': {'status': 'available'}}
self.assert_called('POST', '/volumes/1234/action', body=expected)
def test_reset_state_with_flag(self):
self.run_command('reset-state --state error 1234')
expected = {'os-reset_status': {'status': 'error'}}
self.assert_called('POST', '/volumes/1234/action', body=expected)

View File

@ -241,8 +241,10 @@ class FakeHTTPClient(base_client.HTTPClient):
assert body[action] is None
elif action == 'os-roll_detaching':
assert body[action] is None
elif action == 'os-reset_status':
assert 'status' in body[action]
else:
raise AssertionError("Unexpected server action: %s" % action)
raise AssertionError("Unexpected action: %s" % action)
return (resp, {}, _body)
def post_volumes(self, **kw):

View File

@ -157,3 +157,13 @@ class ShellTest(utils.TestCase):
self.run_command('metadata 1234 unset key1 key2')
self.assert_called('DELETE', '/volumes/1234/metadata/key1')
self.assert_called('DELETE', '/volumes/1234/metadata/key2', pos=-2)
def test_reset_state(self):
self.run_command('reset-state 1234')
expected = {'os-reset_status': {'status': 'available'}}
self.assert_called('POST', '/volumes/1234/action', body=expected)
def test_reset_state_with_flag(self):
self.run_command('reset-state --state error 1234')
expected = {'os-reset_status': {'status': 'error'}}
self.assert_called('POST', '/volumes/1234/action', body=expected)

View File

@ -268,6 +268,18 @@ def do_force_delete(cs, args):
volume.force_delete()
@utils.arg('volume', metavar='<volume>', help='ID of the volume to modify.')
@utils.arg('--state', metavar='<state>', default='available',
help=('Indicate which state to assign the volume. Options include '
'available, error, creating, deleting, error_deleting. If no '
'state is provided, available will be used.'))
@utils.service_type('volume')
def do_reset_state(cs, args):
"""Explicitly update the state of a volume."""
volume = _find_volume(cs, args.volume)
volume.reset_state(args.state)
@utils.arg('volume', metavar='<volume>', help='ID of the volume to rename.')
@utils.arg('display_name', nargs='?', metavar='<display-name>',
help='New display-name for the volume.')

View File

@ -98,6 +98,10 @@ class Volume(base.Resource):
"""
self.manager.force_delete(self)
def reset_state(self, state):
"""Update the volume with the provided state."""
self.manager.reset_state(self, state)
class VolumeManager(base.ManagerWithFind):
"""
@ -327,3 +331,7 @@ class VolumeManager(base.ManagerWithFind):
def force_delete(self, volume):
return self._action('os-force_delete', base.getid(volume))
def reset_state(self, volume, state):
"""Update the provided volume with the provided state."""
return self._action('os-reset_status', volume, {'status': state})

View File

@ -278,6 +278,18 @@ def do_force_delete(cs, args):
volume.force_delete()
@utils.arg('volume', metavar='<volume>', help='ID of the volume to modify.')
@utils.arg('--state', metavar='<state>', default='available',
help=('Indicate which state to assign the volume. Options include '
'available, error, creating, deleting, error_deleting. If no '
'state is provided, available will be used.'))
@utils.service_type('volume')
def do_reset_state(cs, args):
"""Explicitly update the state of a volume."""
volume = _find_volume(cs, args.volume)
volume.reset_state(args.state)
@utils.arg('volume',
metavar='<volume>',
help='ID of the volume to rename.')

View File

@ -97,6 +97,10 @@ class Volume(base.Resource):
"""
self.manager.force_delete(self)
def reset_state(self, state):
"""Update the volume with the provided state."""
self.manager.reset_state(self, state)
class VolumeManager(base.ManagerWithFind):
"""Manage :class:`Volume` resources."""
@ -307,3 +311,7 @@ class VolumeManager(base.ManagerWithFind):
def force_delete(self, volume):
return self._action('os-force_delete', base.getid(volume))
def reset_state(self, volume, state):
"""Update the provided volume with the provided state."""
return self._action('os-reset_status', volume, {'status': state})