blob: 9edffc697b7274686f3ae44b12971dcdbcd5a451 [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):
Ghanshyam Mann7d91b692020-03-03 10:21:50 -060028 create_default_network = True
Rohit Karajgia42fe442012-09-21 03:08:33 -070029
30 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053031 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070032 super(VolumesActionsTest, cls).resource_setup()
Rohit Karajgia42fe442012-09-21 03:08:33 -070033
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090034 # Create a test shared volume for attach/detach tests
35 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070036
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080037 @decorators.idempotent_id('fff42874-7db5-4487-a8e1-ddda5fb5288d')
Jordan Pittier3b46d272017-04-12 16:17:28 +020038 @decorators.attr(type='smoke')
Andrea Frittolicd368412017-08-14 21:37:56 +010039 @utils.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070040 def test_attach_detach_volume_to_instance(self):
lkuchlan5fc69362016-09-05 08:42:34 +030041 # Create a server
lkuchland4ecd0e2017-06-11 12:01:27 +030042 server = self.create_server()
Sean Dague72a00382013-01-03 17:53:38 -050043 # Volume is attached and detached successfully from an instance
lkuchlan76d80b52017-04-03 12:29:57 +030044 self.volumes_client.attach_volume(self.volume['id'],
45 instance_uuid=server['id'],
46 mountpoint='/dev/%s' %
47 CONF.compute.volume_device_name)
48 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020049 self.volume['id'], 'in-use')
lkuchlan76d80b52017-04-03 12:29:57 +030050 self.volumes_client.detach_volume(self.volume['id'])
51 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020052 self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070053
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080054 @decorators.idempotent_id('63e21b4c-0a0c-41f6-bfc3-7c2816815599')
bkopilov8a657ae2015-05-11 11:45:23 +030055 def test_volume_bootable(self):
56 # Verify that a volume bootable flag is retrieved
57 for bool_bootable in [True, False]:
lkuchlan76d80b52017-04-03 12:29:57 +030058 self.volumes_client.set_bootable_volume(self.volume['id'],
59 bootable=bool_bootable)
60 fetched_volume = self.volumes_client.show_volume(
John Warren6177c9e2015-08-19 20:00:17 +000061 self.volume['id'])['volume']
bkopilov8a657ae2015-05-11 11:45:23 +030062 # Get Volume information
Masayuki Igawa50627462016-11-29 15:53:14 +090063 # NOTE(masayukig): 'bootable' is "true" or "false" in the current
64 # cinder implementation. So we need to cast boolean values to str
65 # and make it lower to compare here.
66 self.assertEqual(str(bool_bootable).lower(),
67 fetched_volume['bootable'])
bkopilov8a657ae2015-05-11 11:45:23 +030068
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080069 @decorators.idempotent_id('9516a2c8-9135-488c-8dd6-5677a7e5f371')
Andrea Frittolicd368412017-08-14 21:37:56 +010070 @utils.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070071 def test_get_volume_attachment(self):
lkuchlan5fc69362016-09-05 08:42:34 +030072 # Create a server
lkuchland4ecd0e2017-06-11 12:01:27 +030073 server = self.create_server()
Sean Dague72a00382013-01-03 17:53:38 -050074 # Verify that a volume's attachment information is retrieved
lkuchlan76d80b52017-04-03 12:29:57 +030075 self.volumes_client.attach_volume(self.volume['id'],
76 instance_uuid=server['id'],
77 mountpoint='/dev/%s' %
78 CONF.compute.volume_device_name)
79 waiters.wait_for_volume_resource_status(self.volumes_client,
80 self.volume['id'],
lkuchlan52d7b0d2016-11-07 20:53:19 +020081 'in-use')
lkuchlan76d80b52017-04-03 12:29:57 +030082 self.addCleanup(waiters.wait_for_volume_resource_status,
83 self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020084 self.volume['id'], 'available')
lkuchlan76d80b52017-04-03 12:29:57 +030085 self.addCleanup(self.volumes_client.detach_volume, self.volume['id'])
86 volume = self.volumes_client.show_volume(self.volume['id'])['volume']
Giulio Fidente92f77192013-08-26 17:13:28 +020087 self.assertIn('attachments', volume)
Ken'ichi Ohmichi84a5f962016-08-26 15:34:26 -070088 attachment = volume['attachments'][0]
89
bkopilovbc830d02016-03-27 14:09:47 +030090 self.assertEqual('/dev/%s' %
91 CONF.compute.volume_device_name,
92 attachment['device'])
lkuchlan5fc69362016-09-05 08:42:34 +030093 self.assertEqual(server['id'], attachment['server_id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020094 self.assertEqual(self.volume['id'], attachment['id'])
95 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020096
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080097 @decorators.idempotent_id('d8f1ca95-3d5b-44a3-b8ca-909691c9532d')
Andrea Frittolicd368412017-08-14 21:37:56 +010098 @utils.services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +020099 def test_volume_upload(self):
100 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
101 # it is shared with the other tests. After it is uploaded in Glance,
102 # there is no way to delete it from Cinder, so we delete it from Glance
lkuchlan153df152017-04-25 16:43:47 +0300103 # using the Glance images_client and from Cinder via tearDownClass.
zhuflc6ce5392016-08-17 14:34:37 +0800104 image_name = data_utils.rand_name(self.__class__.__name__ + '-Image')
lkuchlan76d80b52017-04-03 12:29:57 +0300105 body = self.volumes_client.upload_volume(
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900106 self.volume['id'], image_name=image_name,
107 disk_format=CONF.volume.disk_format)['os-volume_upload_image']
Giulio Fidente884e9da2013-06-21 17:25:42 +0200108 image_id = body["image_id"]
Jordan Pittier9e227c52016-02-09 14:35:18 +0100109 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800110 self.images_client.delete_image,
Jordan Pittier9e227c52016-02-09 14:35:18 +0100111 image_id)
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800112 waiters.wait_for_image_status(self.images_client, image_id, 'active')
lkuchlan76d80b52017-04-03 12:29:57 +0300113 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +0200114 self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530115
lkuchlanc1ebf652017-04-03 12:15:28 +0300116 image_info = self.images_client.show_image(image_id)
117 self.assertEqual(image_name, image_info['name'])
118 self.assertEqual(CONF.volume.disk_format, image_info['disk_format'])
119
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800120 @decorators.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33')
zhangyanzi6b632432013-10-24 19:08:50 +0800121 def test_reserve_unreserve_volume(self):
122 # Mark volume as reserved.
jeremy.zhange280f662017-06-30 17:38:58 +0800123 self.volumes_client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800124 # To get the volume info
lkuchlan76d80b52017-04-03 12:29:57 +0300125 body = self.volumes_client.show_volume(self.volume['id'])['volume']
zhangyanzi6b632432013-10-24 19:08:50 +0800126 self.assertIn('attaching', body['status'])
127 # Unmark volume as reserved.
jeremy.zhange280f662017-06-30 17:38:58 +0800128 self.volumes_client.unreserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800129 # To get the volume info
lkuchlan76d80b52017-04-03 12:29:57 +0300130 body = self.volumes_client.show_volume(self.volume['id'])['volume']
zhangyanzi6b632432013-10-24 19:08:50 +0800131 self.assertIn('available', body['status'])
132
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800133 @decorators.idempotent_id('fff74e1e-5bd3-4b33-9ea9-24c103bc3f59')
zhangyanziaa180072013-11-21 12:31:26 +0800134 def test_volume_readonly_update(self):
zhuflf9b46942016-10-09 11:23:46 +0800135 for readonly in [True, False]:
136 # Update volume readonly
lkuchlan76d80b52017-04-03 12:29:57 +0300137 self.volumes_client.update_volume_readonly(self.volume['id'],
138 readonly=readonly)
zhuflf9b46942016-10-09 11:23:46 +0800139 # Get Volume information
lkuchlan76d80b52017-04-03 12:29:57 +0300140 fetched_volume = self.volumes_client.show_volume(
zhuflf9b46942016-10-09 11:23:46 +0800141 self.volume['id'])['volume']
Masayuki Igawa50627462016-11-29 15:53:14 +0900142 # NOTE(masayukig): 'readonly' is "True" or "False" in the current
143 # cinder implementation. So we need to cast boolean values to str
144 # to compare here.
145 self.assertEqual(str(readonly),
146 fetched_volume['metadata']['readonly'])