Skip to content

Commit 3599ebe

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix: Restore output 'VolumeBackupsRestore' object is not iterable"
2 parents 3d7772e + 24255ad commit 3599ebe

4 files changed

Lines changed: 67 additions & 5 deletions

File tree

.zuul.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@
166166
s-container: false
167167
s-object: false
168168
s-proxy: false
169-
# As swift is not available for this job, c-backup service won't be functional.
169+
# As swift is not available for this job, c-bak service won't be functional.
170170
# The backup related tests can be handled by other jobs having swift enabled.
171171
# The backup service along with swift services can be enabled once swift is
172172
# compatible with py3
173-
c-backup: false
173+
c-bak: false
174174
tox_envlist: functional
175175
tox_install_siblings: true
176176

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import json
14+
import uuid
15+
16+
from openstackclient.tests.functional.volume.v2 import common
17+
18+
19+
class VolumeBackupTests(common.BaseVolumeTests):
20+
"""Functional tests for volume backups. """
21+
22+
def setUp(self):
23+
super(VolumeBackupTests, self).setUp()
24+
self.backup_enabled = False
25+
serv_list = json.loads(self.openstack('volume service list -f json'))
26+
for service in serv_list:
27+
if service['Binary'] == 'cinder-backup':
28+
if service['Status'] == 'enabled':
29+
self.backup_enabled = True
30+
31+
def test_volume_backup_restore(self):
32+
"""Test restore backup"""
33+
if not self.backup_enabled:
34+
self.skipTest('Backup service is not enabled')
35+
vol_id = uuid.uuid4().hex
36+
# create a volume
37+
json.loads(self.openstack(
38+
'volume create -f json ' +
39+
'--size 1 ' +
40+
vol_id
41+
))
42+
# create a backup
43+
backup = json.loads(self.openstack(
44+
'volume backup create -f json ' +
45+
vol_id
46+
))
47+
48+
self.wait_for_status("volume", vol_id, "available")
49+
self.wait_for_status("backup", backup['id'], "available")
50+
# restore the backup
51+
backup_restored = json.loads(self.openstack(
52+
'volume backup restore -f json %s %s'
53+
% (backup['id'], vol_id)))
54+
self.assertEqual(backup_restored['backup_id'], backup['id'])
55+
self.wait_for_status("backup", backup['id'], "available")
56+
self.wait_for_status("volume", backup_restored['volume_id'],
57+
"available")
58+
self.addCleanup(self.openstack, 'volume delete %s' % vol_id)

openstackclient/tests/unit/volume/v2/test_backup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ def setUp(self):
367367

368368
self.backups_mock.get.return_value = self.backup
369369
self.volumes_mock.get.return_value = self.volume
370-
self.restores_mock.restore.return_value = None
370+
self.restores_mock.restore.return_value = (
371+
volume_fakes.FakeVolume.create_one_volume(
372+
{'id': self.volume['id']}))
371373
# Get the command object to mock
372374
self.cmd = backup.RestoreVolumeBackup(self.app, None)
373375

@@ -385,7 +387,7 @@ def test_backup_restore(self):
385387
result = self.cmd.take_action(parsed_args)
386388
self.restores_mock.restore.assert_called_with(self.backup.id,
387389
self.backup.volume_id)
388-
self.assertIsNone(result)
390+
self.assertIsNotNone(result)
389391

390392

391393
class TestBackupSet(TestBackup):

openstackclient/volume/v2/backup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ def take_action(self, parsed_args):
319319
backup = utils.find_resource(volume_client.backups, parsed_args.backup)
320320
destination_volume = utils.find_resource(volume_client.volumes,
321321
parsed_args.volume)
322-
return volume_client.restores.restore(backup.id, destination_volume.id)
322+
backup = volume_client.restores.restore(backup.id,
323+
destination_volume.id)
324+
return zip(*sorted(six.iteritems(backup._info)))
323325

324326

325327
class RestoreBackup(RestoreVolumeBackup):

0 commit comments

Comments
 (0)