blob: e7d9d7b9ef0deee631cc7aca952c3772ebcf4c38 [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
23 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010024 def resource_setup(cls):
Chandan Kumar457d1632014-11-18 13:46:08 +053025 super(SnapshotsActionsV2Test, cls).resource_setup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080026 cls.client = cls.snapshots_client
27
zhangyanzid4d3c6d2013-11-06 09:27:13 +080028 # Create a test shared volume for tests
29 vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
Chandan Kumar457d1632014-11-18 13:46:08 +053030 cls.name_field = cls.special_fields['name_field']
31 params = {cls.name_field: vol_name}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000032 cls.volume = \
Chandan Kumar457d1632014-11-18 13:46:08 +053033 cls.volumes_client.create_volume(size=1, **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080034 cls.volumes_client.wait_for_volume_status(cls.volume['id'],
35 'available')
36
37 # Create a test shared snapshot for tests
38 snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-')
Chandan Kumar457d1632014-11-18 13:46:08 +053039 params = {cls.name_field: snap_name}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000040 cls.snapshot = \
Chandan Kumar457d1632014-11-18 13:46:08 +053041 cls.client.create_snapshot(cls.volume['id'], **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080042 cls.client.wait_for_snapshot_status(cls.snapshot['id'],
43 'available')
44
45 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010046 def resource_cleanup(cls):
zhangyanzid4d3c6d2013-11-06 09:27:13 +080047 # Delete the test snapshot
48 cls.client.delete_snapshot(cls.snapshot['id'])
49 cls.client.wait_for_resource_deletion(cls.snapshot['id'])
50
51 # Delete the test volume
52 cls.volumes_client.delete_volume(cls.volume['id'])
53 cls.volumes_client.wait_for_resource_deletion(cls.volume['id'])
54
Chandan Kumar457d1632014-11-18 13:46:08 +053055 super(SnapshotsActionsV2Test, cls).resource_cleanup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080056
57 def tearDown(self):
58 # Set snapshot's status to available after test
59 status = 'available'
60 snapshot_id = self.snapshot['id']
61 self.admin_snapshots_client.reset_snapshot_status(snapshot_id,
62 status)
Chandan Kumar457d1632014-11-18 13:46:08 +053063 super(SnapshotsActionsV2Test, self).tearDown()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080064
wanghaofa3908c2014-01-15 19:34:03 +080065 def _create_reset_and_force_delete_temp_snapshot(self, status=None):
66 # Create snapshot, reset snapshot status,
67 # and force delete temp snapshot
68 temp_snapshot = self.create_snapshot(self.volume['id'])
69 if status:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000070 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080071 reset_snapshot_status(temp_snapshot['id'], status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000072 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080073 force_delete_snapshot(temp_snapshot['id'])
wanghaofa3908c2014-01-15 19:34:03 +080074 self.client.wait_for_resource_deletion(temp_snapshot['id'])
75
zhangyanzid4d3c6d2013-11-06 09:27:13 +080076 def _get_progress_alias(self):
77 return 'os-extended-snapshot-attributes:progress'
78
Masayuki Igawaa279a682014-03-14 13:29:42 +090079 @test.attr(type='gate')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080080 def test_reset_snapshot_status(self):
81 # Reset snapshot status to creating
82 status = 'creating'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000083 self.admin_snapshots_client.\
zhangyanzid4d3c6d2013-11-06 09:27:13 +080084 reset_snapshot_status(self.snapshot['id'], status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000085 snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +080086 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +080087 self.assertEqual(status, snapshot_get['status'])
88
Masayuki Igawaa279a682014-03-14 13:29:42 +090089 @test.attr(type='gate')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080090 def test_update_snapshot_status(self):
91 # Reset snapshot status to creating
92 status = 'creating'
93 self.admin_snapshots_client.\
94 reset_snapshot_status(self.snapshot['id'], status)
95
96 # Update snapshot status to error
97 progress = '80%'
98 status = 'error'
99 progress_alias = self._get_progress_alias()
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000100 self.client.update_snapshot_status(self.snapshot['id'],
101 status, progress)
102 snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800103 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800104 self.assertEqual(status, snapshot_get['status'])
105 self.assertEqual(progress, snapshot_get[progress_alias])
106
Masayuki Igawaa279a682014-03-14 13:29:42 +0900107 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800108 def test_snapshot_force_delete_when_snapshot_is_creating(self):
109 # test force delete when status of snapshot is creating
110 self._create_reset_and_force_delete_temp_snapshot('creating')
111
Masayuki Igawaa279a682014-03-14 13:29:42 +0900112 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800113 def test_snapshot_force_delete_when_snapshot_is_deleting(self):
114 # test force delete when status of snapshot is deleting
115 self._create_reset_and_force_delete_temp_snapshot('deleting')
116
Masayuki Igawaa279a682014-03-14 13:29:42 +0900117 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800118 def test_snapshot_force_delete_when_snapshot_is_error(self):
119 # test force delete when status of snapshot is error
120 self._create_reset_and_force_delete_temp_snapshot('error')
121
Masayuki Igawaa279a682014-03-14 13:29:42 +0900122 @test.attr(type='gate')
wanghaofa3908c2014-01-15 19:34:03 +0800123 def test_snapshot_force_delete_when_snapshot_is_error_deleting(self):
124 # test force delete when status of snapshot is error_deleting
125 self._create_reset_and_force_delete_temp_snapshot('error_deleting')
126
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800127
Chandan Kumar457d1632014-11-18 13:46:08 +0530128class SnapshotsActionsV1Test(SnapshotsActionsV2Test):
129 _api_version = 1