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 |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Takeaki Matsumoto | a08e2e5 | 2015-09-02 13:52:26 +0900 | [diff] [blame] | 18 | from tempest import config |
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 | |
Takeaki Matsumoto | a08e2e5 | 2015-09-02 13:52:26 +0900 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 23 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 24 | class SnapshotsActionsV2Test(base.BaseVolumeAdminTest): |
Takeaki Matsumoto | a08e2e5 | 2015-09-02 13:52:26 +0900 | [diff] [blame] | 25 | @classmethod |
| 26 | def skip_checks(cls): |
| 27 | super(SnapshotsActionsV2Test, cls).skip_checks() |
| 28 | if not CONF.volume_feature_enabled.snapshot: |
| 29 | raise cls.skipException("Cinder snapshot feature disabled") |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 30 | |
| 31 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 32 | def setup_clients(cls): |
| 33 | super(SnapshotsActionsV2Test, cls).setup_clients() |
| 34 | cls.client = cls.snapshots_client |
| 35 | |
| 36 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 37 | def resource_setup(cls): |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 38 | super(SnapshotsActionsV2Test, cls).resource_setup() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 39 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 40 | # Create a test shared volume for tests |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 41 | vol_name = data_utils.rand_name(cls.__name__ + '-Volume') |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 42 | cls.name_field = cls.special_fields['name_field'] |
| 43 | params = {cls.name_field: vol_name} |
lkuchlan | a84500a | 2016-08-17 08:30:39 +0300 | [diff] [blame] | 44 | cls.volume = cls.create_volume(**params) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 45 | |
| 46 | # Create a test shared snapshot for tests |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 47 | snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot') |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 48 | params = {cls.name_field: snap_name} |
lkuchlan | a84500a | 2016-08-17 08:30:39 +0300 | [diff] [blame] | 49 | cls.snapshot = cls.create_snapshot( |
| 50 | volume_id=cls.volume['id'], **params) |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 51 | |
| 52 | def tearDown(self): |
| 53 | # Set snapshot's status to available after test |
| 54 | status = 'available' |
| 55 | snapshot_id = self.snapshot['id'] |
| 56 | self.admin_snapshots_client.reset_snapshot_status(snapshot_id, |
| 57 | status) |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 58 | super(SnapshotsActionsV2Test, self).tearDown() |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 59 | |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 60 | def _create_reset_and_force_delete_temp_snapshot(self, status=None): |
| 61 | # Create snapshot, reset snapshot status, |
| 62 | # and force delete temp snapshot |
Ghanshyam | 0b75b63 | 2015-12-11 15:08:28 +0900 | [diff] [blame] | 63 | temp_snapshot = self.create_snapshot(volume_id=self.volume['id']) |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 64 | if status: |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 65 | self.admin_snapshots_client.\ |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 66 | reset_snapshot_status(temp_snapshot['id'], status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 67 | self.admin_snapshots_client.\ |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 68 | force_delete_snapshot(temp_snapshot['id']) |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 69 | self.client.wait_for_resource_deletion(temp_snapshot['id']) |
| 70 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 71 | def _get_progress_alias(self): |
| 72 | return 'os-extended-snapshot-attributes:progress' |
| 73 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 74 | @test.idempotent_id('3e13ca2f-48ea-49f3-ae1a-488e9180d535') |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 75 | def test_reset_snapshot_status(self): |
| 76 | # Reset snapshot status to creating |
| 77 | status = 'creating' |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 78 | self.admin_snapshots_client.\ |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 79 | reset_snapshot_status(self.snapshot['id'], status) |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 80 | snapshot_get = self.admin_snapshots_client.show_snapshot( |
| 81 | self.snapshot['id'])['snapshot'] |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 82 | self.assertEqual(status, snapshot_get['status']) |
| 83 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 84 | @test.idempotent_id('41288afd-d463-485e-8f6e-4eea159413eb') |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 85 | def test_update_snapshot_status(self): |
| 86 | # Reset snapshot status to creating |
| 87 | status = 'creating' |
| 88 | self.admin_snapshots_client.\ |
| 89 | reset_snapshot_status(self.snapshot['id'], status) |
| 90 | |
| 91 | # Update snapshot status to error |
| 92 | progress = '80%' |
| 93 | status = 'error' |
| 94 | progress_alias = self._get_progress_alias() |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 95 | self.client.update_snapshot_status(self.snapshot['id'], |
Ghanshyam | 0b75b63 | 2015-12-11 15:08:28 +0900 | [diff] [blame] | 96 | status=status, progress=progress) |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 97 | snapshot_get = self.admin_snapshots_client.show_snapshot( |
| 98 | self.snapshot['id'])['snapshot'] |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 99 | self.assertEqual(status, snapshot_get['status']) |
| 100 | self.assertEqual(progress, snapshot_get[progress_alias]) |
| 101 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 102 | @test.idempotent_id('05f711b6-e629-4895-8103-7ca069f2073a') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 103 | def test_snapshot_force_delete_when_snapshot_is_creating(self): |
| 104 | # test force delete when status of snapshot is creating |
| 105 | self._create_reset_and_force_delete_temp_snapshot('creating') |
| 106 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 107 | @test.idempotent_id('92ce8597-b992-43a1-8868-6316b22a969e') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 108 | def test_snapshot_force_delete_when_snapshot_is_deleting(self): |
| 109 | # test force delete when status of snapshot is deleting |
| 110 | self._create_reset_and_force_delete_temp_snapshot('deleting') |
| 111 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 112 | @test.idempotent_id('645a4a67-a1eb-4e8e-a547-600abac1525d') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 113 | def test_snapshot_force_delete_when_snapshot_is_error(self): |
| 114 | # test force delete when status of snapshot is error |
| 115 | self._create_reset_and_force_delete_temp_snapshot('error') |
| 116 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 117 | @test.idempotent_id('bf89080f-8129-465e-9327-b2f922666ba5') |
wanghao | fa3908c | 2014-01-15 19:34:03 +0800 | [diff] [blame] | 118 | def test_snapshot_force_delete_when_snapshot_is_error_deleting(self): |
| 119 | # test force delete when status of snapshot is error_deleting |
| 120 | self._create_reset_and_force_delete_temp_snapshot('error_deleting') |
| 121 | |
zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame] | 122 | |
Chandan Kumar | 457d163 | 2014-11-18 13:46:08 +0530 | [diff] [blame] | 123 | class SnapshotsActionsV1Test(SnapshotsActionsV2Test): |
| 124 | _api_version = 1 |