jeremy.zhang | 2abe00a | 2017-11-21 10:14:09 +0800 | [diff] [blame] | 1 | # 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 | |
| 17 | from tempest.api.volume import base |
| 18 | from tempest.common import waiters |
jeremy.zhang | b134589 | 2017-12-16 17:21:17 +0800 | [diff] [blame] | 19 | from tempest import config |
jeremy.zhang | 2abe00a | 2017-11-21 10:14:09 +0800 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
| 21 | from tempest.lib.common.utils import test_utils |
| 22 | from tempest.lib import decorators |
| 23 | |
jeremy.zhang | b134589 | 2017-12-16 17:21:17 +0800 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
jeremy.zhang | 2abe00a | 2017-11-21 10:14:09 +0800 | [diff] [blame] | 26 | |
| 27 | class BaseGroupSnapshotsTest(base.BaseVolumeAdminTest): |
| 28 | |
jeremy.zhang | b134589 | 2017-12-16 17:21:17 +0800 | [diff] [blame] | 29 | @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.zhang | 2abe00a | 2017-11-21 10:14:09 +0800 | [diff] [blame] | 35 | 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 | |
| 64 | class GroupSnapshotsTest(BaseGroupSnapshotsTest): |
| 65 | _api_version = 3 |
| 66 | min_microversion = '3.14' |
| 67 | max_microversion = 'latest' |
| 68 | |
| 69 | @decorators.idempotent_id('1298e537-f1f0-47a3-a1dd-8adec8168897') |
| 70 | def test_group_snapshot_create_show_list_delete(self): |
| 71 | # Create volume type |
| 72 | volume_type = self.create_volume_type() |
| 73 | |
| 74 | # Create group type |
| 75 | group_type = self.create_group_type() |
| 76 | |
| 77 | # Create group |
| 78 | grp = self.create_group(group_type=group_type['id'], |
| 79 | volume_types=[volume_type['id']]) |
| 80 | |
| 81 | # Create volume |
| 82 | vol = self.create_volume(volume_type=volume_type['id'], |
| 83 | group_id=grp['id']) |
| 84 | |
| 85 | # Create group snapshot |
| 86 | group_snapshot_name = data_utils.rand_name('group_snapshot') |
| 87 | group_snapshot = self._create_group_snapshot( |
| 88 | group_id=grp['id'], name=group_snapshot_name) |
| 89 | snapshots = self.snapshots_client.list_snapshots( |
| 90 | detail=True)['snapshots'] |
| 91 | for snap in snapshots: |
| 92 | if vol['id'] == snap['volume_id']: |
| 93 | waiters.wait_for_volume_resource_status( |
| 94 | self.snapshots_client, snap['id'], 'available') |
| 95 | self.assertEqual(group_snapshot_name, group_snapshot['name']) |
| 96 | |
| 97 | # Get a given group snapshot |
| 98 | group_snapshot = self.group_snapshots_client.show_group_snapshot( |
| 99 | group_snapshot['id'])['group_snapshot'] |
| 100 | self.assertEqual(group_snapshot_name, group_snapshot['name']) |
| 101 | |
| 102 | # Get all group snapshots with details, check some detail-specific |
| 103 | # elements, and look for the created group snapshot |
| 104 | group_snapshots = self.group_snapshots_client.list_group_snapshots( |
| 105 | detail=True)['group_snapshots'] |
| 106 | for grp_snapshot in group_snapshots: |
| 107 | self.assertIn('created_at', grp_snapshot) |
| 108 | self.assertIn('group_id', grp_snapshot) |
| 109 | self.assertIn((group_snapshot['name'], group_snapshot['id']), |
| 110 | [(m['name'], m['id']) for m in group_snapshots]) |
| 111 | |
| 112 | # Delete group snapshot |
| 113 | self._delete_group_snapshot(group_snapshot) |
| 114 | group_snapshots = self.group_snapshots_client.list_group_snapshots()[ |
| 115 | 'group_snapshots'] |
| 116 | self.assertEmpty(group_snapshots) |
| 117 | |
| 118 | @decorators.idempotent_id('eff52c70-efc7-45ed-b47a-4ad675d09b81') |
| 119 | def test_create_group_from_group_snapshot(self): |
| 120 | # Create volume type |
| 121 | volume_type = self.create_volume_type() |
| 122 | |
| 123 | # Create group type |
| 124 | group_type = self.create_group_type() |
| 125 | |
| 126 | # Create Group |
| 127 | grp = self.create_group(group_type=group_type['id'], |
| 128 | volume_types=[volume_type['id']]) |
| 129 | |
| 130 | # Create volume |
| 131 | vol = self.create_volume(volume_type=volume_type['id'], |
| 132 | group_id=grp['id']) |
| 133 | |
| 134 | # Create group_snapshot |
| 135 | group_snapshot_name = data_utils.rand_name('group_snapshot') |
| 136 | group_snapshot = self._create_group_snapshot( |
| 137 | group_id=grp['id'], name=group_snapshot_name) |
| 138 | self.assertEqual(group_snapshot_name, group_snapshot['name']) |
| 139 | snapshots = self.snapshots_client.list_snapshots( |
| 140 | detail=True)['snapshots'] |
| 141 | for snap in snapshots: |
| 142 | if vol['id'] == snap['volume_id']: |
| 143 | waiters.wait_for_volume_resource_status( |
| 144 | self.snapshots_client, snap['id'], 'available') |
| 145 | |
| 146 | # Create Group from Group snapshot |
| 147 | grp_name2 = data_utils.rand_name('Group_from_snap') |
| 148 | grp2 = self.groups_client.create_group_from_source( |
| 149 | group_snapshot_id=group_snapshot['id'], name=grp_name2)['group'] |
| 150 | self.addCleanup(self.delete_group, grp2['id']) |
| 151 | self.assertEqual(grp_name2, grp2['name']) |
| 152 | vols = self.volumes_client.list_volumes(detail=True)['volumes'] |
| 153 | for vol in vols: |
| 154 | if vol['group_id'] == grp2['id']: |
| 155 | waiters.wait_for_volume_resource_status( |
| 156 | self.volumes_client, vol['id'], 'available') |
| 157 | waiters.wait_for_volume_resource_status( |
| 158 | self.groups_client, grp2['id'], 'available') |
| 159 | |
lkuchlan | a08b4e6 | 2017-12-19 15:48:31 +0200 | [diff] [blame] | 160 | @decorators.idempotent_id('7d7fc000-0b4c-4376-a372-544116d2e127') |
| 161 | @decorators.related_bug('1739031') |
| 162 | def test_delete_group_snapshots_following_updated_volumes(self): |
| 163 | volume_type = self.create_volume_type() |
| 164 | |
| 165 | group_type = self.create_group_type() |
| 166 | |
| 167 | # Create a volume group |
| 168 | grp = self.create_group(group_type=group_type['id'], |
| 169 | volume_types=[volume_type['id']]) |
| 170 | |
| 171 | # Note: When dealing with consistency groups all volumes must |
| 172 | # reside on the same backend. Adding volumes to the same consistency |
| 173 | # group from multiple backends isn't supported. In order to ensure all |
| 174 | # volumes share the same backend, all volumes must share same |
| 175 | # volume-type and group id. |
| 176 | volume_list = [] |
| 177 | for _ in range(2): |
| 178 | volume = self.create_volume(volume_type=volume_type['id'], |
| 179 | group_id=grp['id']) |
| 180 | volume_list.append(volume['id']) |
| 181 | |
| 182 | for vol in volume_list: |
| 183 | self.groups_client.update_group(grp['id'], |
| 184 | remove_volumes=vol) |
| 185 | waiters.wait_for_volume_resource_status( |
| 186 | self.groups_client, grp['id'], 'available') |
| 187 | |
| 188 | self.groups_client.update_group(grp['id'], |
| 189 | add_volumes=vol) |
| 190 | waiters.wait_for_volume_resource_status( |
| 191 | self.groups_client, grp['id'], 'available') |
| 192 | |
| 193 | # Verify the created volumes are associated with consistency group |
| 194 | vols = self.volumes_client.list_volumes(detail=True)['volumes'] |
| 195 | grp_vols = [v for v in vols if v['group_id'] == grp['id']] |
| 196 | self.assertEqual(2, len(grp_vols)) |
| 197 | |
| 198 | # Create a snapshot group |
| 199 | group_snapshot = self._create_group_snapshot(group_id=grp['id']) |
| 200 | snapshots = self.snapshots_client.list_snapshots( |
| 201 | detail=True)['snapshots'] |
| 202 | |
| 203 | for snap in snapshots: |
| 204 | if snap['volume_id'] in volume_list: |
| 205 | waiters.wait_for_volume_resource_status( |
| 206 | self.snapshots_client, snap['id'], 'available') |
| 207 | |
| 208 | # Delete a snapshot group |
| 209 | self._delete_group_snapshot(group_snapshot) |
| 210 | |
jeremy.zhang | 2abe00a | 2017-11-21 10:14:09 +0800 | [diff] [blame] | 211 | |
| 212 | class GroupSnapshotsV319Test(BaseGroupSnapshotsTest): |
| 213 | _api_version = 3 |
| 214 | min_microversion = '3.19' |
| 215 | max_microversion = 'latest' |
| 216 | |
| 217 | @decorators.idempotent_id('3b42c9b9-c984-4444-816e-ca2e1ed30b40') |
Matt Riedemann | 5b91aea | 2018-09-14 11:39:46 -0400 | [diff] [blame] | 218 | @decorators.skip_because(bug='1770179') |
jeremy.zhang | 2abe00a | 2017-11-21 10:14:09 +0800 | [diff] [blame] | 219 | def test_reset_group_snapshot_status(self): |
| 220 | # Create volume type |
| 221 | volume_type = self.create_volume_type() |
| 222 | |
| 223 | # Create group type |
| 224 | group_type = self.create_group_type() |
| 225 | |
| 226 | # Create group |
| 227 | group = self.create_group(group_type=group_type['id'], |
| 228 | volume_types=[volume_type['id']]) |
| 229 | |
| 230 | # Create volume |
| 231 | volume = self.create_volume(volume_type=volume_type['id'], |
| 232 | group_id=group['id']) |
| 233 | |
| 234 | # Create group snapshot |
| 235 | group_snapshot = self._create_group_snapshot(group_id=group['id']) |
| 236 | snapshots = self.snapshots_client.list_snapshots( |
| 237 | detail=True)['snapshots'] |
| 238 | for snap in snapshots: |
| 239 | if volume['id'] == snap['volume_id']: |
| 240 | waiters.wait_for_volume_resource_status( |
| 241 | self.snapshots_client, snap['id'], 'available') |
| 242 | |
| 243 | # Reset group snapshot status |
| 244 | self.addCleanup(waiters.wait_for_volume_resource_status, |
| 245 | self.group_snapshots_client, |
| 246 | group_snapshot['id'], 'available') |
| 247 | self.addCleanup( |
| 248 | self.admin_group_snapshots_client.reset_group_snapshot_status, |
| 249 | group_snapshot['id'], 'available') |
| 250 | for status in ['creating', 'available', 'error']: |
| 251 | self.admin_group_snapshots_client.reset_group_snapshot_status( |
| 252 | group_snapshot['id'], status) |
| 253 | waiters.wait_for_volume_resource_status( |
| 254 | self.group_snapshots_client, group_snapshot['id'], status) |