zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 1 | # Copyright 2013 Huawei Technologies Co.,LTD |
| 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 | |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 16 | from tempest_lib.common.utils import data_utils |
| 17 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 18 | from tempest.api.volume import base |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 19 | from tempest import test |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 20 | |
| 21 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 22 | class SnapshotsActionsV2Test(base.BaseVolumeAdminTest): |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 23 | |
| 24 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 25 | def setup_clients(cls): |
| 26 | super(SnapshotsActionsV2Test, cls).setup_clients() |
| 27 | cls.client = cls.snapshots_client |
| 28 | |
| 29 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 30 | def resource_setup(cls): |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 31 | super(SnapshotsActionsV2Test, cls).resource_setup() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 32 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 33 | # Create a test shared volume for tests |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 34 | vol_name = data_utils.rand_name(cls.__name__ + '-Volume') |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 35 | cls.name_field = cls.special_fields['name_field'] |
| 36 | params = {cls.name_field: vol_name} |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 37 | cls.volume = \ |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 38 | cls.volumes_client.create_volume(**params) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 39 | cls.volumes_client.wait_for_volume_status(cls.volume['id'], |
| 40 | 'available') |
| 41 | |
| 42 | # Create a test shared snapshot for tests |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 43 | snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot') |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 44 | params = {cls.name_field: snap_name} |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 45 | cls.snapshot = \ |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 46 | cls.client.create_snapshot(cls.volume['id'], **params) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 47 | cls.client.wait_for_snapshot_status(cls.snapshot['id'], |
| 48 | 'available') |
| 49 | |
| 50 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 51 | def resource_cleanup(cls): |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 52 | # Delete the test snapshot |
| 53 | cls.client.delete_snapshot(cls.snapshot['id']) |
| 54 | cls.client.wait_for_resource_deletion(cls.snapshot['id']) |
| 55 | |
| 56 | # Delete the test volume |
| 57 | cls.volumes_client.delete_volume(cls.volume['id']) |
| 58 | cls.volumes_client.wait_for_resource_deletion(cls.volume['id']) |
| 59 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 60 | super(SnapshotsActionsV2Test, cls).resource_cleanup() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 61 | |
| 62 | def tearDown(self): |
| 63 | # Set snapshot's status to available after test |
| 64 | status = 'available' |
| 65 | snapshot_id = self.snapshot['id'] |
| 66 | self.admin_snapshots_client.reset_snapshot_status(snapshot_id, |
| 67 | status) |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 68 | super(SnapshotsActionsV2Test, self).tearDown() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 69 | |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 70 | def _create_reset_and_force_delete_temp_snapshot(self, status=None): |
| 71 | # Create snapshot, reset snapshot status, |
| 72 | # and force delete temp snapshot |
| 73 | temp_snapshot = self.create_snapshot(self.volume['id']) |
| 74 | if status: |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 75 | self.admin_snapshots_client.\ |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 76 | reset_snapshot_status(temp_snapshot['id'], status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 77 | self.admin_snapshots_client.\ |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 78 | force_delete_snapshot(temp_snapshot['id']) |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 79 | self.client.wait_for_resource_deletion(temp_snapshot['id']) |
| 80 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 81 | def _get_progress_alias(self): |
| 82 | return 'os-extended-snapshot-attributes:progress' |
| 83 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 84 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 85 | @test.idempotent_id('3e13ca2f-48ea-49f3-ae1a-488e9180d535') |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 86 | def test_reset_snapshot_status(self): |
| 87 | # Reset snapshot status to creating |
| 88 | status = 'creating' |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 89 | self.admin_snapshots_client.\ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 90 | reset_snapshot_status(self.snapshot['id'], status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 91 | snapshot_get \ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 92 | = self.admin_snapshots_client.get_snapshot(self.snapshot['id']) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 93 | self.assertEqual(status, snapshot_get['status']) |
| 94 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 95 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 96 | @test.idempotent_id('41288afd-d463-485e-8f6e-4eea159413eb') |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 97 | def test_update_snapshot_status(self): |
| 98 | # Reset snapshot status to creating |
| 99 | status = 'creating' |
| 100 | self.admin_snapshots_client.\ |
| 101 | reset_snapshot_status(self.snapshot['id'], status) |
| 102 | |
| 103 | # Update snapshot status to error |
| 104 | progress = '80%' |
| 105 | status = 'error' |
| 106 | progress_alias = self._get_progress_alias() |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 107 | self.client.update_snapshot_status(self.snapshot['id'], |
| 108 | status, progress) |
| 109 | snapshot_get \ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 110 | = self.admin_snapshots_client.get_snapshot(self.snapshot['id']) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 111 | self.assertEqual(status, snapshot_get['status']) |
| 112 | self.assertEqual(progress, snapshot_get[progress_alias]) |
| 113 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 114 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 115 | @test.idempotent_id('05f711b6-e629-4895-8103-7ca069f2073a') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 116 | def test_snapshot_force_delete_when_snapshot_is_creating(self): |
| 117 | # test force delete when status of snapshot is creating |
| 118 | self._create_reset_and_force_delete_temp_snapshot('creating') |
| 119 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 120 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 121 | @test.idempotent_id('92ce8597-b992-43a1-8868-6316b22a969e') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 122 | def test_snapshot_force_delete_when_snapshot_is_deleting(self): |
| 123 | # test force delete when status of snapshot is deleting |
| 124 | self._create_reset_and_force_delete_temp_snapshot('deleting') |
| 125 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 126 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 127 | @test.idempotent_id('645a4a67-a1eb-4e8e-a547-600abac1525d') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 128 | def test_snapshot_force_delete_when_snapshot_is_error(self): |
| 129 | # test force delete when status of snapshot is error |
| 130 | self._create_reset_and_force_delete_temp_snapshot('error') |
| 131 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 132 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 133 | @test.idempotent_id('bf89080f-8129-465e-9327-b2f922666ba5') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 134 | def test_snapshot_force_delete_when_snapshot_is_error_deleting(self): |
| 135 | # test force delete when status of snapshot is error_deleting |
| 136 | self._create_reset_and_force_delete_temp_snapshot('error_deleting') |
| 137 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 138 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 139 | class SnapshotsActionsV1Test(SnapshotsActionsV2Test): |
| 140 | _api_version = 1 |