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 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 16 | from tempest.api.volume import base |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 18 | from tempest import test |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 19 | |
| 20 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 21 | class SnapshotsActionsV2Test(base.BaseVolumeAdminTest): |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 22 | _interface = "json" |
| 23 | |
| 24 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 25 | def resource_setup(cls): |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 26 | super(SnapshotsActionsV2Test, cls).resource_setup() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 27 | cls.client = cls.snapshots_client |
| 28 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 29 | # Create a test shared volume for tests |
| 30 | vol_name = data_utils.rand_name(cls.__name__ + '-Volume-') |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 31 | cls.name_field = cls.special_fields['name_field'] |
| 32 | params = {cls.name_field: vol_name} |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 33 | _, cls.volume = \ |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 34 | cls.volumes_client.create_volume(size=1, **params) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 35 | cls.volumes_client.wait_for_volume_status(cls.volume['id'], |
| 36 | 'available') |
| 37 | |
| 38 | # Create a test shared snapshot for tests |
| 39 | snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-') |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 40 | params = {cls.name_field: snap_name} |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 41 | _, cls.snapshot = \ |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 42 | cls.client.create_snapshot(cls.volume['id'], **params) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 43 | cls.client.wait_for_snapshot_status(cls.snapshot['id'], |
| 44 | 'available') |
| 45 | |
| 46 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 47 | def resource_cleanup(cls): |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 48 | # Delete the test snapshot |
| 49 | cls.client.delete_snapshot(cls.snapshot['id']) |
| 50 | cls.client.wait_for_resource_deletion(cls.snapshot['id']) |
| 51 | |
| 52 | # Delete the test volume |
| 53 | cls.volumes_client.delete_volume(cls.volume['id']) |
| 54 | cls.volumes_client.wait_for_resource_deletion(cls.volume['id']) |
| 55 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 56 | super(SnapshotsActionsV2Test, cls).resource_cleanup() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 57 | |
| 58 | def tearDown(self): |
| 59 | # Set snapshot's status to available after test |
| 60 | status = 'available' |
| 61 | snapshot_id = self.snapshot['id'] |
| 62 | self.admin_snapshots_client.reset_snapshot_status(snapshot_id, |
| 63 | status) |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 64 | super(SnapshotsActionsV2Test, self).tearDown() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 65 | |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 66 | def _create_reset_and_force_delete_temp_snapshot(self, status=None): |
| 67 | # Create snapshot, reset snapshot status, |
| 68 | # and force delete temp snapshot |
| 69 | temp_snapshot = self.create_snapshot(self.volume['id']) |
| 70 | if status: |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 71 | _, body = self.admin_snapshots_client.\ |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 72 | reset_snapshot_status(temp_snapshot['id'], status) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 73 | _, volume_delete = self.admin_snapshots_client.\ |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 74 | force_delete_snapshot(temp_snapshot['id']) |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 75 | self.client.wait_for_resource_deletion(temp_snapshot['id']) |
| 76 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 77 | def _get_progress_alias(self): |
| 78 | return 'os-extended-snapshot-attributes:progress' |
| 79 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 80 | @test.attr(type='gate') |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 81 | def test_reset_snapshot_status(self): |
| 82 | # Reset snapshot status to creating |
| 83 | status = 'creating' |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 84 | _, body = self.admin_snapshots_client.\ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 85 | reset_snapshot_status(self.snapshot['id'], status) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 86 | _, snapshot_get \ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 87 | = self.admin_snapshots_client.get_snapshot(self.snapshot['id']) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 88 | self.assertEqual(status, snapshot_get['status']) |
| 89 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 90 | @test.attr(type='gate') |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 91 | def test_update_snapshot_status(self): |
| 92 | # Reset snapshot status to creating |
| 93 | status = 'creating' |
| 94 | self.admin_snapshots_client.\ |
| 95 | reset_snapshot_status(self.snapshot['id'], status) |
| 96 | |
| 97 | # Update snapshot status to error |
| 98 | progress = '80%' |
| 99 | status = 'error' |
| 100 | progress_alias = self._get_progress_alias() |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 101 | _, body = self.client.update_snapshot_status(self.snapshot['id'], |
| 102 | status, progress) |
| 103 | _, snapshot_get \ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 104 | = self.admin_snapshots_client.get_snapshot(self.snapshot['id']) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 105 | self.assertEqual(status, snapshot_get['status']) |
| 106 | self.assertEqual(progress, snapshot_get[progress_alias]) |
| 107 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 108 | @test.attr(type='gate') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 109 | def test_snapshot_force_delete_when_snapshot_is_creating(self): |
| 110 | # test force delete when status of snapshot is creating |
| 111 | self._create_reset_and_force_delete_temp_snapshot('creating') |
| 112 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 113 | @test.attr(type='gate') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 114 | def test_snapshot_force_delete_when_snapshot_is_deleting(self): |
| 115 | # test force delete when status of snapshot is deleting |
| 116 | self._create_reset_and_force_delete_temp_snapshot('deleting') |
| 117 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 118 | @test.attr(type='gate') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 119 | def test_snapshot_force_delete_when_snapshot_is_error(self): |
| 120 | # test force delete when status of snapshot is error |
| 121 | self._create_reset_and_force_delete_temp_snapshot('error') |
| 122 | |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 123 | @test.attr(type='gate') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 124 | def test_snapshot_force_delete_when_snapshot_is_error_deleting(self): |
| 125 | # test force delete when status of snapshot is error_deleting |
| 126 | self._create_reset_and_force_delete_temp_snapshot('error_deleting') |
| 127 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 128 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 129 | class SnapshotsActionsV1Test(SnapshotsActionsV2Test): |
| 130 | _api_version = 1 |