blob: 29a161b234f9f99284d37610fd0bd731f8003206 [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
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090017from tempest import config
Masayuki Igawaa279a682014-03-14 13:29:42 +090018from tempest import test
zhangyanzid4d3c6d2013-11-06 09:27:13 +080019
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090020CONF = config.CONF
21
zhangyanzid4d3c6d2013-11-06 09:27:13 +080022
Chandan Kumar457d1632014-11-18 13:46:08 +053023class SnapshotsActionsV2Test(base.BaseVolumeAdminTest):
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090024 @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")
zhangyanzid4d3c6d2013-11-06 09:27:13 +080029
30 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010031 def resource_setup(cls):
Chandan Kumar457d1632014-11-18 13:46:08 +053032 super(SnapshotsActionsV2Test, cls).resource_setup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080033
zhangyanzid4d3c6d2013-11-06 09:27:13 +080034 # Create a test shared volume for tests
zhufl354b2fb2016-10-24 15:24:22 +080035 cls.volume = cls.create_volume()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080036
37 # Create a test shared snapshot for tests
zhufl354b2fb2016-10-24 15:24:22 +080038 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +080039
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 Kumar457d1632014-11-18 13:46:08 +053046 super(SnapshotsActionsV2Test, self).tearDown()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080047
wanghaofa3908c2014-01-15 19:34:03 +080048 def _create_reset_and_force_delete_temp_snapshot(self, status=None):
49 # Create snapshot, reset snapshot status,
50 # and force delete temp snapshot
Ghanshyam0b75b632015-12-11 15:08:28 +090051 temp_snapshot = self.create_snapshot(volume_id=self.volume['id'])
wanghaofa3908c2014-01-15 19:34:03 +080052 if status:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000053 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080054 reset_snapshot_status(temp_snapshot['id'], status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000055 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080056 force_delete_snapshot(temp_snapshot['id'])
lkuchlanb21fc572016-11-28 12:25:22 +020057 self.snapshots_client.wait_for_resource_deletion(temp_snapshot['id'])
wanghaofa3908c2014-01-15 19:34:03 +080058
zhangyanzid4d3c6d2013-11-06 09:27:13 +080059 def _get_progress_alias(self):
60 return 'os-extended-snapshot-attributes:progress'
61
Chris Hoge7579c1a2015-02-26 14:12:15 -080062 @test.idempotent_id('3e13ca2f-48ea-49f3-ae1a-488e9180d535')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080063 def test_reset_snapshot_status(self):
64 # Reset snapshot status to creating
65 status = 'creating'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000066 self.admin_snapshots_client.\
zhangyanzid4d3c6d2013-11-06 09:27:13 +080067 reset_snapshot_status(self.snapshot['id'], status)
John Warrenff7faf62015-08-17 16:59:06 +000068 snapshot_get = self.admin_snapshots_client.show_snapshot(
69 self.snapshot['id'])['snapshot']
zhangyanzid4d3c6d2013-11-06 09:27:13 +080070 self.assertEqual(status, snapshot_get['status'])
71
Chris Hoge7579c1a2015-02-26 14:12:15 -080072 @test.idempotent_id('41288afd-d463-485e-8f6e-4eea159413eb')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080073 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()
lkuchlanb21fc572016-11-28 12:25:22 +020083 self.snapshots_client.update_snapshot_status(self.snapshot['id'],
84 status=status,
85 progress=progress)
John Warrenff7faf62015-08-17 16:59:06 +000086 snapshot_get = self.admin_snapshots_client.show_snapshot(
87 self.snapshot['id'])['snapshot']
zhangyanzid4d3c6d2013-11-06 09:27:13 +080088 self.assertEqual(status, snapshot_get['status'])
89 self.assertEqual(progress, snapshot_get[progress_alias])
90
Chris Hoge7579c1a2015-02-26 14:12:15 -080091 @test.idempotent_id('05f711b6-e629-4895-8103-7ca069f2073a')
wanghaofa3908c2014-01-15 19:34:03 +080092 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 Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('92ce8597-b992-43a1-8868-6316b22a969e')
wanghaofa3908c2014-01-15 19:34:03 +080097 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 Hoge7579c1a2015-02-26 14:12:15 -0800101 @test.idempotent_id('645a4a67-a1eb-4e8e-a547-600abac1525d')
wanghaofa3908c2014-01-15 19:34:03 +0800102 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 Hoge7579c1a2015-02-26 14:12:15 -0800106 @test.idempotent_id('bf89080f-8129-465e-9327-b2f922666ba5')
wanghaofa3908c2014-01-15 19:34:03 +0800107 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
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800111
Chandan Kumar457d1632014-11-18 13:46:08 +0530112class SnapshotsActionsV1Test(SnapshotsActionsV2Test):
113 _api_version = 1