blob: 6c32321fc70831776f88b575d81d10b782f2264c [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from 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
23 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053024 def setup_clients(cls):
25 super(VolumesActionsV2Test, cls).setup_clients()
26 cls.client = cls.volumes_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(VolumesActionsV2Test, cls).resource_setup()
wanghaoaa1f2f92013-10-10 11:30:37 +080031
wanghaoaa1f2f92013-10-10 11:30:37 +080032 # Create a test shared volume for tests
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000033 vol_name = 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}
wanghaoaa1f2f92013-10-10 11:30:37 +080036
John Warren6177c9e2015-08-19 20:00:17 +000037 cls.volume = cls.client.create_volume(**params)['volume']
wanghaoaa1f2f92013-10-10 11:30:37 +080038 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
39
40 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010041 def resource_cleanup(cls):
wanghaoaa1f2f92013-10-10 11:30:37 +080042 # Delete the test volume
43 cls.client.delete_volume(cls.volume['id'])
44 cls.client.wait_for_resource_deletion(cls.volume['id'])
45
Chandan Kumar457d1632014-11-18 13:46:08 +053046 super(VolumesActionsV2Test, cls).resource_cleanup()
wanghaoaa1f2f92013-10-10 11:30:37 +080047
48 def _reset_volume_status(self, volume_id, status):
wanghao9d3d6cb2013-11-12 15:10:10 +080049 # Reset the volume status
Joseph Lanoux6809bab2014-12-18 14:57:18 +000050 body = self.admin_volume_client.reset_volume_status(volume_id,
51 status)
52 return body
wanghaoaa1f2f92013-10-10 11:30:37 +080053
54 def tearDown(self):
55 # Set volume's status to available after test
56 self._reset_volume_status(self.volume['id'], 'available')
Chandan Kumar457d1632014-11-18 13:46:08 +053057 super(VolumesActionsV2Test, self).tearDown()
wanghaoaa1f2f92013-10-10 11:30:37 +080058
wanghao9d3d6cb2013-11-12 15:10:10 +080059 def _create_temp_volume(self):
60 # Create a temp volume for force delete tests
61 vol_name = utils.rand_name('Volume')
Chandan Kumar457d1632014-11-18 13:46:08 +053062 params = {self.name_field: vol_name}
John Warren6177c9e2015-08-19 20:00:17 +000063 temp_volume = self.client.create_volume(**params)['volume']
wanghao9d3d6cb2013-11-12 15:10:10 +080064 self.client.wait_for_volume_status(temp_volume['id'], 'available')
65
66 return temp_volume
67
68 def _create_reset_and_force_delete_temp_volume(self, status=None):
69 # Create volume, reset volume status, and force delete temp volume
70 temp_volume = self._create_temp_volume()
71 if status:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000072 self._reset_volume_status(temp_volume['id'], status)
73 self.admin_volume_client.force_delete_volume(temp_volume['id'])
wanghao9d3d6cb2013-11-12 15:10:10 +080074 self.client.wait_for_resource_deletion(temp_volume['id'])
75
Chris Hoge7579c1a2015-02-26 14:12:15 -080076 @test.idempotent_id('d063f96e-a2e0-4f34-8b8a-395c42de1845')
wanghaoaa1f2f92013-10-10 11:30:37 +080077 def test_volume_reset_status(self):
78 # test volume reset status : available->error->available
Joseph Lanoux6809bab2014-12-18 14:57:18 +000079 self._reset_volume_status(self.volume['id'], 'error')
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000080 volume_get = self.admin_volume_client.show_volume(
John Warren6177c9e2015-08-19 20:00:17 +000081 self.volume['id'])['volume']
wanghaoaa1f2f92013-10-10 11:30:37 +080082 self.assertEqual('error', volume_get['status'])
83
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('21737d5a-92f2-46d7-b009-a0cc0ee7a570')
wanghao9d3d6cb2013-11-12 15:10:10 +080085 def test_volume_force_delete_when_volume_is_creating(self):
86 # test force delete when status of volume is creating
87 self._create_reset_and_force_delete_temp_volume('creating')
88
Chris Hoge7579c1a2015-02-26 14:12:15 -080089 @test.idempotent_id('db8d607a-aa2e-4beb-b51d-d4005c232011')
wanghao9d3d6cb2013-11-12 15:10:10 +080090 def test_volume_force_delete_when_volume_is_attaching(self):
91 # test force delete when status of volume is attaching
92 self._create_reset_and_force_delete_temp_volume('attaching')
93
Chris Hoge7579c1a2015-02-26 14:12:15 -080094 @test.idempotent_id('3e33a8a8-afd4-4d64-a86b-c27a185c5a4a')
wanghao9d3d6cb2013-11-12 15:10:10 +080095 def test_volume_force_delete_when_volume_is_error(self):
96 # test force delete when status of volume is error
97 self._create_reset_and_force_delete_temp_volume('error')
98
wanghaoaa1f2f92013-10-10 11:30:37 +080099
Chandan Kumar457d1632014-11-18 13:46:08 +0530100class VolumesActionsV1Test(VolumesActionsV2Test):
101 _api_version = 1