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