From: Vipin Balachandran Date: Thu, 4 Sep 2014 11:52:45 +0000 (+0530) Subject: Unit test for restore with different hosts X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=55e2a8b49ec22fac19c2ccdf98d5a35d0a2c4bf7;p=openstack-build%2Fcinder-build.git Unit test for restore with different hosts This patch adds unit test for restore API with different hosts for backup and volume. Change-Id: Ia38ea8f046110c4312212460e7f55ef038e18b93 --- diff --git a/cinder/tests/api/contrib/test_backups.py b/cinder/tests/api/contrib/test_backups.py index 4304813bf..f41a4f796 100644 --- a/cinder/tests/api/contrib/test_backups.py +++ b/cinder/tests/api/contrib/test_backups.py @@ -58,13 +58,13 @@ class BackupsAPITestCase(test.TestCase): display_description='this is a test backup', container='volumebackups', status='creating', - size=0, object_count=0): + size=0, object_count=0, host='testhost'): """Create a backup object.""" backup = {} backup['volume_id'] = volume_id backup['user_id'] = 'fake' backup['project_id'] = 'fake' - backup['host'] = 'testhost' + backup['host'] = host backup['availability_zone'] = 'az1' backup['display_name'] = display_name backup['display_description'] = display_description @@ -984,6 +984,33 @@ class BackupsAPITestCase(test.TestCase): db.volume_destroy(context.get_admin_context(), volume_id) db.backup_destroy(context.get_admin_context(), backup_id) + @mock.patch('cinder.backup.rpcapi.BackupAPI.restore_backup') + def test_restore_backup_with_different_host(self, mock_restore_backup): + backup_id = self._create_backup(status='available', size=10, + host='HostA@BackendB#PoolA') + volume_id = utils.create_volume(self.context, size=10, + host='HostB@BackendB#PoolB')['id'] + + body = {"restore": {"volume_id": volume_id, }} + req = webob.Request.blank('/v2/fake/backups/%s/restore' % + backup_id) + req.method = 'POST' + req.headers['Content-Type'] = 'application/json' + req.body = json.dumps(body) + res = req.get_response(fakes.wsgi_app()) + res_dict = json.loads(res.body) + + self.assertEqual(res.status_int, 202) + self.assertEqual(res_dict['restore']['backup_id'], backup_id) + self.assertEqual(res_dict['restore']['volume_id'], volume_id) + mock_restore_backup.assert_called_once_with(mock.ANY, + 'HostB', + backup_id, + volume_id) + + db.volume_destroy(context.get_admin_context(), volume_id) + db.backup_destroy(context.get_admin_context(), backup_id) + def test_export_record_as_non_admin(self): backup_id = self._create_backup(status='available', size=10) req = webob.Request.blank('/v2/fake/backups/%s/export_record' %