blob: 6dcde08b3f064c65c79a43f1df33cd53bdf6c475 [file] [log] [blame]
lkuchlan9dea88e2016-06-07 17:12:01 +03001# 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
16from tempest.api.volume import base
17from tempest.common.utils import data_utils
18from tempest.common import waiters
19from tempest import config
20from tempest import test
21
22CONF = config.CONF
23
24
25class 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
lkuchlanc6e88a62016-12-08 17:12:31 +020033 def restore_backup(self, backup_id):
34 # Restore a backup
35 restored_volume = self.backups_client.restore_backup(
36 backup_id)['restore']
37
38 # Delete backup
39 self.addCleanup(self.volumes_client.delete_volume,
40 restored_volume['volume_id'])
41 self.assertEqual(backup_id, restored_volume['backup_id'])
42 waiters.wait_for_backup_status(self.backups_client,
43 backup_id, 'available')
44 waiters.wait_for_volume_status(self.volumes_client,
45 restored_volume['volume_id'],
46 'available')
47 return restored_volume
48
lkuchlanf8a66682016-06-16 14:49:19 +030049 @test.idempotent_id('a66eb488-8ee1-47d4-8e9f-575a095728c6')
50 def test_volume_backup_create_get_detailed_list_restore_delete(self):
51 # Create backup
lisalibf543c32016-08-24 17:11:20 +080052 volume = self.create_volume()
53 self.addCleanup(self.volumes_client.delete_volume,
54 volume['id'])
zhuflc6ce5392016-08-17 14:34:37 +080055 backup_name = data_utils.rand_name(
56 self.__class__.__name__ + '-Backup')
lkuchlan9e52d6b2016-12-11 12:18:42 +020057 description = data_utils.rand_name("volume-backup-description")
lkuchlana2beb492016-08-17 12:42:44 +030058 backup = self.create_backup(volume_id=volume['id'],
lkuchlan9e52d6b2016-12-11 12:18:42 +020059 name=backup_name,
60 description=description)
lkuchlanf8a66682016-06-16 14:49:19 +030061 self.assertEqual(backup_name, backup['name'])
62 waiters.wait_for_volume_status(self.volumes_client,
lisalibf543c32016-08-24 17:11:20 +080063 volume['id'], 'available')
lkuchlanf8a66682016-06-16 14:49:19 +030064
65 # Get a given backup
66 backup = self.backups_client.show_backup(backup['id'])['backup']
67 self.assertEqual(backup_name, backup['name'])
lkuchlan9e52d6b2016-12-11 12:18:42 +020068 self.assertEqual(description, backup['description'])
lkuchlanf8a66682016-06-16 14:49:19 +030069
70 # Get all backups with detail
71 backups = self.backups_client.list_backups(
72 detail=True)['backups']
73 self.assertIn((backup['name'], backup['id']),
74 [(m['name'], m['id']) for m in backups])
75
lkuchlanc6e88a62016-12-08 17:12:31 +020076 self.restore_backup(backup['id'])
lkuchlanf8a66682016-06-16 14:49:19 +030077
lkuchlan9dea88e2016-06-07 17:12:01 +030078 @test.idempotent_id('07af8f6d-80af-44c9-a5dc-c8427b1b62e6')
79 @test.services('compute')
80 def test_backup_create_attached_volume(self):
81 """Test backup create using force flag.
82
83 Cinder allows to create a volume backup, whether the volume status
84 is "available" or "in-use".
85 """
86 # Create a server
lisalibf543c32016-08-24 17:11:20 +080087 volume = self.create_volume()
88 self.addCleanup(self.volumes_client.delete_volume,
89 volume['id'])
zhufl7867a6e2016-10-18 15:37:12 +080090 server = self.create_server(wait_until='ACTIVE')
lkuchlan9dea88e2016-06-07 17:12:01 +030091 # Attach volume to instance
lkuchland818ef32017-01-11 12:22:22 +020092 self.attach_volume(server['id'], volume['id'])
lkuchlan9dea88e2016-06-07 17:12:01 +030093 # Create backup using force flag
zhuflc6ce5392016-08-17 14:34:37 +080094 backup_name = data_utils.rand_name(
95 self.__class__.__name__ + '-Backup')
lkuchlana2beb492016-08-17 12:42:44 +030096 backup = self.create_backup(volume_id=volume['id'],
97 name=backup_name, force=True)
lkuchlan9dea88e2016-06-07 17:12:01 +030098 self.assertEqual(backup_name, backup['name'])
99
lkuchlanc6e88a62016-12-08 17:12:31 +0200100 @test.idempotent_id('2a8ba340-dff2-4511-9db7-646f07156b15')
101 def test_bootable_volume_backup_and_restore(self):
102 # Create volume from image
103 img_uuid = CONF.compute.image_ref
104 volume = self.create_volume(imageRef=img_uuid)
105
106 volume_details = self.volumes_client.show_volume(
107 volume['id'])['volume']
108 self.assertEqual('true', volume_details['bootable'])
109
110 # Create a backup
111 backup = self.create_backup(volume_id=volume['id'])
112
113 # Restore the backup
114 restored_volume_id = self.restore_backup(backup['id'])['volume_id']
115
116 # Verify the restored backup volume is bootable
117 restored_volume_info = self.volumes_client.show_volume(
118 restored_volume_id)['volume']
119
120 self.assertEqual('true', restored_volume_info['bootable'])
121
lkuchlan9dea88e2016-06-07 17:12:01 +0300122
123class VolumesBackupsV1Test(VolumesBackupsV2Test):
124 _api_version = 1