blob: 8a30a1080a82aaad5f1a5dd05a1f4cb5ea11f175 [file] [log] [blame]
wanghaoaa1f2f92013-10-10 11:30:37 +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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils as utils
17
Zhi Kun Liubb363a22013-11-28 18:47:39 +080018from tempest.api.volume import base
Masayuki Igawaa279a682014-03-14 13:29:42 +090019from tempest import test
wanghaoaa1f2f92013-10-10 11:30:37 +080020
21
Chandan Kumar457d1632014-11-18 13:46:08 +053022class VolumesActionsV2Test(base.BaseVolumeAdminTest):
wanghaoaa1f2f92013-10-10 11:30:37 +080023
24 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053025 def setup_clients(cls):
26 super(VolumesActionsV2Test, cls).setup_clients()
27 cls.client = cls.volumes_client
28
29 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010030 def resource_setup(cls):
Chandan Kumar457d1632014-11-18 13:46:08 +053031 super(VolumesActionsV2Test, cls).resource_setup()
wanghaoaa1f2f92013-10-10 11:30:37 +080032
wanghaoaa1f2f92013-10-10 11:30:37 +080033 # Create a test shared volume for tests
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000034 vol_name = utils.rand_name(cls.__name__ + '-Volume')
Chandan Kumar457d1632014-11-18 13:46:08 +053035 cls.name_field = cls.special_fields['name_field']
36 params = {cls.name_field: vol_name}
wanghaoaa1f2f92013-10-10 11:30:37 +080037
Markus Zoeller3d2a21c2015-02-27 12:04:22 +010038 cls.volume = cls.client.create_volume(**params)
wanghaoaa1f2f92013-10-10 11:30:37 +080039 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
40
41 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010042 def resource_cleanup(cls):
wanghaoaa1f2f92013-10-10 11:30:37 +080043 # Delete the test volume
44 cls.client.delete_volume(cls.volume['id'])
45 cls.client.wait_for_resource_deletion(cls.volume['id'])
46
Chandan Kumar457d1632014-11-18 13:46:08 +053047 super(VolumesActionsV2Test, cls).resource_cleanup()
wanghaoaa1f2f92013-10-10 11:30:37 +080048
49 def _reset_volume_status(self, volume_id, status):
wanghao9d3d6cb2013-11-12 15:10:10 +080050 # Reset the volume status
Joseph Lanoux6809bab2014-12-18 14:57:18 +000051 body = self.admin_volume_client.reset_volume_status(volume_id,
52 status)
53 return body
wanghaoaa1f2f92013-10-10 11:30:37 +080054
55 def tearDown(self):
56 # Set volume's status to available after test
57 self._reset_volume_status(self.volume['id'], 'available')
Chandan Kumar457d1632014-11-18 13:46:08 +053058 super(VolumesActionsV2Test, self).tearDown()
wanghaoaa1f2f92013-10-10 11:30:37 +080059
wanghao9d3d6cb2013-11-12 15:10:10 +080060 def _create_temp_volume(self):
61 # Create a temp volume for force delete tests
62 vol_name = utils.rand_name('Volume')
Chandan Kumar457d1632014-11-18 13:46:08 +053063 params = {self.name_field: vol_name}
Markus Zoeller3d2a21c2015-02-27 12:04:22 +010064 temp_volume = self.client.create_volume(**params)
wanghao9d3d6cb2013-11-12 15:10:10 +080065 self.client.wait_for_volume_status(temp_volume['id'], 'available')
66
67 return temp_volume
68
69 def _create_reset_and_force_delete_temp_volume(self, status=None):
70 # Create volume, reset volume status, and force delete temp volume
71 temp_volume = self._create_temp_volume()
72 if status:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000073 self._reset_volume_status(temp_volume['id'], status)
74 self.admin_volume_client.force_delete_volume(temp_volume['id'])
wanghao9d3d6cb2013-11-12 15:10:10 +080075 self.client.wait_for_resource_deletion(temp_volume['id'])
76
Chris Hoge7579c1a2015-02-26 14:12:15 -080077 @test.idempotent_id('d063f96e-a2e0-4f34-8b8a-395c42de1845')
wanghaoaa1f2f92013-10-10 11:30:37 +080078 def test_volume_reset_status(self):
79 # test volume reset status : available->error->available
Joseph Lanoux6809bab2014-12-18 14:57:18 +000080 self._reset_volume_status(self.volume['id'], 'error')
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000081 volume_get = self.admin_volume_client.show_volume(
wanghaoaa1f2f92013-10-10 11:30:37 +080082 self.volume['id'])
83 self.assertEqual('error', volume_get['status'])
84
Chris Hoge7579c1a2015-02-26 14:12:15 -080085 @test.idempotent_id('21737d5a-92f2-46d7-b009-a0cc0ee7a570')
wanghao9d3d6cb2013-11-12 15:10:10 +080086 def test_volume_force_delete_when_volume_is_creating(self):
87 # test force delete when status of volume is creating
88 self._create_reset_and_force_delete_temp_volume('creating')
89
Chris Hoge7579c1a2015-02-26 14:12:15 -080090 @test.idempotent_id('db8d607a-aa2e-4beb-b51d-d4005c232011')
wanghao9d3d6cb2013-11-12 15:10:10 +080091 def test_volume_force_delete_when_volume_is_attaching(self):
92 # test force delete when status of volume is attaching
93 self._create_reset_and_force_delete_temp_volume('attaching')
94
Chris Hoge7579c1a2015-02-26 14:12:15 -080095 @test.idempotent_id('3e33a8a8-afd4-4d64-a86b-c27a185c5a4a')
wanghao9d3d6cb2013-11-12 15:10:10 +080096 def test_volume_force_delete_when_volume_is_error(self):
97 # test force delete when status of volume is error
98 self._create_reset_and_force_delete_temp_volume('error')
99
wanghaoaa1f2f92013-10-10 11:30:37 +0800100
Chandan Kumar457d1632014-11-18 13:46:08 +0530101class VolumesActionsV1Test(VolumesActionsV2Test):
102 _api_version = 1