blob: e664ff70ca662f3e042884767ea0fe78392cefb7 [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
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080020from tempest.lib import decorators
lkuchlan9dea88e2016-06-07 17:12:01 +030021from tempest import test
22
23CONF = config.CONF
24
25
26class VolumesBackupsV2Test(base.BaseVolumeTest):
27
28 @classmethod
29 def skip_checks(cls):
30 super(VolumesBackupsV2Test, cls).skip_checks()
31 if not CONF.volume_feature_enabled.backup:
32 raise cls.skipException("Cinder backup feature disabled")
33
lkuchlanc6e88a62016-12-08 17:12:31 +020034 def restore_backup(self, backup_id):
35 # Restore a backup
36 restored_volume = self.backups_client.restore_backup(
37 backup_id)['restore']
38
39 # Delete backup
40 self.addCleanup(self.volumes_client.delete_volume,
41 restored_volume['volume_id'])
42 self.assertEqual(backup_id, restored_volume['backup_id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020043 waiters.wait_for_volume_resource_status(self.backups_client,
44 backup_id, 'available')
45 waiters.wait_for_volume_resource_status(self.volumes_client,
46 restored_volume['volume_id'],
47 'available')
lkuchlanc6e88a62016-12-08 17:12:31 +020048 return restored_volume
49
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080050 @decorators.idempotent_id('a66eb488-8ee1-47d4-8e9f-575a095728c6')
lkuchlanf8a66682016-06-16 14:49:19 +030051 def test_volume_backup_create_get_detailed_list_restore_delete(self):
52 # Create backup
lisalibf543c32016-08-24 17:11:20 +080053 volume = self.create_volume()
54 self.addCleanup(self.volumes_client.delete_volume,
55 volume['id'])
zhuflc6ce5392016-08-17 14:34:37 +080056 backup_name = data_utils.rand_name(
57 self.__class__.__name__ + '-Backup')
lkuchlan9e52d6b2016-12-11 12:18:42 +020058 description = data_utils.rand_name("volume-backup-description")
lkuchlana2beb492016-08-17 12:42:44 +030059 backup = self.create_backup(volume_id=volume['id'],
lkuchlan9e52d6b2016-12-11 12:18:42 +020060 name=backup_name,
61 description=description)
lkuchlanf8a66682016-06-16 14:49:19 +030062 self.assertEqual(backup_name, backup['name'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020063 waiters.wait_for_volume_resource_status(self.volumes_client,
64 volume['id'], 'available')
lkuchlanf8a66682016-06-16 14:49:19 +030065
66 # Get a given backup
67 backup = self.backups_client.show_backup(backup['id'])['backup']
68 self.assertEqual(backup_name, backup['name'])
lkuchlan9e52d6b2016-12-11 12:18:42 +020069 self.assertEqual(description, backup['description'])
lkuchlanf8a66682016-06-16 14:49:19 +030070
71 # Get all backups with detail
72 backups = self.backups_client.list_backups(
73 detail=True)['backups']
74 self.assertIn((backup['name'], backup['id']),
75 [(m['name'], m['id']) for m in backups])
76
lkuchlanc6e88a62016-12-08 17:12:31 +020077 self.restore_backup(backup['id'])
lkuchlanf8a66682016-06-16 14:49:19 +030078
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080079 @decorators.idempotent_id('07af8f6d-80af-44c9-a5dc-c8427b1b62e6')
lkuchlan9dea88e2016-06-07 17:12:01 +030080 @test.services('compute')
81 def test_backup_create_attached_volume(self):
82 """Test backup create using force flag.
83
84 Cinder allows to create a volume backup, whether the volume status
85 is "available" or "in-use".
86 """
87 # Create a server
lisalibf543c32016-08-24 17:11:20 +080088 volume = self.create_volume()
89 self.addCleanup(self.volumes_client.delete_volume,
90 volume['id'])
zhufl7867a6e2016-10-18 15:37:12 +080091 server = self.create_server(wait_until='ACTIVE')
lkuchlan9dea88e2016-06-07 17:12:01 +030092 # Attach volume to instance
lkuchland818ef32017-01-11 12:22:22 +020093 self.attach_volume(server['id'], volume['id'])
lkuchlan9dea88e2016-06-07 17:12:01 +030094 # Create backup using force flag
zhuflc6ce5392016-08-17 14:34:37 +080095 backup_name = data_utils.rand_name(
96 self.__class__.__name__ + '-Backup')
lkuchlana2beb492016-08-17 12:42:44 +030097 backup = self.create_backup(volume_id=volume['id'],
98 name=backup_name, force=True)
lkuchlan9dea88e2016-06-07 17:12:01 +030099 self.assertEqual(backup_name, backup['name'])
100
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800101 @decorators.idempotent_id('2a8ba340-dff2-4511-9db7-646f07156b15')
lkuchlanc6e88a62016-12-08 17:12:31 +0200102 def test_bootable_volume_backup_and_restore(self):
103 # Create volume from image
104 img_uuid = CONF.compute.image_ref
105 volume = self.create_volume(imageRef=img_uuid)
106
107 volume_details = self.volumes_client.show_volume(
108 volume['id'])['volume']
109 self.assertEqual('true', volume_details['bootable'])
110
111 # Create a backup
112 backup = self.create_backup(volume_id=volume['id'])
113
114 # Restore the backup
115 restored_volume_id = self.restore_backup(backup['id'])['volume_id']
116
117 # Verify the restored backup volume is bootable
118 restored_volume_info = self.volumes_client.show_volume(
119 restored_volume_id)['volume']
120
121 self.assertEqual('true', restored_volume_info['bootable'])
122
lkuchlan9dea88e2016-06-07 17:12:01 +0300123
124class VolumesBackupsV1Test(VolumesBackupsV2Test):
125 _api_version = 1