Implement restore operation

This adds new methods to manage snapshot restoration.

blueprint stack-snapshot
Co-Authored-By: ala.rezmerita@cloudwatt.com

Change-Id: I917c5d89f586110c0614e05e134bebde27d4db55
This commit is contained in:
Thomas Herve 2014-09-26 15:27:25 +02:00
parent 49ab7b36df
commit 47e85e8dd1
4 changed files with 57 additions and 0 deletions

View File

@ -1844,6 +1844,32 @@ class ShellTestUserPass(ShellBase):
resp = self.shell('snapshot-delete teststack/1 2')
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
def test_snapshot_list(self):
self.register_keystone_auth_fixture()

View File

@ -125,6 +125,13 @@ class StackOperationsTest(testtools.TestCase):
manager.snapshot_delete.assert_called_once_with(
'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):
manager = MagicMock()
stack = mock_stack(manager, 'the_stack', 'abcd1234')

View File

@ -942,6 +942,19 @@ def do_snapshot_delete(hc, args):
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>',
help='Name or ID of the stack containing the snapshots.')
def do_snapshot_list(hc, args):

View File

@ -47,6 +47,9 @@ class Stack(base.Resource):
def snapshot_delete(self, 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):
return self.manager.snapshot_list(self.identifier)
@ -176,6 +179,14 @@ class StackManager(base.BaseManager):
'/stacks/%s/snapshots/%s' % (stack.identifier, snapshot_id))
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):
stack = self.get(stack_id)
resp, body = self.client.json_request(