Add update_snapshot_metadata action
This allows Nova to update the state and progress of a snapshot that it is manipulating. Also fix formatting bug in AssertionError in post_snapshots_1234_action. Implements blueprint qemu-assisted-snapshots Change-Id: Ia108e14870410b783c5d074db89acb94e83fce99
This commit is contained in:
		@@ -244,8 +244,10 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
        action = body.keys()[0]
 | 
			
		||||
        if action == 'os-reset_status':
 | 
			
		||||
            assert 'status' in body['os-reset_status']
 | 
			
		||||
        elif action == 'os-update_snapshot_status':
 | 
			
		||||
            assert 'status' in body['os-update_snapshot_status']
 | 
			
		||||
        else:
 | 
			
		||||
            raise AssertionError('Unexpected action: %s" % action')
 | 
			
		||||
            raise AssertionError("Unexpected action: %s" % action)
 | 
			
		||||
        return (resp, {}, _body)
 | 
			
		||||
 | 
			
		||||
    #
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										35
									
								
								cinderclient/tests/v1/test_snapshot_actions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								cinderclient/tests/v1/test_snapshot_actions.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
# Copyright 2013 Red Hat, Inc.
 | 
			
		||||
# All Rights Reserved.
 | 
			
		||||
#
 | 
			
		||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
			
		||||
#    not use this file except in compliance with the License. You may obtain
 | 
			
		||||
#    a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
#    Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
from cinderclient.tests import utils
 | 
			
		||||
from cinderclient.tests.v1 import fakes
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
cs = fakes.FakeClient()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SnapshotActionsTest(utils.TestCase):
 | 
			
		||||
    def test_update_snapshot_status(self):
 | 
			
		||||
        s = cs.volume_snapshots.get('1234')
 | 
			
		||||
        cs.volume_snapshots.update_snapshot_status(s,
 | 
			
		||||
                                                   {'status': 'available'})
 | 
			
		||||
        cs.assert_called('POST', '/snapshots/1234/action')
 | 
			
		||||
 | 
			
		||||
    def test_update_snapshot_status_with_progress(self):
 | 
			
		||||
        s = cs.volume_snapshots.get('1234')
 | 
			
		||||
        cs.volume_snapshots.update_snapshot_status(s,
 | 
			
		||||
                                                   {'status': 'available',
 | 
			
		||||
                                                    'progress': '73%'})
 | 
			
		||||
        cs.assert_called('POST', '/snapshots/1234/action')
 | 
			
		||||
@@ -251,8 +251,10 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
        action = body.keys()[0]
 | 
			
		||||
        if action == 'os-reset_status':
 | 
			
		||||
            assert 'status' in body['os-reset_status']
 | 
			
		||||
        elif action == 'os-update_snapshot_status':
 | 
			
		||||
            assert 'status' in body['os-update_snapshot_status']
 | 
			
		||||
        else:
 | 
			
		||||
            raise AssertionError('Unexpected action: %s" % action')
 | 
			
		||||
            raise AssertionError('Unexpected action: %s' % action)
 | 
			
		||||
        return (resp, {}, _body)
 | 
			
		||||
 | 
			
		||||
    #
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										35
									
								
								cinderclient/tests/v2/test_snapshot_actions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								cinderclient/tests/v2/test_snapshot_actions.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
# Copyright 2013 Red Hat, Inc.
 | 
			
		||||
# All Rights Reserved.
 | 
			
		||||
#
 | 
			
		||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
			
		||||
#    not use this file except in compliance with the License. You may obtain
 | 
			
		||||
#    a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
#    Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
from cinderclient.tests import utils
 | 
			
		||||
from cinderclient.tests.v2 import fakes
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
cs = fakes.FakeClient()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SnapshotActionsTest(utils.TestCase):
 | 
			
		||||
    def test_update_snapshot_status(self):
 | 
			
		||||
        s = cs.volume_snapshots.get('1234')
 | 
			
		||||
        cs.volume_snapshots.update_snapshot_status(s,
 | 
			
		||||
                                                   {'status': 'available'})
 | 
			
		||||
        cs.assert_called('POST', '/snapshots/1234/action')
 | 
			
		||||
 | 
			
		||||
    def test_update_snapshot_status_with_progress(self):
 | 
			
		||||
        s = cs.volume_snapshots.get('1234')
 | 
			
		||||
        cs.volume_snapshots.update_snapshot_status(s,
 | 
			
		||||
                                                   {'status': 'available',
 | 
			
		||||
                                                    'progress': '73%'})
 | 
			
		||||
        cs.assert_called('POST', '/snapshots/1234/action')
 | 
			
		||||
@@ -148,3 +148,7 @@ class SnapshotManager(base.ManagerWithFind):
 | 
			
		||||
        self.run_hooks('modify_body_for_action', body, **kwargs)
 | 
			
		||||
        url = '/snapshots/%s/action' % base.getid(snapshot)
 | 
			
		||||
        return self.api.client.post(url, body=body)
 | 
			
		||||
 | 
			
		||||
    def update_snapshot_status(self, snapshot, update_dict):
 | 
			
		||||
        return self._action('os-update_snapshot_status',
 | 
			
		||||
                            base.getid(snapshot), update_dict)
 | 
			
		||||
 
 | 
			
		||||
@@ -133,3 +133,7 @@ class SnapshotManager(base.ManagerWithFind):
 | 
			
		||||
        self.run_hooks('modify_body_for_action', body, **kwargs)
 | 
			
		||||
        url = '/snapshots/%s/action' % base.getid(snapshot)
 | 
			
		||||
        return self.api.client.post(url, body=body)
 | 
			
		||||
 | 
			
		||||
    def update_snapshot_status(self, snapshot, update_dict):
 | 
			
		||||
        return self._action('os-update_snapshot_status',
 | 
			
		||||
                            base.getid(snapshot), update_dict)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user