blob: 925beeec6742f93590e530dfa94d58106702f008 [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
Jaesang Leee4dc8fb2017-03-25 01:19:58 +000016import testtools
lkuchlana7fd37a2017-02-12 16:25:54 +020017from testtools import matchers
18
lkuchlan9dea88e2016-06-07 17:12:01 +030019from tempest.api.volume import base
lkuchlan9dea88e2016-06-07 17:12:01 +030020from tempest.common import waiters
21from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080022from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080023from tempest.lib import decorators
lkuchlan9dea88e2016-06-07 17:12:01 +030024from tempest import test
25
26CONF = config.CONF
27
28
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070029class VolumesBackupsTest(base.BaseVolumeTest):
lkuchlan9dea88e2016-06-07 17:12:01 +030030
31 @classmethod
32 def skip_checks(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070033 super(VolumesBackupsTest, cls).skip_checks()
lkuchlan9dea88e2016-06-07 17:12:01 +030034 if not CONF.volume_feature_enabled.backup:
35 raise cls.skipException("Cinder backup feature disabled")
36
lkuchlanc6e88a62016-12-08 17:12:31 +020037 def restore_backup(self, backup_id):
38 # Restore a backup
39 restored_volume = self.backups_client.restore_backup(
40 backup_id)['restore']
41
42 # Delete backup
43 self.addCleanup(self.volumes_client.delete_volume,
44 restored_volume['volume_id'])
45 self.assertEqual(backup_id, restored_volume['backup_id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020046 waiters.wait_for_volume_resource_status(self.backups_client,
47 backup_id, 'available')
48 waiters.wait_for_volume_resource_status(self.volumes_client,
49 restored_volume['volume_id'],
50 'available')
lkuchlanc6e88a62016-12-08 17:12:31 +020051 return restored_volume
52
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080053 @decorators.idempotent_id('a66eb488-8ee1-47d4-8e9f-575a095728c6')
lkuchlanf8a66682016-06-16 14:49:19 +030054 def test_volume_backup_create_get_detailed_list_restore_delete(self):
lkuchlana7fd37a2017-02-12 16:25:54 +020055 # Create a volume with metadata
56 metadata = {"vol-meta1": "value1",
57 "vol-meta2": "value2",
58 "vol-meta3": "value3"}
59 volume = self.create_volume(metadata=metadata)
lisalibf543c32016-08-24 17:11:20 +080060 self.addCleanup(self.volumes_client.delete_volume,
61 volume['id'])
lkuchlana7fd37a2017-02-12 16:25:54 +020062
63 # Create a backup
zhuflc6ce5392016-08-17 14:34:37 +080064 backup_name = data_utils.rand_name(
65 self.__class__.__name__ + '-Backup')
lkuchlan9e52d6b2016-12-11 12:18:42 +020066 description = data_utils.rand_name("volume-backup-description")
lkuchlana2beb492016-08-17 12:42:44 +030067 backup = self.create_backup(volume_id=volume['id'],
lkuchlan9e52d6b2016-12-11 12:18:42 +020068 name=backup_name,
lkuchlanf62703b2017-04-04 14:50:55 +030069 description=description,
70 container='container')
lkuchlanf8a66682016-06-16 14:49:19 +030071 self.assertEqual(backup_name, backup['name'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020072 waiters.wait_for_volume_resource_status(self.volumes_client,
73 volume['id'], 'available')
lkuchlanf8a66682016-06-16 14:49:19 +030074
75 # Get a given backup
76 backup = self.backups_client.show_backup(backup['id'])['backup']
77 self.assertEqual(backup_name, backup['name'])
lkuchlan9e52d6b2016-12-11 12:18:42 +020078 self.assertEqual(description, backup['description'])
lkuchlanf62703b2017-04-04 14:50:55 +030079 self.assertEqual('container', backup['container'])
lkuchlanf8a66682016-06-16 14:49:19 +030080
81 # Get all backups with detail
82 backups = self.backups_client.list_backups(
83 detail=True)['backups']
84 self.assertIn((backup['name'], backup['id']),
85 [(m['name'], m['id']) for m in backups])
86
lkuchlana7fd37a2017-02-12 16:25:54 +020087 restored_volume = self.restore_backup(backup['id'])
88
89 restored_volume_metadata = self.volumes_client.show_volume(
90 restored_volume['volume_id'])['volume']['metadata']
91
92 # Verify the backups has been restored successfully
93 # with the metadata of the source volume.
94 self.assertThat(restored_volume_metadata.items(),
95 matchers.ContainsAll(metadata.items()))
lkuchlanf8a66682016-06-16 14:49:19 +030096
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080097 @decorators.idempotent_id('07af8f6d-80af-44c9-a5dc-c8427b1b62e6')
lkuchlan9dea88e2016-06-07 17:12:01 +030098 @test.services('compute')
99 def test_backup_create_attached_volume(self):
100 """Test backup create using force flag.
101
102 Cinder allows to create a volume backup, whether the volume status
103 is "available" or "in-use".
104 """
105 # Create a server
lisalibf543c32016-08-24 17:11:20 +0800106 volume = self.create_volume()
107 self.addCleanup(self.volumes_client.delete_volume,
108 volume['id'])
zhufl7867a6e2016-10-18 15:37:12 +0800109 server = self.create_server(wait_until='ACTIVE')
lkuchlan9dea88e2016-06-07 17:12:01 +0300110 # Attach volume to instance
lkuchland818ef32017-01-11 12:22:22 +0200111 self.attach_volume(server['id'], volume['id'])
lkuchlan9dea88e2016-06-07 17:12:01 +0300112 # Create backup using force flag
zhuflc6ce5392016-08-17 14:34:37 +0800113 backup_name = data_utils.rand_name(
114 self.__class__.__name__ + '-Backup')
lkuchlana2beb492016-08-17 12:42:44 +0300115 backup = self.create_backup(volume_id=volume['id'],
116 name=backup_name, force=True)
lkuchlan9dea88e2016-06-07 17:12:01 +0300117 self.assertEqual(backup_name, backup['name'])
118
Jaesang Leee4dc8fb2017-03-25 01:19:58 +0000119 @testtools.skipUnless(CONF.service_available.glance,
120 "Glance is not available")
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800121 @decorators.idempotent_id('2a8ba340-dff2-4511-9db7-646f07156b15')
lkuchlanc6e88a62016-12-08 17:12:31 +0200122 def test_bootable_volume_backup_and_restore(self):
123 # Create volume from image
124 img_uuid = CONF.compute.image_ref
125 volume = self.create_volume(imageRef=img_uuid)
126
127 volume_details = self.volumes_client.show_volume(
128 volume['id'])['volume']
129 self.assertEqual('true', volume_details['bootable'])
130
131 # Create a backup
132 backup = self.create_backup(volume_id=volume['id'])
133
134 # Restore the backup
135 restored_volume_id = self.restore_backup(backup['id'])['volume_id']
136
137 # Verify the restored backup volume is bootable
138 restored_volume_info = self.volumes_client.show_volume(
139 restored_volume_id)['volume']
140
141 self.assertEqual('true', restored_volume_info['bootable'])