blob: ddfc78af5ba45501ffd292bdba2941d7639927b3 [file] [log] [blame]
jeremy.zhang2abe00a2017-11-21 10:14:09 +08001# Copyright 2017 FiberHome Telecommunication Technologies CO.,LTD
2# Copyright (C) 2017 Dell Inc. or its subsidiaries.
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17from tempest.api.volume import base
18from tempest.common import waiters
jeremy.zhangb1345892017-12-16 17:21:17 +080019from tempest import config
jeremy.zhang2abe00a2017-11-21 10:14:09 +080020from tempest.lib.common.utils import data_utils
21from tempest.lib.common.utils import test_utils
22from tempest.lib import decorators
23
jeremy.zhangb1345892017-12-16 17:21:17 +080024CONF = config.CONF
25
jeremy.zhang2abe00a2017-11-21 10:14:09 +080026
27class BaseGroupSnapshotsTest(base.BaseVolumeAdminTest):
28
jeremy.zhangb1345892017-12-16 17:21:17 +080029 @classmethod
30 def skip_checks(cls):
31 super(BaseGroupSnapshotsTest, cls).skip_checks()
32 if not CONF.volume_feature_enabled.snapshot:
33 raise cls.skipException("Cinder volume snapshots are disabled")
34
jeremy.zhang2abe00a2017-11-21 10:14:09 +080035 def _create_group_snapshot(self, **kwargs):
36 if 'name' not in kwargs:
37 kwargs['name'] = data_utils.rand_name(
38 self.__class__.__name__ + '-Group_Snapshot')
39
40 group_snapshot = self.group_snapshots_client.create_group_snapshot(
41 **kwargs)['group_snapshot']
42 group_snapshot['group_id'] = kwargs['group_id']
43 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
44 self._delete_group_snapshot, group_snapshot)
45 waiters.wait_for_volume_resource_status(
46 self.group_snapshots_client, group_snapshot['id'], 'available')
47 return group_snapshot
48
49 def _delete_group_snapshot(self, group_snapshot):
50 self.group_snapshots_client.delete_group_snapshot(group_snapshot['id'])
51 vols = self.volumes_client.list_volumes(detail=True)['volumes']
52 snapshots = self.snapshots_client.list_snapshots(
53 detail=True)['snapshots']
54 for vol in vols:
55 for snap in snapshots:
56 if (vol['group_id'] == group_snapshot['group_id'] and
57 vol['id'] == snap['volume_id']):
58 self.snapshots_client.wait_for_resource_deletion(
59 snap['id'])
60 self.group_snapshots_client.wait_for_resource_deletion(
61 group_snapshot['id'])
62
63
64class GroupSnapshotsTest(BaseGroupSnapshotsTest):
zhufl2480d2f2020-08-14 11:16:39 +080065 """Test group snapshot"""
66
Sophie Huangd458bf32021-10-12 17:08:41 +000067 volume_min_microversion = '3.14'
68 volume_max_microversion = 'latest'
jeremy.zhang2abe00a2017-11-21 10:14:09 +080069
70 @decorators.idempotent_id('1298e537-f1f0-47a3-a1dd-8adec8168897')
71 def test_group_snapshot_create_show_list_delete(self):
zhufl2480d2f2020-08-14 11:16:39 +080072 """Test create/show/list/delete group snapshot
73
74 1. Create volume type "volume_type1"
75 2. Create group type "group_type1"
76 3. Create group "group1" with "group_type1" and "volume_type1"
77 4. Create volume "volume1" with "volume_type1" and "group1"
78 5. Create group snapshot "group_snapshot1" with "group1"
79 6. Check snapshot created from "volume1" reaches available status
80 7. Check the created group snapshot "group_snapshot1" is in the list
81 of all group snapshots
82 8. Delete group snapshot "group_snapshot1"
83 """
jeremy.zhang2abe00a2017-11-21 10:14:09 +080084 # Create volume type
85 volume_type = self.create_volume_type()
86
87 # Create group type
88 group_type = self.create_group_type()
89
90 # Create group
91 grp = self.create_group(group_type=group_type['id'],
92 volume_types=[volume_type['id']])
93
94 # Create volume
95 vol = self.create_volume(volume_type=volume_type['id'],
96 group_id=grp['id'])
97
98 # Create group snapshot
99 group_snapshot_name = data_utils.rand_name('group_snapshot')
100 group_snapshot = self._create_group_snapshot(
101 group_id=grp['id'], name=group_snapshot_name)
102 snapshots = self.snapshots_client.list_snapshots(
103 detail=True)['snapshots']
104 for snap in snapshots:
105 if vol['id'] == snap['volume_id']:
106 waiters.wait_for_volume_resource_status(
107 self.snapshots_client, snap['id'], 'available')
108 self.assertEqual(group_snapshot_name, group_snapshot['name'])
109
110 # Get a given group snapshot
111 group_snapshot = self.group_snapshots_client.show_group_snapshot(
112 group_snapshot['id'])['group_snapshot']
113 self.assertEqual(group_snapshot_name, group_snapshot['name'])
114
115 # Get all group snapshots with details, check some detail-specific
116 # elements, and look for the created group snapshot
117 group_snapshots = self.group_snapshots_client.list_group_snapshots(
118 detail=True)['group_snapshots']
119 for grp_snapshot in group_snapshots:
120 self.assertIn('created_at', grp_snapshot)
121 self.assertIn('group_id', grp_snapshot)
122 self.assertIn((group_snapshot['name'], group_snapshot['id']),
123 [(m['name'], m['id']) for m in group_snapshots])
124
125 # Delete group snapshot
126 self._delete_group_snapshot(group_snapshot)
127 group_snapshots = self.group_snapshots_client.list_group_snapshots()[
128 'group_snapshots']
Andrey Volkov8b297922020-03-24 11:26:03 +0300129 self.assertNotIn((group_snapshot['name'], group_snapshot['id']),
130 [(m['name'], m['id']) for m in group_snapshots])
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800131
132 @decorators.idempotent_id('eff52c70-efc7-45ed-b47a-4ad675d09b81')
133 def test_create_group_from_group_snapshot(self):
zhufl2480d2f2020-08-14 11:16:39 +0800134 """Test creating group from group snapshot
135
136 1. Create volume type "volume_type1"
137 2. Create group type "group_type1"
138 3. Create group "group1" with "group_type1" and "volume_type1"
139 4. Create volume "volume1" with "volume_type1" and "group1"
140 5. Create group snapshot "group_snapshot1" with "group1"
141 6. Check snapshot created from "volume1" reaches available status
142 7. Create group "group2" from "group_snapshot1"
143 8. Check the volumes belonging to "group2" reach available status
144 9. Check "group2" reaches available status
145 """
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800146 # Create volume type
147 volume_type = self.create_volume_type()
148
149 # Create group type
150 group_type = self.create_group_type()
151
152 # Create Group
153 grp = self.create_group(group_type=group_type['id'],
154 volume_types=[volume_type['id']])
155
156 # Create volume
157 vol = self.create_volume(volume_type=volume_type['id'],
158 group_id=grp['id'])
159
160 # Create group_snapshot
161 group_snapshot_name = data_utils.rand_name('group_snapshot')
162 group_snapshot = self._create_group_snapshot(
163 group_id=grp['id'], name=group_snapshot_name)
164 self.assertEqual(group_snapshot_name, group_snapshot['name'])
165 snapshots = self.snapshots_client.list_snapshots(
166 detail=True)['snapshots']
167 for snap in snapshots:
168 if vol['id'] == snap['volume_id']:
169 waiters.wait_for_volume_resource_status(
170 self.snapshots_client, snap['id'], 'available')
171
172 # Create Group from Group snapshot
173 grp_name2 = data_utils.rand_name('Group_from_snap')
174 grp2 = self.groups_client.create_group_from_source(
175 group_snapshot_id=group_snapshot['id'], name=grp_name2)['group']
176 self.addCleanup(self.delete_group, grp2['id'])
177 self.assertEqual(grp_name2, grp2['name'])
178 vols = self.volumes_client.list_volumes(detail=True)['volumes']
179 for vol in vols:
180 if vol['group_id'] == grp2['id']:
181 waiters.wait_for_volume_resource_status(
182 self.volumes_client, vol['id'], 'available')
183 waiters.wait_for_volume_resource_status(
184 self.groups_client, grp2['id'], 'available')
185
lkuchlana08b4e62017-12-19 15:48:31 +0200186 @decorators.idempotent_id('7d7fc000-0b4c-4376-a372-544116d2e127')
187 @decorators.related_bug('1739031')
188 def test_delete_group_snapshots_following_updated_volumes(self):
zhufl2480d2f2020-08-14 11:16:39 +0800189 """Test deleting group snapshot following updated volumes
190
191 1. Create volume type "volume_type1"
192 2. Create group type "group_type1"
193 3. Create group "group1" with "group_type1" and "volume_type1"
194 4. Create 2 volumes "volume1" and "volume2"
195 with "volume_type1" and "group1"
196 5. For each created volume, removing and then adding back to "group1"
197 6. Create group snapshot "group_snapshot1" with "group1"
198 7. Check snapshots created from "volume1" and "volume2" reach
199 available status
200 8. Delete "group_snapshot1"
201 9. Check snapshots created from "volume1" and "volume2" are deleted
202 """
lkuchlana08b4e62017-12-19 15:48:31 +0200203 volume_type = self.create_volume_type()
204
205 group_type = self.create_group_type()
206
207 # Create a volume group
208 grp = self.create_group(group_type=group_type['id'],
209 volume_types=[volume_type['id']])
210
211 # Note: When dealing with consistency groups all volumes must
212 # reside on the same backend. Adding volumes to the same consistency
213 # group from multiple backends isn't supported. In order to ensure all
214 # volumes share the same backend, all volumes must share same
215 # volume-type and group id.
216 volume_list = []
217 for _ in range(2):
218 volume = self.create_volume(volume_type=volume_type['id'],
219 group_id=grp['id'])
220 volume_list.append(volume['id'])
221
222 for vol in volume_list:
223 self.groups_client.update_group(grp['id'],
224 remove_volumes=vol)
225 waiters.wait_for_volume_resource_status(
226 self.groups_client, grp['id'], 'available')
227
228 self.groups_client.update_group(grp['id'],
229 add_volumes=vol)
230 waiters.wait_for_volume_resource_status(
231 self.groups_client, grp['id'], 'available')
232
233 # Verify the created volumes are associated with consistency group
234 vols = self.volumes_client.list_volumes(detail=True)['volumes']
235 grp_vols = [v for v in vols if v['group_id'] == grp['id']]
236 self.assertEqual(2, len(grp_vols))
237
238 # Create a snapshot group
239 group_snapshot = self._create_group_snapshot(group_id=grp['id'])
240 snapshots = self.snapshots_client.list_snapshots(
241 detail=True)['snapshots']
242
243 for snap in snapshots:
244 if snap['volume_id'] in volume_list:
245 waiters.wait_for_volume_resource_status(
246 self.snapshots_client, snap['id'], 'available')
247
248 # Delete a snapshot group
249 self._delete_group_snapshot(group_snapshot)
250
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800251
252class GroupSnapshotsV319Test(BaseGroupSnapshotsTest):
zhufl2480d2f2020-08-14 11:16:39 +0800253 """Test group snapshot with volume microversion greater than 3.18"""
254
Sophie Huangd458bf32021-10-12 17:08:41 +0000255 volume_min_microversion = '3.19'
256 volume_max_microversion = 'latest'
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800257
258 @decorators.idempotent_id('3b42c9b9-c984-4444-816e-ca2e1ed30b40')
Matt Riedemann5b91aea2018-09-14 11:39:46 -0400259 @decorators.skip_because(bug='1770179')
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800260 def test_reset_group_snapshot_status(self):
zhufl2480d2f2020-08-14 11:16:39 +0800261 """Test resetting group snapshot status to creating/available/error"""
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800262 # Create volume type
263 volume_type = self.create_volume_type()
264
265 # Create group type
266 group_type = self.create_group_type()
267
268 # Create group
269 group = self.create_group(group_type=group_type['id'],
270 volume_types=[volume_type['id']])
271
272 # Create volume
273 volume = self.create_volume(volume_type=volume_type['id'],
274 group_id=group['id'])
275
276 # Create group snapshot
277 group_snapshot = self._create_group_snapshot(group_id=group['id'])
278 snapshots = self.snapshots_client.list_snapshots(
279 detail=True)['snapshots']
280 for snap in snapshots:
281 if volume['id'] == snap['volume_id']:
282 waiters.wait_for_volume_resource_status(
283 self.snapshots_client, snap['id'], 'available')
284
285 # Reset group snapshot status
286 self.addCleanup(waiters.wait_for_volume_resource_status,
287 self.group_snapshots_client,
288 group_snapshot['id'], 'available')
289 self.addCleanup(
290 self.admin_group_snapshots_client.reset_group_snapshot_status,
291 group_snapshot['id'], 'available')
292 for status in ['creating', 'available', 'error']:
293 self.admin_group_snapshots_client.reset_group_snapshot_status(
294 group_snapshot['id'], status)
295 waiters.wait_for_volume_resource_status(
296 self.group_snapshots_client, group_snapshot['id'], status)