]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Return volume name from backup_restore
authorlisali <xiaoyan.li@intel.com>
Thu, 9 Jul 2015 05:57:45 +0000 (13:57 +0800)
committerlisali <xiaoyan.li@intel.com>
Fri, 14 Aug 2015 02:16:56 +0000 (10:16 +0800)
Currently volume id and backup id are returned, the change is
to return volume_name also, which is consistent in style with
cinder backup-create.

The related change in python-cinderclient is
https://review.openstack.org/#/c/199846/

APIImpact
It will return additional info "volume_name": volume name when
restoring backup.

Change-Id: I9f5d8ded993fcf1d351d4c65b6806929693b15d6
Closes-Bug: #1472493

cinder/api/contrib/backups.py
cinder/api/views/backups.py
cinder/backup/api.py
cinder/tests/unit/api/contrib/test_backups.py

index 6c5066071f71efab147d30f4d4501203cfd770be..454391ff91cc1a38c0f4adfb2c1c0153092640bb 100644 (file)
@@ -52,6 +52,7 @@ def make_backup(elem):
 def make_backup_restore(elem):
     elem.set('backup_id')
     elem.set('volume_id')
+    elem.set('volume_name')
 
 
 def make_backup_export_import_record(elem):
index fff90d251fe1fc5e5a117d8a4221d2d19cde61cf..21019e52f9498b461497c9efd90316cda1843635 100644 (file)
@@ -57,6 +57,7 @@ class ViewBuilder(common.ViewBuilder):
             'restore': {
                 'backup_id': restore['backup_id'],
                 'volume_id': restore['volume_id'],
+                'volume_name': restore['volume_name'],
             },
         }
 
index f04e1962d59daac4b28c2fac1c22317ba637b284..09648da0207fd03f7665f149612d6c1e62794723 100644 (file)
@@ -316,7 +316,8 @@ class API(base.Base):
                                           volume_id)
 
         d = {'backup_id': backup_id,
-             'volume_id': volume_id, }
+             'volume_id': volume_id,
+             'volume_name': volume['display_name'], }
 
         return d
 
index b580217828b5493389c4cb789d39acfb7c4a9c95..6e80cd2e57bac17403cb9d5be8d8cc00c0c875d4 100644 (file)
@@ -892,7 +892,10 @@ class BackupsAPITestCase(test.TestCase):
     def test_restore_backup_volume_id_specified_json(self):
         backup_id = self._create_backup(status='available')
         # need to create the volume referenced below first
-        volume_id = utils.create_volume(self.context, size=5)['id']
+        volume_name = 'test1'
+        volume_id = utils.create_volume(self.context,
+                                        size=5,
+                                        display_name = volume_name)['id']
 
         body = {"restore": {"volume_id": volume_id, }}
         req = webob.Request.blank('/v2/fake/backups/%s/restore' %
@@ -906,10 +909,14 @@ class BackupsAPITestCase(test.TestCase):
         self.assertEqual(202, res.status_int)
         self.assertEqual(backup_id, res_dict['restore']['backup_id'])
         self.assertEqual(volume_id, res_dict['restore']['volume_id'])
+        self.assertEqual(volume_name, res_dict['restore']['volume_name'])
 
     def test_restore_backup_volume_id_specified_xml(self):
+        volume_name = 'test1'
         backup_id = self._create_backup(status='available')
-        volume_id = utils.create_volume(self.context, size=2)['id']
+        volume_id = utils.create_volume(self.context,
+                                        size=2,
+                                        display_name=volume_name)['id']
 
         req = webob.Request.blank('/v2/fake/backups/%s/restore' % backup_id)
         req.body = '<restore volume_id="%s"/>' % volume_id
@@ -1247,7 +1254,10 @@ class BackupsAPITestCase(test.TestCase):
     def test_restore_backup_to_oversized_volume(self):
         backup_id = self._create_backup(status='available', size=10)
         # need to create the volume referenced below first
-        volume_id = utils.create_volume(self.context, size=15)['id']
+        volume_name = 'test1'
+        volume_id = utils.create_volume(self.context,
+                                        size=15,
+                                        display_name = volume_name)['id']
 
         body = {"restore": {"volume_id": volume_id, }}
         req = webob.Request.blank('/v2/fake/backups/%s/restore' %
@@ -1261,16 +1271,19 @@ class BackupsAPITestCase(test.TestCase):
         self.assertEqual(202, res.status_int)
         self.assertEqual(backup_id, res_dict['restore']['backup_id'])
         self.assertEqual(volume_id, res_dict['restore']['volume_id'])
+        self.assertEqual(volume_name, res_dict['restore']['volume_name'])
 
         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):
+        volume_name = 'test1'
         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']
+                                        host='HostB@BackendB#PoolB',
+                                        display_name=volume_name)['id']
 
         body = {"restore": {"volume_id": volume_id, }}
         req = webob.Request.blank('/v2/fake/backups/%s/restore' %
@@ -1284,6 +1297,7 @@ class BackupsAPITestCase(test.TestCase):
         self.assertEqual(202, res.status_int)
         self.assertEqual(backup_id, res_dict['restore']['backup_id'])
         self.assertEqual(volume_id, res_dict['restore']['volume_id'])
+        self.assertEqual(volume_name, res_dict['restore']['volume_name'])
         mock_restore_backup.assert_called_once_with(mock.ANY, u'HostB',
                                                     mock.ANY, volume_id)
         # Manually check if restore_backup was called with appropriate backup.