blob: c31991c2cc41d595d20d2c75180c47b433c72d8d [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
29class VolumesBackupsV2Test(base.BaseVolumeTest):
30
31 @classmethod
32 def skip_checks(cls):
33 super(VolumesBackupsV2Test, cls).skip_checks()
34 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,
69 description=description)
lkuchlanf8a66682016-06-16 14:49:19 +030070 self.assertEqual(backup_name, backup['name'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020071 waiters.wait_for_volume_resource_status(self.volumes_client,
72 volume['id'], 'available')
lkuchlanf8a66682016-06-16 14:49:19 +030073
74 # Get a given backup
75 backup = self.backups_client.show_backup(backup['id'])['backup']
76 self.assertEqual(backup_name, backup['name'])
lkuchlan9e52d6b2016-12-11 12:18:42 +020077 self.assertEqual(description, backup['description'])
lkuchlanf8a66682016-06-16 14:49:19 +030078
79 # Get all backups with detail
80 backups = self.backups_client.list_backups(
81 detail=True)['backups']
82 self.assertIn((backup['name'], backup['id']),
83 [(m['name'], m['id']) for m in backups])
84
lkuchlana7fd37a2017-02-12 16:25:54 +020085 restored_volume = self.restore_backup(backup['id'])
86
87 restored_volume_metadata = self.volumes_client.show_volume(
88 restored_volume['volume_id'])['volume']['metadata']
89
90 # Verify the backups has been restored successfully
91 # with the metadata of the source volume.
92 self.assertThat(restored_volume_metadata.items(),
93 matchers.ContainsAll(metadata.items()))
lkuchlanf8a66682016-06-16 14:49:19 +030094
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080095 @decorators.idempotent_id('07af8f6d-80af-44c9-a5dc-c8427b1b62e6')
lkuchlan9dea88e2016-06-07 17:12:01 +030096 @test.services('compute')
97 def test_backup_create_attached_volume(self):
98 """Test backup create using force flag.
99
100 Cinder allows to create a volume backup, whether the volume status
101 is "available" or "in-use".
102 """
103 # Create a server
lisalibf543c32016-08-24 17:11:20 +0800104 volume = self.create_volume()
105 self.addCleanup(self.volumes_client.delete_volume,
106 volume['id'])
zhufl7867a6e2016-10-18 15:37:12 +0800107 server = self.create_server(wait_until='ACTIVE')
lkuchlan9dea88e2016-06-07 17:12:01 +0300108 # Attach volume to instance
lkuchland818ef32017-01-11 12:22:22 +0200109 self.attach_volume(server['id'], volume['id'])
lkuchlan9dea88e2016-06-07 17:12:01 +0300110 # Create backup using force flag
zhuflc6ce5392016-08-17 14:34:37 +0800111 backup_name = data_utils.rand_name(
112 self.__class__.__name__ + '-Backup')
lkuchlana2beb492016-08-17 12:42:44 +0300113 backup = self.create_backup(volume_id=volume['id'],
114 name=backup_name, force=True)
lkuchlan9dea88e2016-06-07 17:12:01 +0300115 self.assertEqual(backup_name, backup['name'])
116
Jaesang Leee4dc8fb2017-03-25 01:19:58 +0000117 @testtools.skipUnless(CONF.service_available.glance,
118 "Glance is not available")
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800119 @decorators.idempotent_id('2a8ba340-dff2-4511-9db7-646f07156b15')
lkuchlanc6e88a62016-12-08 17:12:31 +0200120 def test_bootable_volume_backup_and_restore(self):
121 # Create volume from image
122 img_uuid = CONF.compute.image_ref
123 volume = self.create_volume(imageRef=img_uuid)
124
125 volume_details = self.volumes_client.show_volume(
126 volume['id'])['volume']
127 self.assertEqual('true', volume_details['bootable'])
128
129 # Create a backup
130 backup = self.create_backup(volume_id=volume['id'])
131
132 # Restore the backup
133 restored_volume_id = self.restore_backup(backup['id'])['volume_id']
134
135 # Verify the restored backup volume is bootable
136 restored_volume_info = self.volumes_client.show_volume(
137 restored_volume_id)['volume']
138
139 self.assertEqual('true', restored_volume_info['bootable'])