From 48fb9c56952ed03d09fb6b251e372efd40676af2 Mon Sep 17 00:00:00 2001 From: lisali Date: Thu, 9 Jul 2015 13:57:45 +0800 Subject: [PATCH] Return volume name from backup_restore 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 | 1 + cinder/api/views/backups.py | 1 + cinder/backup/api.py | 3 ++- cinder/tests/unit/api/contrib/test_backups.py | 22 +++++++++++++++---- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cinder/api/contrib/backups.py b/cinder/api/contrib/backups.py index 6c5066071..454391ff9 100644 --- a/cinder/api/contrib/backups.py +++ b/cinder/api/contrib/backups.py @@ -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): diff --git a/cinder/api/views/backups.py b/cinder/api/views/backups.py index fff90d251..21019e52f 100644 --- a/cinder/api/views/backups.py +++ b/cinder/api/views/backups.py @@ -57,6 +57,7 @@ class ViewBuilder(common.ViewBuilder): 'restore': { 'backup_id': restore['backup_id'], 'volume_id': restore['volume_id'], + 'volume_name': restore['volume_name'], }, } diff --git a/cinder/backup/api.py b/cinder/backup/api.py index f04e1962d..09648da02 100644 --- a/cinder/backup/api.py +++ b/cinder/backup/api.py @@ -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 diff --git a/cinder/tests/unit/api/contrib/test_backups.py b/cinder/tests/unit/api/contrib/test_backups.py index b58021782..6e80cd2e5 100644 --- a/cinder/tests/unit/api/contrib/test_backups.py +++ b/cinder/tests/unit/api/contrib/test_backups.py @@ -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 = '' % 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. -- 2.45.2