blob: f85718bce34662767ab4f932f6368b6e3cabf695 [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
Zhi Kun Liubb363a22013-11-28 18:47:39 +080021class VolumesActionsTest(base.BaseVolumeV1AdminTest):
wanghaoaa1f2f92013-10-10 11:30:37 +080022 _interface = "json"
23
24 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010025 def resource_setup(cls):
26 super(VolumesActionsTest, cls).resource_setup()
wanghaoaa1f2f92013-10-10 11:30:37 +080027 cls.client = cls.volumes_client
28
29 # Create admin volume client
30 cls.admin_volume_client = cls.os_adm.volumes_client
31
32 # Create a test shared volume for tests
33 vol_name = utils.rand_name(cls.__name__ + '-Volume-')
34
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000035 _, cls.volume = cls.client.create_volume(size=1,
36 display_name=vol_name)
wanghaoaa1f2f92013-10-10 11:30:37 +080037 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
38
39 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010040 def resource_cleanup(cls):
wanghaoaa1f2f92013-10-10 11:30:37 +080041 # Delete the test volume
42 cls.client.delete_volume(cls.volume['id'])
43 cls.client.wait_for_resource_deletion(cls.volume['id'])
44
Andrea Frittoli61a12e22014-09-15 13:14:54 +010045 super(VolumesActionsTest, cls).resource_cleanup()
wanghaoaa1f2f92013-10-10 11:30:37 +080046
47 def _reset_volume_status(self, volume_id, status):
wanghao9d3d6cb2013-11-12 15:10:10 +080048 # Reset the volume status
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000049 _, body = self.admin_volume_client.reset_volume_status(volume_id,
50 status)
51 return _, body
wanghaoaa1f2f92013-10-10 11:30:37 +080052
53 def tearDown(self):
54 # Set volume's status to available after test
55 self._reset_volume_status(self.volume['id'], 'available')
56 super(VolumesActionsTest, self).tearDown()
57
wanghao9d3d6cb2013-11-12 15:10:10 +080058 def _create_temp_volume(self):
59 # Create a temp volume for force delete tests
60 vol_name = utils.rand_name('Volume')
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000061 _, temp_volume = self.client.create_volume(size=1,
62 display_name=vol_name)
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
98class VolumesActionsTestXML(VolumesActionsTest):
99 _interface = "xml"