blob: acff7cd2d2840368a253dd13638688115c891dd2 [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
jeremy.zhang7b0eaf82017-04-25 15:11:15 +080017from tempest.common import waiters
18from tempest import config
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080019from tempest.lib import decorators
jeremy.zhang7b0eaf82017-04-25 15:11:15 +080020from tempest import test
21
22CONF = config.CONF
wanghaoaa1f2f92013-10-10 11:30:37 +080023
24
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070025class VolumesActionsTest(base.BaseVolumeAdminTest):
wanghaoaa1f2f92013-10-10 11:30:37 +080026
wanghao9d3d6cb2013-11-12 15:10:10 +080027 def _create_reset_and_force_delete_temp_volume(self, status=None):
28 # Create volume, reset volume status, and force delete temp volume
zhufl89403442016-10-09 16:19:28 +080029 temp_volume = self.create_volume()
wanghao9d3d6cb2013-11-12 15:10:10 +080030 if status:
zhufl7e75fcb2016-10-17 09:00:40 +080031 self.admin_volume_client.reset_volume_status(
32 temp_volume['id'], status=status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000033 self.admin_volume_client.force_delete_volume(temp_volume['id'])
lkuchlanb21fc572016-11-28 12:25:22 +020034 self.volumes_client.wait_for_resource_deletion(temp_volume['id'])
wanghao9d3d6cb2013-11-12 15:10:10 +080035
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080036 @decorators.idempotent_id('d063f96e-a2e0-4f34-8b8a-395c42de1845')
wanghaoaa1f2f92013-10-10 11:30:37 +080037 def test_volume_reset_status(self):
38 # test volume reset status : available->error->available
zhufl7a682fe2016-12-15 17:20:00 +080039 volume = self.create_volume()
Benny Kopilovba37ac42017-03-26 13:25:04 +030040 self.addCleanup(self.admin_volume_client.reset_volume_status,
41 volume['id'], status='available')
42 for status in ['error', 'available', 'maintenance']:
zhufl7a682fe2016-12-15 17:20:00 +080043 self.admin_volume_client.reset_volume_status(
44 volume['id'], status=status)
45 volume_get = self.admin_volume_client.show_volume(
46 volume['id'])['volume']
47 self.assertEqual(status, volume_get['status'])
wanghaoaa1f2f92013-10-10 11:30:37 +080048
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080049 @decorators.idempotent_id('21737d5a-92f2-46d7-b009-a0cc0ee7a570')
wanghao9d3d6cb2013-11-12 15:10:10 +080050 def test_volume_force_delete_when_volume_is_creating(self):
51 # test force delete when status of volume is creating
52 self._create_reset_and_force_delete_temp_volume('creating')
53
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080054 @decorators.idempotent_id('db8d607a-aa2e-4beb-b51d-d4005c232011')
wanghao9d3d6cb2013-11-12 15:10:10 +080055 def test_volume_force_delete_when_volume_is_attaching(self):
56 # test force delete when status of volume is attaching
57 self._create_reset_and_force_delete_temp_volume('attaching')
58
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080059 @decorators.idempotent_id('3e33a8a8-afd4-4d64-a86b-c27a185c5a4a')
wanghao9d3d6cb2013-11-12 15:10:10 +080060 def test_volume_force_delete_when_volume_is_error(self):
61 # test force delete when status of volume is error
62 self._create_reset_and_force_delete_temp_volume('error')
Benny Kopilov63fe58f2017-03-26 13:31:46 +030063
64 @decorators.idempotent_id('b957cabd-1486-4e21-90cf-a9ed3c39dfb2')
65 def test_volume_force_delete_when_volume_is_maintenance(self):
66 # test force delete when status of volume is maintenance
67 self._create_reset_and_force_delete_temp_volume('maintenance')
jeremy.zhang7b0eaf82017-04-25 15:11:15 +080068
69 @decorators.idempotent_id('d38285d9-929d-478f-96a5-00e66a115b81')
70 @test.services('compute')
71 def test_force_detach_volume(self):
72 # Create a server and a volume
73 server_id = self.create_server(wait_until='ACTIVE')['id']
74 volume_id = self.create_volume()['id']
75
76 # Attach volume
77 self.volumes_client.attach_volume(
78 volume_id,
79 instance_uuid=server_id,
80 mountpoint='/dev/%s' % CONF.compute.volume_device_name)
81 waiters.wait_for_volume_resource_status(self.volumes_client,
82 volume_id, 'in-use')
83 self.addCleanup(waiters.wait_for_volume_resource_status,
84 self.volumes_client, volume_id, 'available')
85 self.addCleanup(self.volumes_client.detach_volume, volume_id)
86 attachment = self.volumes_client.show_volume(
87 volume_id)['volume']['attachments'][0]
88
89 # Reset volume's status to error
90 self.admin_volume_client.reset_volume_status(volume_id, status='error')
91
92 # Force detach volume
93 self.admin_volume_client.force_detach_volume(
94 volume_id, connector=None,
95 attachment_id=attachment['attachment_id'])
96 waiters.wait_for_volume_resource_status(self.volumes_client,
97 volume_id, 'available')
98 vol_info = self.volumes_client.show_volume(volume_id)['volume']
99 self.assertIn('attachments', vol_info)
100 self.assertEmpty(vol_info['attachments'])