blob: 5b50bfa5adb95e925ddf5cb3c9fc0fc4a986ec0b [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgia42fe442012-09-21 03:08:33 -07002# 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
Andrea Frittolicd368412017-08-14 21:37:56 +010017from tempest.common import utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000018from tempest.common import waiters
Matthew Treinish4d352bc2014-01-29 18:29:18 +000019from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080020from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010021from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080022from tempest.lib import decorators
Rohit Karajgia42fe442012-09-21 03:08:33 -070023
Matthew Treinish4d352bc2014-01-29 18:29:18 +000024CONF = config.CONF
25
Rohit Karajgia42fe442012-09-21 03:08:33 -070026
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070027class VolumesActionsTest(base.BaseVolumeTest):
zhufla5682372020-08-14 14:56:57 +080028 """Test volume actions"""
29
Ghanshyam Mann7d91b692020-03-03 10:21:50 -060030 create_default_network = True
Rohit Karajgia42fe442012-09-21 03:08:33 -070031
32 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053033 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070034 super(VolumesActionsTest, cls).resource_setup()
Rohit Karajgia42fe442012-09-21 03:08:33 -070035
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090036 # Create a test shared volume for attach/detach tests
37 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070038
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080039 @decorators.idempotent_id('fff42874-7db5-4487-a8e1-ddda5fb5288d')
Jordan Pittier3b46d272017-04-12 16:17:28 +020040 @decorators.attr(type='smoke')
Andrea Frittolicd368412017-08-14 21:37:56 +010041 @utils.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070042 def test_attach_detach_volume_to_instance(self):
zhufla5682372020-08-14 14:56:57 +080043 """Test attaching and detaching volume to instance"""
lkuchlan5fc69362016-09-05 08:42:34 +030044 # Create a server
lkuchland4ecd0e2017-06-11 12:01:27 +030045 server = self.create_server()
Sean Dague72a00382013-01-03 17:53:38 -050046 # Volume is attached and detached successfully from an instance
lkuchlan76d80b52017-04-03 12:29:57 +030047 self.volumes_client.attach_volume(self.volume['id'],
48 instance_uuid=server['id'],
49 mountpoint='/dev/%s' %
50 CONF.compute.volume_device_name)
51 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020052 self.volume['id'], 'in-use')
lkuchlan76d80b52017-04-03 12:29:57 +030053 self.volumes_client.detach_volume(self.volume['id'])
54 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020055 self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070056
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080057 @decorators.idempotent_id('63e21b4c-0a0c-41f6-bfc3-7c2816815599')
bkopilov8a657ae2015-05-11 11:45:23 +030058 def test_volume_bootable(self):
zhufla5682372020-08-14 14:56:57 +080059 """Test setting and retrieving bootable flag of a volume"""
bkopilov8a657ae2015-05-11 11:45:23 +030060 for bool_bootable in [True, False]:
lkuchlan76d80b52017-04-03 12:29:57 +030061 self.volumes_client.set_bootable_volume(self.volume['id'],
62 bootable=bool_bootable)
63 fetched_volume = self.volumes_client.show_volume(
John Warren6177c9e2015-08-19 20:00:17 +000064 self.volume['id'])['volume']
bkopilov8a657ae2015-05-11 11:45:23 +030065 # Get Volume information
Masayuki Igawa50627462016-11-29 15:53:14 +090066 # NOTE(masayukig): 'bootable' is "true" or "false" in the current
67 # cinder implementation. So we need to cast boolean values to str
68 # and make it lower to compare here.
69 self.assertEqual(str(bool_bootable).lower(),
70 fetched_volume['bootable'])
bkopilov8a657ae2015-05-11 11:45:23 +030071
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080072 @decorators.idempotent_id('9516a2c8-9135-488c-8dd6-5677a7e5f371')
Andrea Frittolicd368412017-08-14 21:37:56 +010073 @utils.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070074 def test_get_volume_attachment(self):
zhufla5682372020-08-14 14:56:57 +080075 """Test getting volume attachments
76
77 Attach a volume to a server, and then retrieve volume's attachments
78 info.
79 """
lkuchlan5fc69362016-09-05 08:42:34 +030080 # Create a server
lkuchland4ecd0e2017-06-11 12:01:27 +030081 server = self.create_server()
Sean Dague72a00382013-01-03 17:53:38 -050082 # Verify that a volume's attachment information is retrieved
lkuchlan76d80b52017-04-03 12:29:57 +030083 self.volumes_client.attach_volume(self.volume['id'],
84 instance_uuid=server['id'],
85 mountpoint='/dev/%s' %
86 CONF.compute.volume_device_name)
87 waiters.wait_for_volume_resource_status(self.volumes_client,
88 self.volume['id'],
lkuchlan52d7b0d2016-11-07 20:53:19 +020089 'in-use')
lkuchlan76d80b52017-04-03 12:29:57 +030090 self.addCleanup(waiters.wait_for_volume_resource_status,
91 self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020092 self.volume['id'], 'available')
lkuchlan76d80b52017-04-03 12:29:57 +030093 self.addCleanup(self.volumes_client.detach_volume, self.volume['id'])
94 volume = self.volumes_client.show_volume(self.volume['id'])['volume']
Ken'ichi Ohmichi84a5f962016-08-26 15:34:26 -070095 attachment = volume['attachments'][0]
96
bkopilovbc830d02016-03-27 14:09:47 +030097 self.assertEqual('/dev/%s' %
98 CONF.compute.volume_device_name,
99 attachment['device'])
lkuchlan5fc69362016-09-05 08:42:34 +0300100 self.assertEqual(server['id'], attachment['server_id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200101 self.assertEqual(self.volume['id'], attachment['id'])
102 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +0200103
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800104 @decorators.idempotent_id('d8f1ca95-3d5b-44a3-b8ca-909691c9532d')
Andrea Frittolicd368412017-08-14 21:37:56 +0100105 @utils.services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +0200106 def test_volume_upload(self):
zhufla5682372020-08-14 14:56:57 +0800107 """Test uploading volume to create an image"""
Giulio Fidente884e9da2013-06-21 17:25:42 +0200108 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
109 # it is shared with the other tests. After it is uploaded in Glance,
110 # there is no way to delete it from Cinder, so we delete it from Glance
lkuchlan153df152017-04-25 16:43:47 +0300111 # using the Glance images_client and from Cinder via tearDownClass.
zhuflc6ce5392016-08-17 14:34:37 +0800112 image_name = data_utils.rand_name(self.__class__.__name__ + '-Image')
lkuchlan76d80b52017-04-03 12:29:57 +0300113 body = self.volumes_client.upload_volume(
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900114 self.volume['id'], image_name=image_name,
115 disk_format=CONF.volume.disk_format)['os-volume_upload_image']
Giulio Fidente884e9da2013-06-21 17:25:42 +0200116 image_id = body["image_id"]
Jordan Pittier9e227c52016-02-09 14:35:18 +0100117 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800118 self.images_client.delete_image,
Jordan Pittier9e227c52016-02-09 14:35:18 +0100119 image_id)
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800120 waiters.wait_for_image_status(self.images_client, image_id, 'active')
lkuchlan76d80b52017-04-03 12:29:57 +0300121 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +0200122 self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530123
lkuchlanc1ebf652017-04-03 12:15:28 +0300124 image_info = self.images_client.show_image(image_id)
125 self.assertEqual(image_name, image_info['name'])
126 self.assertEqual(CONF.volume.disk_format, image_info['disk_format'])
127
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800128 @decorators.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33')
zhangyanzi6b632432013-10-24 19:08:50 +0800129 def test_reserve_unreserve_volume(self):
zhufla5682372020-08-14 14:56:57 +0800130 """Test reserving and unreserving volume"""
zhangyanzi6b632432013-10-24 19:08:50 +0800131 # Mark volume as reserved.
jeremy.zhange280f662017-06-30 17:38:58 +0800132 self.volumes_client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800133 # To get the volume info
lkuchlan76d80b52017-04-03 12:29:57 +0300134 body = self.volumes_client.show_volume(self.volume['id'])['volume']
zhangyanzi6b632432013-10-24 19:08:50 +0800135 self.assertIn('attaching', body['status'])
136 # Unmark volume as reserved.
jeremy.zhange280f662017-06-30 17:38:58 +0800137 self.volumes_client.unreserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800138 # To get the volume info
lkuchlan76d80b52017-04-03 12:29:57 +0300139 body = self.volumes_client.show_volume(self.volume['id'])['volume']
zhangyanzi6b632432013-10-24 19:08:50 +0800140 self.assertIn('available', body['status'])
141
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800142 @decorators.idempotent_id('fff74e1e-5bd3-4b33-9ea9-24c103bc3f59')
zhangyanziaa180072013-11-21 12:31:26 +0800143 def test_volume_readonly_update(self):
zhufla5682372020-08-14 14:56:57 +0800144 """Test updating and retrieve volume's readonly flag"""
zhuflf9b46942016-10-09 11:23:46 +0800145 for readonly in [True, False]:
146 # Update volume readonly
lkuchlan76d80b52017-04-03 12:29:57 +0300147 self.volumes_client.update_volume_readonly(self.volume['id'],
148 readonly=readonly)
zhuflf9b46942016-10-09 11:23:46 +0800149 # Get Volume information
lkuchlan76d80b52017-04-03 12:29:57 +0300150 fetched_volume = self.volumes_client.show_volume(
zhuflf9b46942016-10-09 11:23:46 +0800151 self.volume['id'])['volume']
Masayuki Igawa50627462016-11-29 15:53:14 +0900152 # NOTE(masayukig): 'readonly' is "True" or "False" in the current
153 # cinder implementation. So we need to cast boolean values to str
154 # to compare here.
155 self.assertEqual(str(readonly),
156 fetched_volume['metadata']['readonly'])