Merge "Implement restore operation"
This commit is contained in:
@@ -1844,6 +1844,32 @@ class ShellTestUserPass(ShellBase):
|
|||||||
resp = self.shell('snapshot-delete teststack/1 2')
|
resp = self.shell('snapshot-delete teststack/1 2')
|
||||||
self.assertEqual("", resp)
|
self.assertEqual("", resp)
|
||||||
|
|
||||||
|
@httpretty.activate
|
||||||
|
def test_stack_restore(self):
|
||||||
|
self.register_keystone_auth_fixture()
|
||||||
|
|
||||||
|
stack_dict = {"stack": {
|
||||||
|
"id": "1",
|
||||||
|
"stack_name": "teststack",
|
||||||
|
"stack_status": 'CREATE_COMPLETE',
|
||||||
|
"creation_time": "2012-10-25T01:58:47Z"
|
||||||
|
}}
|
||||||
|
|
||||||
|
resp = fakes.FakeHTTPResponse(
|
||||||
|
204,
|
||||||
|
'No Content',
|
||||||
|
{},
|
||||||
|
None)
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'GET', '/stacks/teststack/1').AndReturn((resp, stack_dict))
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'POST',
|
||||||
|
'/stacks/teststack/1/snapshots/2/restore').AndReturn((resp, {}))
|
||||||
|
|
||||||
|
self.m.ReplayAll()
|
||||||
|
resp = self.shell('stack-restore teststack/1 2')
|
||||||
|
self.assertEqual("", resp)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_snapshot_list(self):
|
def test_snapshot_list(self):
|
||||||
self.register_keystone_auth_fixture()
|
self.register_keystone_auth_fixture()
|
||||||
|
@@ -125,6 +125,13 @@ class StackOperationsTest(testtools.TestCase):
|
|||||||
manager.snapshot_delete.assert_called_once_with(
|
manager.snapshot_delete.assert_called_once_with(
|
||||||
'the_stack/abcd1234', 'snap1234')
|
'the_stack/abcd1234', 'snap1234')
|
||||||
|
|
||||||
|
def test_restore(self):
|
||||||
|
manager = MagicMock()
|
||||||
|
stack = mock_stack(manager, 'the_stack', 'abcd1234')
|
||||||
|
stack.restore('snap1234')
|
||||||
|
manager.restore.assert_called_once_with(
|
||||||
|
'the_stack/abcd1234', 'snap1234')
|
||||||
|
|
||||||
def test_snapshot_list(self):
|
def test_snapshot_list(self):
|
||||||
manager = MagicMock()
|
manager = MagicMock()
|
||||||
stack = mock_stack(manager, 'the_stack', 'abcd1234')
|
stack = mock_stack(manager, 'the_stack', 'abcd1234')
|
||||||
|
@@ -943,6 +943,19 @@ def do_snapshot_delete(hc, args):
|
|||||||
raise exc.CommandError('Stack or snapshot not found')
|
raise exc.CommandError('Stack or snapshot not found')
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('id', metavar='<NAME or ID>',
|
||||||
|
help='Name or ID of the stack containing the snapshot.')
|
||||||
|
@utils.arg('snapshot', metavar='<SNAPSHOT>',
|
||||||
|
help='The ID of the snapshot to restore.')
|
||||||
|
def do_stack_restore(hc, args):
|
||||||
|
'''Restore a snapshot of a stack.'''
|
||||||
|
fields = {'stack_id': args.id, 'snapshot_id': args.snapshot}
|
||||||
|
try:
|
||||||
|
hc.stacks.restore(**fields)
|
||||||
|
except exc.HTTPNotFound:
|
||||||
|
raise exc.CommandError('Stack or snapshot not found')
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('id', metavar='<NAME or ID>',
|
@utils.arg('id', metavar='<NAME or ID>',
|
||||||
help='Name or ID of the stack containing the snapshots.')
|
help='Name or ID of the stack containing the snapshots.')
|
||||||
def do_snapshot_list(hc, args):
|
def do_snapshot_list(hc, args):
|
||||||
|
@@ -47,6 +47,9 @@ class Stack(base.Resource):
|
|||||||
def snapshot_delete(self, snapshot_id):
|
def snapshot_delete(self, snapshot_id):
|
||||||
return self.manager.snapshot_delete(self.identifier, snapshot_id)
|
return self.manager.snapshot_delete(self.identifier, snapshot_id)
|
||||||
|
|
||||||
|
def restore(self, snapshot_id):
|
||||||
|
return self.manager.restore(self.identifier, snapshot_id)
|
||||||
|
|
||||||
def snapshot_list(self):
|
def snapshot_list(self):
|
||||||
return self.manager.snapshot_list(self.identifier)
|
return self.manager.snapshot_list(self.identifier)
|
||||||
|
|
||||||
@@ -176,6 +179,14 @@ class StackManager(base.BaseManager):
|
|||||||
'/stacks/%s/snapshots/%s' % (stack.identifier, snapshot_id))
|
'/stacks/%s/snapshots/%s' % (stack.identifier, snapshot_id))
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
def restore(self, stack_id, snapshot_id):
|
||||||
|
stack = self.get(stack_id)
|
||||||
|
resp, body = self.client.json_request(
|
||||||
|
'POST',
|
||||||
|
'/stacks/%s/snapshots/%s/restore' % (stack.identifier,
|
||||||
|
snapshot_id))
|
||||||
|
return body
|
||||||
|
|
||||||
def snapshot_list(self, stack_id):
|
def snapshot_list(self, stack_id):
|
||||||
stack = self.get(stack_id)
|
stack = self.get(stack_id)
|
||||||
resp, body = self.client.json_request(
|
resp, body = self.client.json_request(
|
||||||
|
Reference in New Issue
Block a user