]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Unit test for restore with different hosts
authorVipin Balachandran <vbala@vmware.com>
Thu, 4 Sep 2014 11:52:45 +0000 (17:22 +0530)
committerVipin Balachandran <vbala@vmware.com>
Thu, 4 Sep 2014 11:52:45 +0000 (17:22 +0530)
This patch adds unit test for restore API with different hosts
for backup and volume.

Change-Id: Ia38ea8f046110c4312212460e7f55ef038e18b93

cinder/tests/api/contrib/test_backups.py

index 4304813bf76087146db8eb0861a92ff016097318..f41a4f79622df3d35be0372eda77b0d67e04fa16 100644 (file)
@@ -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' %