|
| 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) |
0 commit comments