blob: 469f13ee2ee9e1cd3003b3b595fb0687b1accd8e [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
Rohan Kanade05749152015-01-30 17:15:18 +053024 def setup_clients(cls):
25 super(SnapshotsActionsV2Test, cls).setup_clients()
26 cls.client = cls.snapshots_client
27
28 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010029 def resource_setup(cls):
Chandan Kumar457d1632014-11-18 13:46:08 +053030 super(SnapshotsActionsV2Test, cls).resource_setup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080031
zhangyanzid4d3c6d2013-11-06 09:27:13 +080032 # Create a test shared volume for tests
33 vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
Chandan Kumar457d1632014-11-18 13:46:08 +053034 cls.name_field = cls.special_fields['name_field']
35 params = {cls.name_field: vol_name}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000036 cls.volume = \
Chandan Kumar457d1632014-11-18 13:46:08 +053037 cls.volumes_client.create_volume(size=1, **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080038 cls.volumes_client.wait_for_volume_status(cls.volume['id'],
39 'available')
40
41 # Create a test shared snapshot for tests
42 snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-')
Chandan Kumar457d1632014-11-18 13:46:08 +053043 params = {cls.name_field: snap_name}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000044 cls.snapshot = \
Chandan Kumar457d1632014-11-18 13:46:08 +053045 cls.client.create_snapshot(cls.volume['id'], **params)
zhangyanzid4d3c6d2013-11-06 09:27:13 +080046 cls.client.wait_for_snapshot_status(cls.snapshot['id'],
47 'available')
48
49 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010050 def resource_cleanup(cls):
zhangyanzid4d3c6d2013-11-06 09:27:13 +080051 # Delete the test snapshot
52 cls.client.delete_snapshot(cls.snapshot['id'])
53 cls.client.wait_for_resource_deletion(cls.snapshot['id'])
54
55 # Delete the test volume
56 cls.volumes_client.delete_volume(cls.volume['id'])
57 cls.volumes_client.wait_for_resource_deletion(cls.volume['id'])
58
Chandan Kumar457d1632014-11-18 13:46:08 +053059 super(SnapshotsActionsV2Test, cls).resource_cleanup()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080060
61 def tearDown(self):
62 # Set snapshot's status to available after test
63 status = 'available'
64 snapshot_id = self.snapshot['id']
65 self.admin_snapshots_client.reset_snapshot_status(snapshot_id,
66 status)
Chandan Kumar457d1632014-11-18 13:46:08 +053067 super(SnapshotsActionsV2Test, self).tearDown()
zhangyanzid4d3c6d2013-11-06 09:27:13 +080068
wanghaofa3908c2014-01-15 19:34:03 +080069 def _create_reset_and_force_delete_temp_snapshot(self, status=None):
70 # Create snapshot, reset snapshot status,
71 # and force delete temp snapshot
72 temp_snapshot = self.create_snapshot(self.volume['id'])
73 if status:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000074 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080075 reset_snapshot_status(temp_snapshot['id'], status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000076 self.admin_snapshots_client.\
wanghaofa3908c2014-01-15 19:34:03 +080077 force_delete_snapshot(temp_snapshot['id'])
wanghaofa3908c2014-01-15 19:34:03 +080078 self.client.wait_for_resource_deletion(temp_snapshot['id'])
79
zhangyanzid4d3c6d2013-11-06 09:27:13 +080080 def _get_progress_alias(self):
81 return 'os-extended-snapshot-attributes:progress'
82
Masayuki Igawaa279a682014-03-14 13:29:42 +090083 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('3e13ca2f-48ea-49f3-ae1a-488e9180d535')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080085 def test_reset_snapshot_status(self):
86 # Reset snapshot status to creating
87 status = 'creating'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000088 self.admin_snapshots_client.\
zhangyanzid4d3c6d2013-11-06 09:27:13 +080089 reset_snapshot_status(self.snapshot['id'], status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000090 snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +080091 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +080092 self.assertEqual(status, snapshot_get['status'])
93
Masayuki Igawaa279a682014-03-14 13:29:42 +090094 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080095 @test.idempotent_id('41288afd-d463-485e-8f6e-4eea159413eb')
zhangyanzid4d3c6d2013-11-06 09:27:13 +080096 def test_update_snapshot_status(self):
97 # Reset snapshot status to creating
98 status = 'creating'
99 self.admin_snapshots_client.\
100 reset_snapshot_status(self.snapshot['id'], status)
101
102 # Update snapshot status to error
103 progress = '80%'
104 status = 'error'
105 progress_alias = self._get_progress_alias()
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000106 self.client.update_snapshot_status(self.snapshot['id'],
107 status, progress)
108 snapshot_get \
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800109 = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800110 self.assertEqual(status, snapshot_get['status'])
111 self.assertEqual(progress, snapshot_get[progress_alias])
112
Masayuki Igawaa279a682014-03-14 13:29:42 +0900113 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800114 @test.idempotent_id('05f711b6-e629-4895-8103-7ca069f2073a')
wanghaofa3908c2014-01-15 19:34:03 +0800115 def test_snapshot_force_delete_when_snapshot_is_creating(self):
116 # test force delete when status of snapshot is creating
117 self._create_reset_and_force_delete_temp_snapshot('creating')
118
Masayuki Igawaa279a682014-03-14 13:29:42 +0900119 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800120 @test.idempotent_id('92ce8597-b992-43a1-8868-6316b22a969e')
wanghaofa3908c2014-01-15 19:34:03 +0800121 def test_snapshot_force_delete_when_snapshot_is_deleting(self):
122 # test force delete when status of snapshot is deleting
123 self._create_reset_and_force_delete_temp_snapshot('deleting')
124
Masayuki Igawaa279a682014-03-14 13:29:42 +0900125 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800126 @test.idempotent_id('645a4a67-a1eb-4e8e-a547-600abac1525d')
wanghaofa3908c2014-01-15 19:34:03 +0800127 def test_snapshot_force_delete_when_snapshot_is_error(self):
128 # test force delete when status of snapshot is error
129 self._create_reset_and_force_delete_temp_snapshot('error')
130
Masayuki Igawaa279a682014-03-14 13:29:42 +0900131 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800132 @test.idempotent_id('bf89080f-8129-465e-9327-b2f922666ba5')
wanghaofa3908c2014-01-15 19:34:03 +0800133 def test_snapshot_force_delete_when_snapshot_is_error_deleting(self):
134 # test force delete when status of snapshot is error_deleting
135 self._create_reset_and_force_delete_temp_snapshot('error_deleting')
136
zhangyanzid4d3c6d2013-11-06 09:27:13 +0800137
Chandan Kumar457d1632014-11-18 13:46:08 +0530138class SnapshotsActionsV1Test(SnapshotsActionsV2Test):
139 _api_version = 1