blob: abbe1e99993d77bf264383871d4a9479be1089e8 [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
Zhi Kun Liubb363a22013-11-28 18:47:39 +080021class SnapshotsActionsTest(base.BaseVolumeV1AdminTest):
zhangyanzid4d3c6d2013-11-06 09:27:13 +080022 _interface = "json"
23
24 @classmethod
Masayuki Igawaa279a682014-03-14 13:29:42 +090025 @test.safe_setup
zhangyanzid4d3c6d2013-11-06 09:27:13 +080026 def setUpClass(cls):
27 super(SnapshotsActionsTest, cls).setUpClass()
28 cls.client = cls.snapshots_client
29
30 # Create admin volume client
31 cls.admin_snapshots_client = cls.os_adm.snapshots_client
32
33 # Create a test shared volume for tests
34 vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000035 _, cls.volume = \
zhangyanzid4d3c6d2013-11-06 09:27:13 +080036 cls.volumes_client.create_volume(size=1, display_name=vol_name)
37 cls.volumes_client.wait_for_volume_status(cls.volume['id'],
38 'available')
39
40 # Create a test shared snapshot for tests
41 snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-')
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000042 _, cls.snapshot = \
zhangyanzid4d3c6d2013-11-06 09:27:13 +080043 cls.client.create_snapshot(cls.volume['id'],
44 display_name=snap_name)
45 cls.client.wait_for_snapshot_status(cls.snapshot['id'],
46 'available')
47
48 @classmethod
49 def tearDownClass(cls):
50 # Delete the test snapshot
51 cls.client.delete_snapshot(cls.snapshot['id'])
52 cls.client.wait_for_resource_deletion(cls.snapshot['id'])
53
54 # Delete the test volume
55 cls.volumes_client.delete_volume(cls.volume['id'])
56 cls.volumes_client.wait_for_resource_deletion(cls.volume['id'])
57
58 super(SnapshotsActionsTest, cls).tearDownClass()
59
60 def tearDown(self):
61 # Set snapshot's status to available after test
62 status = 'available'
63 snapshot_id = self.snapshot['id']
64 self.admin_snapshots_client.reset_snapshot_status(snapshot_id,
65 status)
66 super(SnapshotsActionsTest, self).tearDown()
67
wanghaofa3908c2014-01-15 19:34:03 +080068 def _create_reset_and_force_delete_temp_snapshot(self, status=None):
69 # Create snapshot, reset snapshot status,
70 # and force delete temp snapshot
71 temp_snapshot = self.create_snapshot(self.volume['id'])
72 if status:
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000073 _, body = self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080074 reset_snapshot_status(temp_snapshot['id'], status)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000075 _, volume_delete = self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080076 force_delete_snapshot(temp_snapshot['id'])
wanghaofa3908c2014-01-15 19:34:03 +080077 self.client.wait_for_resource_deletion(temp_snapshot['id'])
78
zhangyanzid4d3c6d2013-11-06 09:27:13 +080079 def _get_progress_alias(self):
80 return 'os-extended-snapshot-attributes:progress'
81
Masayuki Igawaa279a682014-03-14 13:29:42 +090082 @test.attr(type='gate')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080083 def test_reset_snapshot_status(self):
84 # Reset snapshot status to creating
85 status = 'creating'
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000086 _, body = self.admin_snapshots_client.\
zhangyanzid4d3c6d2013-11-06 09:27:13 +080087 reset_snapshot_status(self.snapshot['id'], status)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000088 _, snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +080089 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +080090 self.assertEqual(status, snapshot_get['status'])
91
Masayuki Igawaa279a682014-03-14 13:29:42 +090092 @test.attr(type='gate')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080093 def test_update_snapshot_status(self):
94 # Reset snapshot status to creating
95 status = 'creating'
96 self.admin_snapshots_client.\
97 reset_snapshot_status(self.snapshot['id'], status)
98
99 # Update snapshot status to error
100 progress = '80%'
101 status = 'error'
102 progress_alias = self._get_progress_alias()
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000103 _, body = self.client.update_snapshot_status(self.snapshot['id'],
104 status, progress)
105 _, snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800106 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800107 self.assertEqual(status, snapshot_get['status'])
108 self.assertEqual(progress, snapshot_get[progress_alias])
109
Masayuki Igawaa279a682014-03-14 13:29:42 +0900110 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800111 def test_snapshot_force_delete_when_snapshot_is_creating(self):
112 # test force delete when status of snapshot is creating
113 self._create_reset_and_force_delete_temp_snapshot('creating')
114
Masayuki Igawaa279a682014-03-14 13:29:42 +0900115 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800116 def test_snapshot_force_delete_when_snapshot_is_deleting(self):
117 # test force delete when status of snapshot is deleting
118 self._create_reset_and_force_delete_temp_snapshot('deleting')
119
Masayuki Igawaa279a682014-03-14 13:29:42 +0900120 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800121 def test_snapshot_force_delete_when_snapshot_is_error(self):
122 # test force delete when status of snapshot is error
123 self._create_reset_and_force_delete_temp_snapshot('error')
124
Masayuki Igawaa279a682014-03-14 13:29:42 +0900125 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800126 def test_snapshot_force_delete_when_snapshot_is_error_deleting(self):
127 # test force delete when status of snapshot is error_deleting
128 self._create_reset_and_force_delete_temp_snapshot('error_deleting')
129
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800130
131class SnapshotsActionsTestXML(SnapshotsActionsTest):
132 _interface = "xml"
133
134 def _get_progress_alias(self):
135 return '{http://docs.openstack.org/volume/ext' \
136 '/extended_snapshot_attributes/api/v1}progress'