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