zhangyanzi | d4d3c6d | 2013-11-06 09:27:13 +0800 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 Huawei Technologies Co.,LTD |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | from tempest.api.volume.base import BaseVolumeAdminTest |
| 19 | from tempest.common.utils import data_utils |
| 20 | from tempest.test import attr |
| 21 | |
| 22 | |
| 23 | class SnapshotsActionsTest(BaseVolumeAdminTest): |
| 24 | _interface = "json" |
| 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(SnapshotsActionsTest, cls).setUpClass() |
| 29 | cls.client = cls.snapshots_client |
| 30 | |
| 31 | # Create admin volume client |
| 32 | cls.admin_snapshots_client = cls.os_adm.snapshots_client |
| 33 | |
| 34 | # Create a test shared volume for tests |
| 35 | vol_name = data_utils.rand_name(cls.__name__ + '-Volume-') |
| 36 | resp_vol, cls.volume = \ |
| 37 | cls.volumes_client.create_volume(size=1, display_name=vol_name) |
| 38 | cls.volumes_client.wait_for_volume_status(cls.volume['id'], |
| 39 | 'available') |
| 40 | |
| 41 | # Create a test shared snapshot for tests |
| 42 | snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-') |
| 43 | resp_snap, cls.snapshot = \ |
| 44 | cls.client.create_snapshot(cls.volume['id'], |
| 45 | display_name=snap_name) |
| 46 | cls.client.wait_for_snapshot_status(cls.snapshot['id'], |
| 47 | 'available') |
| 48 | |
| 49 | @classmethod |
| 50 | def tearDownClass(cls): |
| 51 | # Delete the test snapshot |
| 52 | cls.client.delete_snapshot(cls.snapshot['id']) |
| 53 | cls.client.wait_for_resource_deletion(cls.snapshot['id']) |
| 54 | |
| 55 | # Delete the test volume |
| 56 | cls.volumes_client.delete_volume(cls.volume['id']) |
| 57 | cls.volumes_client.wait_for_resource_deletion(cls.volume['id']) |
| 58 | |
| 59 | super(SnapshotsActionsTest, cls).tearDownClass() |
| 60 | |
| 61 | def tearDown(self): |
| 62 | # Set snapshot's status to available after test |
| 63 | status = 'available' |
| 64 | snapshot_id = self.snapshot['id'] |
| 65 | self.admin_snapshots_client.reset_snapshot_status(snapshot_id, |
| 66 | status) |
| 67 | super(SnapshotsActionsTest, self).tearDown() |
| 68 | |
| 69 | def _get_progress_alias(self): |
| 70 | return 'os-extended-snapshot-attributes:progress' |
| 71 | |
| 72 | @attr(type='gate') |
| 73 | def test_reset_snapshot_status(self): |
| 74 | # Reset snapshot status to creating |
| 75 | status = 'creating' |
| 76 | resp, body = self.admin_snapshots_client.\ |
| 77 | reset_snapshot_status(self.snapshot['id'], status) |
| 78 | self.assertEqual(202, resp.status) |
| 79 | resp_get, snapshot_get \ |
| 80 | = self.admin_snapshots_client.get_snapshot(self.snapshot['id']) |
| 81 | self.assertEqual(200, resp_get.status) |
| 82 | self.assertEqual(status, snapshot_get['status']) |
| 83 | |
| 84 | @attr(type='gate') |
| 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() |
| 95 | resp, body = self.client.update_snapshot_status(self.snapshot['id'], |
| 96 | status, progress) |
| 97 | self.assertEqual(202, resp.status) |
| 98 | resp_get, snapshot_get \ |
| 99 | = self.admin_snapshots_client.get_snapshot(self.snapshot['id']) |
| 100 | self.assertEqual(200, resp_get.status) |
| 101 | self.assertEqual(status, snapshot_get['status']) |
| 102 | self.assertEqual(progress, snapshot_get[progress_alias]) |
| 103 | |
| 104 | |
| 105 | class SnapshotsActionsTestXML(SnapshotsActionsTest): |
| 106 | _interface = "xml" |
| 107 | |
| 108 | def _get_progress_alias(self): |
| 109 | return '{http://docs.openstack.org/volume/ext' \ |
| 110 | '/extended_snapshot_attributes/api/v1}progress' |