blob: ed37d74e7c70a0d227d7ebec8d853755f959f555 [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
lkuchlana7fd37a2017-02-12 16:25:54 +020016from testtools import matchers
17
lkuchlan9dea88e2016-06-07 17:12:01 +030018from tempest.api.volume import base
19from tempest.common.utils import data_utils
20from tempest.common import waiters
21from tempest import config
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080022from tempest.lib import decorators
lkuchlan9dea88e2016-06-07 17:12:01 +030023from tempest import test
24
25CONF = config.CONF
26
27
28class VolumesBackupsV2Test(base.BaseVolumeTest):
29
30 @classmethod
31 def skip_checks(cls):
32 super(VolumesBackupsV2Test, cls).skip_checks()
33 if not CONF.volume_feature_enabled.backup:
34 raise cls.skipException("Cinder backup feature disabled")
35
lkuchlanc6e88a62016-12-08 17:12:31 +020036 def restore_backup(self, backup_id):
37 # Restore a backup
38 restored_volume = self.backups_client.restore_backup(
39 backup_id)['restore']
40
41 # Delete backup
42 self.addCleanup(self.volumes_client.delete_volume,
43 restored_volume['volume_id'])
44 self.assertEqual(backup_id, restored_volume['backup_id'])
45 waiters.wait_for_backup_status(self.backups_client,
46 backup_id, 'available')
47 waiters.wait_for_volume_status(self.volumes_client,
48 restored_volume['volume_id'],
49 'available')
50 return restored_volume
51
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080052 @decorators.idempotent_id('a66eb488-8ee1-47d4-8e9f-575a095728c6')
lkuchlanf8a66682016-06-16 14:49:19 +030053 def test_volume_backup_create_get_detailed_list_restore_delete(self):
lkuchlana7fd37a2017-02-12 16:25:54 +020054 # Create a volume with metadata
55 metadata = {"vol-meta1": "value1",
56 "vol-meta2": "value2",
57 "vol-meta3": "value3"}
58 volume = self.create_volume(metadata=metadata)
lisalibf543c32016-08-24 17:11:20 +080059 self.addCleanup(self.volumes_client.delete_volume,
60 volume['id'])
lkuchlana7fd37a2017-02-12 16:25:54 +020061
62 # Create a backup
zhuflc6ce5392016-08-17 14:34:37 +080063 backup_name = data_utils.rand_name(
64 self.__class__.__name__ + '-Backup')
lkuchlan9e52d6b2016-12-11 12:18:42 +020065 description = data_utils.rand_name("volume-backup-description")
lkuchlana2beb492016-08-17 12:42:44 +030066 backup = self.create_backup(volume_id=volume['id'],
lkuchlan9e52d6b2016-12-11 12:18:42 +020067 name=backup_name,
68 description=description)
lkuchlanf8a66682016-06-16 14:49:19 +030069 self.assertEqual(backup_name, backup['name'])
70 waiters.wait_for_volume_status(self.volumes_client,
lisalibf543c32016-08-24 17:11:20 +080071 volume['id'], 'available')
lkuchlanf8a66682016-06-16 14:49:19 +030072
73 # Get a given backup
74 backup = self.backups_client.show_backup(backup['id'])['backup']
75 self.assertEqual(backup_name, backup['name'])
lkuchlan9e52d6b2016-12-11 12:18:42 +020076 self.assertEqual(description, backup['description'])
lkuchlanf8a66682016-06-16 14:49:19 +030077
78 # Get all backups with detail
79 backups = self.backups_client.list_backups(
80 detail=True)['backups']
81 self.assertIn((backup['name'], backup['id']),
82 [(m['name'], m['id']) for m in backups])
83
lkuchlana7fd37a2017-02-12 16:25:54 +020084 restored_volume = self.restore_backup(backup['id'])
85
86 restored_volume_metadata = self.volumes_client.show_volume(
87 restored_volume['volume_id'])['volume']['metadata']
88
89 # Verify the backups has been restored successfully
90 # with the metadata of the source volume.
91 self.assertThat(restored_volume_metadata.items(),
92 matchers.ContainsAll(metadata.items()))
lkuchlanf8a66682016-06-16 14:49:19 +030093
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080094 @decorators.idempotent_id('07af8f6d-80af-44c9-a5dc-c8427b1b62e6')
lkuchlan9dea88e2016-06-07 17:12:01 +030095 @test.services('compute')
96 def test_backup_create_attached_volume(self):
97 """Test backup create using force flag.
98
99 Cinder allows to create a volume backup, whether the volume status
100 is "available" or "in-use".
101 """
102 # Create a server
lisalibf543c32016-08-24 17:11:20 +0800103 volume = self.create_volume()
104 self.addCleanup(self.volumes_client.delete_volume,
105 volume['id'])
zhufl7867a6e2016-10-18 15:37:12 +0800106 server = self.create_server(wait_until='ACTIVE')
lkuchlan9dea88e2016-06-07 17:12:01 +0300107 # Attach volume to instance
lkuchland818ef32017-01-11 12:22:22 +0200108 self.attach_volume(server['id'], volume['id'])
lkuchlan9dea88e2016-06-07 17:12:01 +0300109 # Create backup using force flag
zhuflc6ce5392016-08-17 14:34:37 +0800110 backup_name = data_utils.rand_name(
111 self.__class__.__name__ + '-Backup')
lkuchlana2beb492016-08-17 12:42:44 +0300112 backup = self.create_backup(volume_id=volume['id'],
113 name=backup_name, force=True)
lkuchlan9dea88e2016-06-07 17:12:01 +0300114 self.assertEqual(backup_name, backup['name'])
115
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800116 @decorators.idempotent_id('2a8ba340-dff2-4511-9db7-646f07156b15')
lkuchlanc6e88a62016-12-08 17:12:31 +0200117 def test_bootable_volume_backup_and_restore(self):
118 # Create volume from image
119 img_uuid = CONF.compute.image_ref
120 volume = self.create_volume(imageRef=img_uuid)
121
122 volume_details = self.volumes_client.show_volume(
123 volume['id'])['volume']
124 self.assertEqual('true', volume_details['bootable'])
125
126 # Create a backup
127 backup = self.create_backup(volume_id=volume['id'])
128
129 # Restore the backup
130 restored_volume_id = self.restore_backup(backup['id'])['volume_id']
131
132 # Verify the restored backup volume is bootable
133 restored_volume_info = self.volumes_client.show_volume(
134 restored_volume_id)['volume']
135
136 self.assertEqual('true', restored_volume_info['bootable'])
137
lkuchlan9dea88e2016-06-07 17:12:01 +0300138
139class VolumesBackupsV1Test(VolumesBackupsV2Test):
140 _api_version = 1