lkuchlan | 9dea88e | 2016-06-07 17:12:01 +0300 | [diff] [blame^] | 1 | # Copyright 2016 Red Hat, Inc. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from tempest.api.volume import base |
| 17 | from tempest.common.utils import data_utils |
| 18 | from tempest.common import waiters |
| 19 | from tempest import config |
| 20 | from tempest import test |
| 21 | |
| 22 | CONF = config.CONF |
| 23 | |
| 24 | |
| 25 | class VolumesBackupsV2Test(base.BaseVolumeTest): |
| 26 | |
| 27 | @classmethod |
| 28 | def skip_checks(cls): |
| 29 | super(VolumesBackupsV2Test, cls).skip_checks() |
| 30 | if not CONF.volume_feature_enabled.backup: |
| 31 | raise cls.skipException("Cinder backup feature disabled") |
| 32 | |
| 33 | @classmethod |
| 34 | def resource_setup(cls): |
| 35 | super(VolumesBackupsV2Test, cls).resource_setup() |
| 36 | |
| 37 | cls.volume = cls.create_volume() |
| 38 | |
| 39 | @test.idempotent_id('07af8f6d-80af-44c9-a5dc-c8427b1b62e6') |
| 40 | @test.services('compute') |
| 41 | def test_backup_create_attached_volume(self): |
| 42 | """Test backup create using force flag. |
| 43 | |
| 44 | Cinder allows to create a volume backup, whether the volume status |
| 45 | is "available" or "in-use". |
| 46 | """ |
| 47 | # Create a server |
| 48 | server_name = data_utils.rand_name('instance') |
| 49 | server = self.create_server(name=server_name, wait_until='ACTIVE') |
| 50 | self.addCleanup(self.servers_client.delete_server, server['id']) |
| 51 | # Attach volume to instance |
| 52 | self.servers_client.attach_volume(server['id'], |
| 53 | volumeId=self.volume['id']) |
| 54 | waiters.wait_for_volume_status(self.volumes_client, |
| 55 | self.volume['id'], 'in-use') |
| 56 | self.addCleanup(waiters.wait_for_volume_status, self.volumes_client, |
| 57 | self.volume['id'], 'available') |
| 58 | self.addCleanup(self.servers_client.detach_volume, server['id'], |
| 59 | self.volume['id']) |
| 60 | # Create backup using force flag |
| 61 | backup_name = data_utils.rand_name('Backup') |
| 62 | backup = self.backups_client.create_backup( |
| 63 | volume_id=self.volume['id'], |
| 64 | name=backup_name, force=True)['backup'] |
| 65 | self.addCleanup(self.backups_client.delete_backup, backup['id']) |
| 66 | self.backups_client.wait_for_backup_status(backup['id'], |
| 67 | 'available') |
| 68 | self.assertEqual(backup_name, backup['name']) |
| 69 | |
| 70 | |
| 71 | class VolumesBackupsV1Test(VolumesBackupsV2Test): |
| 72 | _api_version = 1 |