blob: 31dc09fea9315e1ce6aee919ecdf929dfb0f09b9 [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
zhangyanzid4d3c6d2013-11-06 09:27:13 +080017from tempest.common.utils import data_utils
Masayuki Igawaa279a682014-03-14 13:29:42 +090018from tempest import test
zhangyanzid4d3c6d2013-11-06 09:27:13 +080019
20
Chandan Kumar457d1632014-11-18 13:46:08 +053021class SnapshotsActionsV2Test(base.BaseVolumeAdminTest):
zhangyanzid4d3c6d2013-11-06 09:27:13 +080022 _interface = "json"
23
24 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010025 def resource_setup(cls):
Chandan Kumar457d1632014-11-18 13:46:08 +053026 super(SnapshotsActionsV2Test, cls).resource_setup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080027 cls.client = cls.snapshots_client
28
zhangyanzid4d3c6d2013-11-06 09:27:13 +080029 # Create a test shared volume for tests
30 vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
Chandan Kumar457d1632014-11-18 13:46:08 +053031 cls.name_field = cls.special_fields['name_field']
32 params = {cls.name_field: vol_name}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000033 _, cls.volume = \
Chandan Kumar457d1632014-11-18 13:46:08 +053034 cls.volumes_client.create_volume(size=1, **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080035 cls.volumes_client.wait_for_volume_status(cls.volume['id'],
36 'available')
37
38 # Create a test shared snapshot for tests
39 snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-')
Chandan Kumar457d1632014-11-18 13:46:08 +053040 params = {cls.name_field: snap_name}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000041 _, cls.snapshot = \
Chandan Kumar457d1632014-11-18 13:46:08 +053042 cls.client.create_snapshot(cls.volume['id'], **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080043 cls.client.wait_for_snapshot_status(cls.snapshot['id'],
44 'available')
45
46 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010047 def resource_cleanup(cls):
zhangyanzid4d3c6d2013-11-06 09:27:13 +080048 # Delete the test snapshot
49 cls.client.delete_snapshot(cls.snapshot['id'])
50 cls.client.wait_for_resource_deletion(cls.snapshot['id'])
51
52 # Delete the test volume
53 cls.volumes_client.delete_volume(cls.volume['id'])
54 cls.volumes_client.wait_for_resource_deletion(cls.volume['id'])
55
Chandan Kumar457d1632014-11-18 13:46:08 +053056 super(SnapshotsActionsV2Test, cls).resource_cleanup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080057
58 def tearDown(self):
59 # Set snapshot's status to available after test
60 status = 'available'
61 snapshot_id = self.snapshot['id']
62 self.admin_snapshots_client.reset_snapshot_status(snapshot_id,
63 status)
Chandan Kumar457d1632014-11-18 13:46:08 +053064 super(SnapshotsActionsV2Test, self).tearDown()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080065
wanghaofa3908c2014-01-15 19:34:03 +080066 def _create_reset_and_force_delete_temp_snapshot(self, status=None):
67 # Create snapshot, reset snapshot status,
68 # and force delete temp snapshot
69 temp_snapshot = self.create_snapshot(self.volume['id'])
70 if status:
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000071 _, body = self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080072 reset_snapshot_status(temp_snapshot['id'], status)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000073 _, volume_delete = self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080074 force_delete_snapshot(temp_snapshot['id'])
wanghaofa3908c2014-01-15 19:34:03 +080075 self.client.wait_for_resource_deletion(temp_snapshot['id'])
76
zhangyanzid4d3c6d2013-11-06 09:27:13 +080077 def _get_progress_alias(self):
78 return 'os-extended-snapshot-attributes:progress'
79
Masayuki Igawaa279a682014-03-14 13:29:42 +090080 @test.attr(type='gate')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080081 def test_reset_snapshot_status(self):
82 # Reset snapshot status to creating
83 status = 'creating'
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000084 _, body = self.admin_snapshots_client.\
zhangyanzid4d3c6d2013-11-06 09:27:13 +080085 reset_snapshot_status(self.snapshot['id'], status)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000086 _, snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +080087 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +080088 self.assertEqual(status, snapshot_get['status'])
89
Masayuki Igawaa279a682014-03-14 13:29:42 +090090 @test.attr(type='gate')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080091 def test_update_snapshot_status(self):
92 # Reset snapshot status to creating
93 status = 'creating'
94 self.admin_snapshots_client.\
95 reset_snapshot_status(self.snapshot['id'], status)
96
97 # Update snapshot status to error
98 progress = '80%'
99 status = 'error'
100 progress_alias = self._get_progress_alias()
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000101 _, body = self.client.update_snapshot_status(self.snapshot['id'],
102 status, progress)
103 _, snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800104 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800105 self.assertEqual(status, snapshot_get['status'])
106 self.assertEqual(progress, snapshot_get[progress_alias])
107
Masayuki Igawaa279a682014-03-14 13:29:42 +0900108 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800109 def test_snapshot_force_delete_when_snapshot_is_creating(self):
110 # test force delete when status of snapshot is creating
111 self._create_reset_and_force_delete_temp_snapshot('creating')
112
Masayuki Igawaa279a682014-03-14 13:29:42 +0900113 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800114 def test_snapshot_force_delete_when_snapshot_is_deleting(self):
115 # test force delete when status of snapshot is deleting
116 self._create_reset_and_force_delete_temp_snapshot('deleting')
117
Masayuki Igawaa279a682014-03-14 13:29:42 +0900118 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800119 def test_snapshot_force_delete_when_snapshot_is_error(self):
120 # test force delete when status of snapshot is error
121 self._create_reset_and_force_delete_temp_snapshot('error')
122
Masayuki Igawaa279a682014-03-14 13:29:42 +0900123 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800124 def test_snapshot_force_delete_when_snapshot_is_error_deleting(self):
125 # test force delete when status of snapshot is error_deleting
126 self._create_reset_and_force_delete_temp_snapshot('error_deleting')
127
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800128
Chandan Kumar457d1632014-11-18 13:46:08 +0530129class SnapshotsActionsV1Test(SnapshotsActionsV2Test):
130 _api_version = 1