Enable ability to reset state on snapshots.
Implement the ability to reset-state on snapshots, exposes os-reset_status from snapshot actions. Change-Id: I605f41e39fde46ccfe6a53222b798f32c14bc1f8
This commit is contained in:
parent
273a829671
commit
ee9f0354ec
@ -231,6 +231,17 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
snapshot.update(kw['body']['snapshot'])
|
snapshot.update(kw['body']['snapshot'])
|
||||||
return (200, {}, {'snapshot': snapshot})
|
return (200, {}, {'snapshot': snapshot})
|
||||||
|
|
||||||
|
def post_snapshots_1234_action(self, body, **kw):
|
||||||
|
_body = None
|
||||||
|
resp = 202
|
||||||
|
assert len(body.keys()) == 1
|
||||||
|
action = body.keys()[0]
|
||||||
|
if action == 'os-reset_status':
|
||||||
|
assert 'status' in body['os-reset_status']
|
||||||
|
else:
|
||||||
|
raise AssertionError('Unexpected action: %s" % action')
|
||||||
|
return (resp, {}, _body)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Volumes
|
# Volumes
|
||||||
#
|
#
|
||||||
|
@ -189,3 +189,13 @@ class ShellTest(utils.TestCase):
|
|||||||
self.run_command('reset-state --state error 1234')
|
self.run_command('reset-state --state error 1234')
|
||||||
expected = {'os-reset_status': {'status': 'error'}}
|
expected = {'os-reset_status': {'status': 'error'}}
|
||||||
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
||||||
|
|
||||||
|
def test_snapshot_reset_state(self):
|
||||||
|
self.run_command('snapshot-reset-state 1234')
|
||||||
|
expected = {'os-reset_status': {'status': 'available'}}
|
||||||
|
self.assert_called('POST', '/snapshots/1234/action', body=expected)
|
||||||
|
|
||||||
|
def test_snapshot_reset_state_with_flag(self):
|
||||||
|
self.run_command('snapshot-reset-state --state error 1234')
|
||||||
|
expected = {'os-reset_status': {'status': 'error'}}
|
||||||
|
self.assert_called('POST', '/snapshots/1234/action', body=expected)
|
||||||
|
@ -238,6 +238,17 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
snapshot.update(kw['body']['snapshot'])
|
snapshot.update(kw['body']['snapshot'])
|
||||||
return (200, {}, {'snapshot': snapshot})
|
return (200, {}, {'snapshot': snapshot})
|
||||||
|
|
||||||
|
def post_snapshots_1234_action(self, body, **kw):
|
||||||
|
_body = None
|
||||||
|
resp = 202
|
||||||
|
assert len(body.keys()) == 1
|
||||||
|
action = body.keys()[0]
|
||||||
|
if action == 'os-reset_status':
|
||||||
|
assert 'status' in body['os-reset_status']
|
||||||
|
else:
|
||||||
|
raise AssertionError('Unexpected action: %s" % action')
|
||||||
|
return (resp, {}, _body)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Volumes
|
# Volumes
|
||||||
#
|
#
|
||||||
|
@ -167,3 +167,13 @@ class ShellTest(utils.TestCase):
|
|||||||
self.run_command('reset-state --state error 1234')
|
self.run_command('reset-state --state error 1234')
|
||||||
expected = {'os-reset_status': {'status': 'error'}}
|
expected = {'os-reset_status': {'status': 'error'}}
|
||||||
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
||||||
|
|
||||||
|
def test_snapshot_reset_state(self):
|
||||||
|
self.run_command('snapshot-reset-state 1234')
|
||||||
|
expected = {'os-reset_status': {'status': 'available'}}
|
||||||
|
self.assert_called('POST', '/snapshots/1234/action', body=expected)
|
||||||
|
|
||||||
|
def test_snapshot_reset_state_with_flag(self):
|
||||||
|
self.run_command('snapshot-reset-state --state error 1234')
|
||||||
|
expected = {'os-reset_status': {'status': 'error'}}
|
||||||
|
self.assert_called('POST', '/snapshots/1234/action', body=expected)
|
||||||
|
@ -443,6 +443,21 @@ def do_snapshot_rename(cs, args):
|
|||||||
_find_volume_snapshot(cs, args.snapshot).update(**kwargs)
|
_find_volume_snapshot(cs, args.snapshot).update(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('snapshot', metavar='<snapshot>',
|
||||||
|
help='ID of the snapshot to modify.')
|
||||||
|
@utils.arg('--state', metavar='<state>',
|
||||||
|
default='available',
|
||||||
|
help=('Indicate which state to assign the snapshot. '
|
||||||
|
'Options include available, error, creating, deleting, '
|
||||||
|
'error_deleting. If no state is provided, '
|
||||||
|
'available will be used.'))
|
||||||
|
@utils.service_type('volume')
|
||||||
|
def do_snapshot_reset_state(cs, args):
|
||||||
|
"""Explicitly update the state of a snapshot."""
|
||||||
|
snapshot = _find_volume_snapshot(cs, args.snapshot)
|
||||||
|
snapshot.reset_state(args.state)
|
||||||
|
|
||||||
|
|
||||||
def _print_volume_type_list(vtypes):
|
def _print_volume_type_list(vtypes):
|
||||||
utils.print_list(vtypes, ['ID', 'Name'])
|
utils.print_list(vtypes, ['ID', 'Name'])
|
||||||
|
|
||||||
|
@ -53,6 +53,10 @@ class Snapshot(base.Resource):
|
|||||||
def project_id(self):
|
def project_id(self):
|
||||||
return self._info.get('os-extended-snapshot-attributes:project_id')
|
return self._info.get('os-extended-snapshot-attributes:project_id')
|
||||||
|
|
||||||
|
def reset_state(self, state):
|
||||||
|
"""Update the snapshot with the privided state."""
|
||||||
|
self.manager.reset_state(self, state)
|
||||||
|
|
||||||
|
|
||||||
class SnapshotManager(base.ManagerWithFind):
|
class SnapshotManager(base.ManagerWithFind):
|
||||||
"""
|
"""
|
||||||
@ -133,3 +137,14 @@ class SnapshotManager(base.ManagerWithFind):
|
|||||||
body = {"snapshot": kwargs}
|
body = {"snapshot": kwargs}
|
||||||
|
|
||||||
self._update("/snapshots/%s" % base.getid(snapshot), body)
|
self._update("/snapshots/%s" % base.getid(snapshot), body)
|
||||||
|
|
||||||
|
def reset_state(self, snapshot, state):
|
||||||
|
"""Update the specified volume with the provided state."""
|
||||||
|
return self._action('os-reset_status', snapshot, {'status': state})
|
||||||
|
|
||||||
|
def _action(self, action, snapshot, info=None, **kwargs):
|
||||||
|
"""Perform a snapshot action."""
|
||||||
|
body = {action: info}
|
||||||
|
self.run_hooks('modify_body_for_action', body, **kwargs)
|
||||||
|
url = '/snapshots/%s/action' % base.getid(snapshot)
|
||||||
|
return self.api.client.post(url, body=body)
|
||||||
|
@ -512,6 +512,21 @@ def do_snapshot_rename(cs, args):
|
|||||||
_find_volume_snapshot(cs, args.snapshot).update(**kwargs)
|
_find_volume_snapshot(cs, args.snapshot).update(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('snapshot', metavar='<snapshot>',
|
||||||
|
help='ID of the snapshot to modify.')
|
||||||
|
@utils.arg('--state', metavar='<state>',
|
||||||
|
default='available',
|
||||||
|
help=('Indicate which state to assign the snapshot. '
|
||||||
|
'Options include available, error, creating, '
|
||||||
|
'deleting, error_deleting. If no state is provided, '
|
||||||
|
'available will be used.'))
|
||||||
|
@utils.service_type('snapshot')
|
||||||
|
def do_snapshot_reset_state(cs, args):
|
||||||
|
"""Explicitly update the state of a snapshot."""
|
||||||
|
snapshot = _find_volume_snapshot(cs, args.snapshot)
|
||||||
|
snapshot.reset_state(args.state)
|
||||||
|
|
||||||
|
|
||||||
def _print_volume_type_list(vtypes):
|
def _print_volume_type_list(vtypes):
|
||||||
utils.print_list(vtypes, ['ID', 'Name'])
|
utils.print_list(vtypes, ['ID', 'Name'])
|
||||||
|
|
||||||
|
@ -45,6 +45,10 @@ class Snapshot(base.Resource):
|
|||||||
def project_id(self):
|
def project_id(self):
|
||||||
return self._info.get('os-extended-snapshot-attributes:project_id')
|
return self._info.get('os-extended-snapshot-attributes:project_id')
|
||||||
|
|
||||||
|
def reset_state(self, state):
|
||||||
|
"""Update the snapshot with the provided state."""
|
||||||
|
self.manager.reset_state(self, state)
|
||||||
|
|
||||||
|
|
||||||
class SnapshotManager(base.ManagerWithFind):
|
class SnapshotManager(base.ManagerWithFind):
|
||||||
"""Manage :class:`Snapshot` resources."""
|
"""Manage :class:`Snapshot` resources."""
|
||||||
@ -118,3 +122,14 @@ class SnapshotManager(base.ManagerWithFind):
|
|||||||
body = {"snapshot": kwargs}
|
body = {"snapshot": kwargs}
|
||||||
|
|
||||||
self._update("/snapshots/%s" % base.getid(snapshot), body)
|
self._update("/snapshots/%s" % base.getid(snapshot), body)
|
||||||
|
|
||||||
|
def reset_state(self, snapshot, state):
|
||||||
|
"""Update the specified snapshot with the provided state."""
|
||||||
|
return self._action('os-reset_status', snapshot, {'status': state})
|
||||||
|
|
||||||
|
def _action(self, action, snapshot, info=None, **kwargs):
|
||||||
|
"""Perform a snapshot action."""
|
||||||
|
body = {action: info}
|
||||||
|
self.run_hooks('modify_body_for_action', body, **kwargs)
|
||||||
|
url = '/snapshots/%s/action' % base.getid(snapshot)
|
||||||
|
return self.api.client.post(url, body=body)
|
||||||
|
Loading…
Reference in New Issue
Block a user