blob: 1468e90b85c91126de529d659eb9be7fd738761f [file] [log] [blame]
zhangyanzid4d3c6d2013-11-06 09:27:13 +08001# 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 Liubb363a22013-11-28 18:47:39 +080016from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090018from tempest import config
Masayuki Igawaa279a682014-03-14 13:29:42 +090019from tempest import test
zhangyanzid4d3c6d2013-11-06 09:27:13 +080020
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090021CONF = config.CONF
22
zhangyanzid4d3c6d2013-11-06 09:27:13 +080023
Chandan Kumar457d1632014-11-18 13:46:08 +053024class SnapshotsActionsV2Test(base.BaseVolumeAdminTest):
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090025 @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")
zhangyanzid4d3c6d2013-11-06 09:27:13 +080030
31 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053032 def setup_clients(cls):
33 super(SnapshotsActionsV2Test, cls).setup_clients()
34 cls.client = cls.snapshots_client
35
36 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010037 def resource_setup(cls):
Chandan Kumar457d1632014-11-18 13:46:08 +053038 super(SnapshotsActionsV2Test, cls).resource_setup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080039
zhangyanzid4d3c6d2013-11-06 09:27:13 +080040 # Create a test shared volume for tests
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000041 vol_name = data_utils.rand_name(cls.__name__ + '-Volume')
Chandan Kumar457d1632014-11-18 13:46:08 +053042 cls.name_field = cls.special_fields['name_field']
43 params = {cls.name_field: vol_name}
lkuchlana84500a2016-08-17 08:30:39 +030044 cls.volume = cls.create_volume(**params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080045
46 # Create a test shared snapshot for tests
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000047 snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot')
Chandan Kumar457d1632014-11-18 13:46:08 +053048 params = {cls.name_field: snap_name}
lkuchlana84500a2016-08-17 08:30:39 +030049 cls.snapshot = cls.create_snapshot(
50 volume_id=cls.volume['id'], **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080051
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 Kumar457d1632014-11-18 13:46:08 +053058 super(SnapshotsActionsV2Test, self).tearDown()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080059
wanghaofa3908c2014-01-15 19:34:03 +080060 def _create_reset_and_force_delete_temp_snapshot(self, status=None):
61 # Create snapshot, reset snapshot status,
62 # and force delete temp snapshot
Ghanshyam0b75b632015-12-11 15:08:28 +090063 temp_snapshot = self.create_snapshot(volume_id=self.volume['id'])
wanghaofa3908c2014-01-15 19:34:03 +080064 if status:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000065 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080066 reset_snapshot_status(temp_snapshot['id'], status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000067 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080068 force_delete_snapshot(temp_snapshot['id'])
wanghaofa3908c2014-01-15 19:34:03 +080069 self.client.wait_for_resource_deletion(temp_snapshot['id'])
70
zhangyanzid4d3c6d2013-11-06 09:27:13 +080071 def _get_progress_alias(self):
72 return 'os-extended-snapshot-attributes:progress'
73
Chris Hoge7579c1a2015-02-26 14:12:15 -080074 @test.idempotent_id('3e13ca2f-48ea-49f3-ae1a-488e9180d535')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080075 def test_reset_snapshot_status(self):
76 # Reset snapshot status to creating
77 status = 'creating'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000078 self.admin_snapshots_client.\
zhangyanzid4d3c6d2013-11-06 09:27:13 +080079 reset_snapshot_status(self.snapshot['id'], status)
John Warrenff7faf62015-08-17 16:59:06 +000080 snapshot_get = self.admin_snapshots_client.show_snapshot(
81 self.snapshot['id'])['snapshot']
zhangyanzid4d3c6d2013-11-06 09:27:13 +080082 self.assertEqual(status, snapshot_get['status'])
83
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('41288afd-d463-485e-8f6e-4eea159413eb')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080085 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 Lanoux6809bab2014-12-18 14:57:18 +000095 self.client.update_snapshot_status(self.snapshot['id'],
Ghanshyam0b75b632015-12-11 15:08:28 +090096 status=status, progress=progress)
John Warrenff7faf62015-08-17 16:59:06 +000097 snapshot_get = self.admin_snapshots_client.show_snapshot(
98 self.snapshot['id'])['snapshot']
zhangyanzid4d3c6d2013-11-06 09:27:13 +080099 self.assertEqual(status, snapshot_get['status'])
100 self.assertEqual(progress, snapshot_get[progress_alias])
101
Chris Hoge7579c1a2015-02-26 14:12:15 -0800102 @test.idempotent_id('05f711b6-e629-4895-8103-7ca069f2073a')
wanghaofa3908c2014-01-15 19:34:03 +0800103 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 Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('92ce8597-b992-43a1-8868-6316b22a969e')
wanghaofa3908c2014-01-15 19:34:03 +0800108 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 Hoge7579c1a2015-02-26 14:12:15 -0800112 @test.idempotent_id('645a4a67-a1eb-4e8e-a547-600abac1525d')
wanghaofa3908c2014-01-15 19:34:03 +0800113 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 Hoge7579c1a2015-02-26 14:12:15 -0800117 @test.idempotent_id('bf89080f-8129-465e-9327-b2f922666ba5')
wanghaofa3908c2014-01-15 19:34:03 +0800118 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
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800122
Chandan Kumar457d1632014-11-18 13:46:08 +0530123class SnapshotsActionsV1Test(SnapshotsActionsV2Test):
124 _api_version = 1