Adds snapshot-reset-state command
Partially implements: bp manila-client-enhancements Change-Id: I7be36be35a5eabe38fb4f03d69d89cede75345ab
This commit is contained in:
parent
f091fa4d99
commit
a7a1d9758b
@ -31,6 +31,10 @@ class ShareSnapshot(base.Resource):
|
||||
"""Update this snapshot."""
|
||||
self.manager.update(self, **kwargs)
|
||||
|
||||
def reset_state(self, state):
|
||||
"""Update the snapshot with the privided state."""
|
||||
self.manager.reset_state(self, state)
|
||||
|
||||
def delete(self):
|
||||
"""Delete this snapshot."""
|
||||
self.manager.delete(self)
|
||||
@ -105,3 +109,14 @@ class ShareSnapshotManager(base.ManagerWithFind):
|
||||
|
||||
body = {'snapshot': kwargs, }
|
||||
return self._update("/snapshots/%s" % snapshot.id, body)
|
||||
|
||||
def reset_state(self, snapshot, state):
|
||||
"""Update the specified share 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)
|
||||
|
@ -609,6 +609,21 @@ def do_snapshot_delete(cs, args):
|
||||
snapshot.delete()
|
||||
|
||||
|
||||
@utils.arg('snapshot', metavar='<snapshot>',
|
||||
help='Name or 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('share')
|
||||
def do_snapshot_reset_state(cs, args):
|
||||
"""Explicitly update the state of a snapshot."""
|
||||
snapshot = _find_share_snapshot(cs, args.snapshot)
|
||||
snapshot.reset_state(args.state)
|
||||
|
||||
|
||||
@utils.arg(
|
||||
'share',
|
||||
metavar='<share>',
|
||||
|
@ -43,6 +43,17 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
snapshot = {'snapshot': {'id': 1234, 'name': 'sharename'}}
|
||||
return (200, {}, snapshot)
|
||||
|
||||
def post_snapshots_1234_action(self, body, **kw):
|
||||
_body = None
|
||||
resp = 202
|
||||
assert len(list(body)) == 1
|
||||
action = list(body)[0]
|
||||
if action == 'os-reset_status':
|
||||
assert 'status' in body['os-reset_status']
|
||||
else:
|
||||
raise AssertionError("Unexpected action: %s" % action)
|
||||
return (resp, {}, _body)
|
||||
|
||||
def get_snapshots_detail(self, **kw):
|
||||
print kw
|
||||
# print kw['share_id']
|
||||
|
@ -194,3 +194,12 @@ class ShellTest(utils.TestCase):
|
||||
expected = {'os-reset_status': {'status': 'error'}}
|
||||
self.assert_called('POST', '/shares/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)
|
||||
|
Loading…
Reference in New Issue
Block a user