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