Merge "Implement reset-state (os-reset_status) action"

This commit is contained in:
Jenkins 2013-06-25 20:36:00 +00:00 committed by Gerrit Code Review
commit 273a829671
8 changed files with 66 additions and 2 deletions

View File

@ -281,8 +281,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

@ -288,8 +288,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

@ -273,6 +273,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

@ -101,6 +101,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):
"""
@ -330,3 +334,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

@ -307,6 +307,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

@ -100,6 +100,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."""
@ -313,3 +317,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})