blob: 1c3e04a505835014cd2cdc0b4ae4f74520e7a3d3 [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
Zhi Kun Liubb363a22013-11-28 18:47:39 +080016from tempest.api.volume import base
wanghaoaa1f2f92013-10-10 11:30:37 +080017from tempest.common.utils import data_utils as utils
Masayuki Igawaa279a682014-03-14 13:29:42 +090018from tempest import test
wanghaoaa1f2f92013-10-10 11:30:37 +080019
20
Chandan Kumar457d1632014-11-18 13:46:08 +053021class VolumesActionsV2Test(base.BaseVolumeAdminTest):
wanghaoaa1f2f92013-10-10 11:30:37 +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(VolumesActionsV2Test, cls).resource_setup()
wanghaoaa1f2f92013-10-10 11:30:37 +080027 cls.client = cls.volumes_client
28
wanghaoaa1f2f92013-10-10 11:30:37 +080029 # Create a test shared volume for tests
30 vol_name = 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}
wanghaoaa1f2f92013-10-10 11:30:37 +080033
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000034 _, cls.volume = cls.client.create_volume(size=1,
Chandan Kumar457d1632014-11-18 13:46:08 +053035 **params)
wanghaoaa1f2f92013-10-10 11:30:37 +080036 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
37
38 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010039 def resource_cleanup(cls):
wanghaoaa1f2f92013-10-10 11:30:37 +080040 # Delete the test volume
41 cls.client.delete_volume(cls.volume['id'])
42 cls.client.wait_for_resource_deletion(cls.volume['id'])
43
Chandan Kumar457d1632014-11-18 13:46:08 +053044 super(VolumesActionsV2Test, cls).resource_cleanup()
wanghaoaa1f2f92013-10-10 11:30:37 +080045
46 def _reset_volume_status(self, volume_id, status):
wanghao9d3d6cb2013-11-12 15:10:10 +080047 # Reset the volume status
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000048 _, body = self.admin_volume_client.reset_volume_status(volume_id,
49 status)
50 return _, body
wanghaoaa1f2f92013-10-10 11:30:37 +080051
52 def tearDown(self):
53 # Set volume's status to available after test
54 self._reset_volume_status(self.volume['id'], 'available')
Chandan Kumar457d1632014-11-18 13:46:08 +053055 super(VolumesActionsV2Test, self).tearDown()
wanghaoaa1f2f92013-10-10 11:30:37 +080056
wanghao9d3d6cb2013-11-12 15:10:10 +080057 def _create_temp_volume(self):
58 # Create a temp volume for force delete tests
59 vol_name = utils.rand_name('Volume')
Chandan Kumar457d1632014-11-18 13:46:08 +053060 params = {self.name_field: vol_name}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000061 _, temp_volume = self.client.create_volume(size=1,
Chandan Kumar457d1632014-11-18 13:46:08 +053062 **params)
wanghao9d3d6cb2013-11-12 15:10:10 +080063 self.client.wait_for_volume_status(temp_volume['id'], 'available')
64
65 return temp_volume
66
67 def _create_reset_and_force_delete_temp_volume(self, status=None):
68 # Create volume, reset volume status, and force delete temp volume
69 temp_volume = self._create_temp_volume()
70 if status:
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000071 _, body = self._reset_volume_status(temp_volume['id'], status)
72 _, volume_delete = self.admin_volume_client.\
wanghao9d3d6cb2013-11-12 15:10:10 +080073 force_delete_volume(temp_volume['id'])
wanghao9d3d6cb2013-11-12 15:10:10 +080074 self.client.wait_for_resource_deletion(temp_volume['id'])
75
Masayuki Igawaa279a682014-03-14 13:29:42 +090076 @test.attr(type='gate')
wanghaoaa1f2f92013-10-10 11:30:37 +080077 def test_volume_reset_status(self):
78 # test volume reset status : available->error->available
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000079 _, body = self._reset_volume_status(self.volume['id'], 'error')
80 _, volume_get = self.admin_volume_client.get_volume(
wanghaoaa1f2f92013-10-10 11:30:37 +080081 self.volume['id'])
82 self.assertEqual('error', volume_get['status'])
83
wanghao9d3d6cb2013-11-12 15:10:10 +080084 def test_volume_force_delete_when_volume_is_creating(self):
85 # test force delete when status of volume is creating
86 self._create_reset_and_force_delete_temp_volume('creating')
87
88 def test_volume_force_delete_when_volume_is_attaching(self):
89 # test force delete when status of volume is attaching
90 self._create_reset_and_force_delete_temp_volume('attaching')
91
Masayuki Igawaa279a682014-03-14 13:29:42 +090092 @test.attr(type='gate')
wanghao9d3d6cb2013-11-12 15:10:10 +080093 def test_volume_force_delete_when_volume_is_error(self):
94 # test force delete when status of volume is error
95 self._create_reset_and_force_delete_temp_volume('error')
96
wanghaoaa1f2f92013-10-10 11:30:37 +080097
Chandan Kumar457d1632014-11-18 13:46:08 +053098class VolumesActionsV1Test(VolumesActionsV2Test):
99 _api_version = 1
100
101
102class VolumesActionsV1TestXML(VolumesActionsV1Test):
wanghaoaa1f2f92013-10-10 11:30:37 +0800103 _interface = "xml"