blob: 0e7f1e9cd6d8eeb1986c388c684970c0f1ece567 [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
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000017from tempest.common import waiters
Matthew Treinish4d352bc2014-01-29 18:29:18 +000018from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080019from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010020from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080021from tempest.lib import decorators
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090022from tempest import test
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):
Rohit Karajgia42fe442012-09-21 03:08:33 -070028
29 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053030 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070031 super(VolumesActionsTest, cls).resource_setup()
Rohit Karajgia42fe442012-09-21 03:08:33 -070032
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090033 # Create a test shared volume for attach/detach tests
34 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070035
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080036 @decorators.idempotent_id('fff42874-7db5-4487-a8e1-ddda5fb5288d')
Jordan Pittier3b46d272017-04-12 16:17:28 +020037 @decorators.attr(type='smoke')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090038 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070039 def test_attach_detach_volume_to_instance(self):
lkuchlan5fc69362016-09-05 08:42:34 +030040 # Create a server
zhufl7867a6e2016-10-18 15:37:12 +080041 server = self.create_server(wait_until='ACTIVE')
Sean Dague72a00382013-01-03 17:53:38 -050042 # Volume is attached and detached successfully from an instance
lkuchlan76d80b52017-04-03 12:29:57 +030043 self.volumes_client.attach_volume(self.volume['id'],
44 instance_uuid=server['id'],
45 mountpoint='/dev/%s' %
46 CONF.compute.volume_device_name)
47 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020048 self.volume['id'], 'in-use')
lkuchlan76d80b52017-04-03 12:29:57 +030049 self.volumes_client.detach_volume(self.volume['id'])
50 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020051 self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070052
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080053 @decorators.idempotent_id('63e21b4c-0a0c-41f6-bfc3-7c2816815599')
bkopilov8a657ae2015-05-11 11:45:23 +030054 def test_volume_bootable(self):
55 # Verify that a volume bootable flag is retrieved
56 for bool_bootable in [True, False]:
lkuchlan76d80b52017-04-03 12:29:57 +030057 self.volumes_client.set_bootable_volume(self.volume['id'],
58 bootable=bool_bootable)
59 fetched_volume = self.volumes_client.show_volume(
John Warren6177c9e2015-08-19 20:00:17 +000060 self.volume['id'])['volume']
bkopilov8a657ae2015-05-11 11:45:23 +030061 # Get Volume information
Masayuki Igawa50627462016-11-29 15:53:14 +090062 # NOTE(masayukig): 'bootable' is "true" or "false" in the current
63 # cinder implementation. So we need to cast boolean values to str
64 # and make it lower to compare here.
65 self.assertEqual(str(bool_bootable).lower(),
66 fetched_volume['bootable'])
bkopilov8a657ae2015-05-11 11:45:23 +030067
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080068 @decorators.idempotent_id('9516a2c8-9135-488c-8dd6-5677a7e5f371')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090069 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070070 def test_get_volume_attachment(self):
lkuchlan5fc69362016-09-05 08:42:34 +030071 # Create a server
zhufl7867a6e2016-10-18 15:37:12 +080072 server = self.create_server(wait_until='ACTIVE')
Sean Dague72a00382013-01-03 17:53:38 -050073 # Verify that a volume's attachment information is retrieved
lkuchlan76d80b52017-04-03 12:29:57 +030074 self.volumes_client.attach_volume(self.volume['id'],
75 instance_uuid=server['id'],
76 mountpoint='/dev/%s' %
77 CONF.compute.volume_device_name)
78 waiters.wait_for_volume_resource_status(self.volumes_client,
79 self.volume['id'],
lkuchlan52d7b0d2016-11-07 20:53:19 +020080 'in-use')
lkuchlan76d80b52017-04-03 12:29:57 +030081 self.addCleanup(waiters.wait_for_volume_resource_status,
82 self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +020083 self.volume['id'], 'available')
lkuchlan76d80b52017-04-03 12:29:57 +030084 self.addCleanup(self.volumes_client.detach_volume, self.volume['id'])
85 volume = self.volumes_client.show_volume(self.volume['id'])['volume']
Giulio Fidente92f77192013-08-26 17:13:28 +020086 self.assertIn('attachments', volume)
Ken'ichi Ohmichi84a5f962016-08-26 15:34:26 -070087 attachment = volume['attachments'][0]
88
bkopilovbc830d02016-03-27 14:09:47 +030089 self.assertEqual('/dev/%s' %
90 CONF.compute.volume_device_name,
91 attachment['device'])
lkuchlan5fc69362016-09-05 08:42:34 +030092 self.assertEqual(server['id'], attachment['server_id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020093 self.assertEqual(self.volume['id'], attachment['id'])
94 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020095
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080096 @decorators.idempotent_id('d8f1ca95-3d5b-44a3-b8ca-909691c9532d')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090097 @test.services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +020098 def test_volume_upload(self):
99 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
100 # it is shared with the other tests. After it is uploaded in Glance,
101 # there is no way to delete it from Cinder, so we delete it from Glance
lkuchlan153df152017-04-25 16:43:47 +0300102 # using the Glance images_client and from Cinder via tearDownClass.
zhuflc6ce5392016-08-17 14:34:37 +0800103 image_name = data_utils.rand_name(self.__class__.__name__ + '-Image')
lkuchlan76d80b52017-04-03 12:29:57 +0300104 body = self.volumes_client.upload_volume(
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900105 self.volume['id'], image_name=image_name,
106 disk_format=CONF.volume.disk_format)['os-volume_upload_image']
Giulio Fidente884e9da2013-06-21 17:25:42 +0200107 image_id = body["image_id"]
Jordan Pittier9e227c52016-02-09 14:35:18 +0100108 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800109 self.images_client.delete_image,
Jordan Pittier9e227c52016-02-09 14:35:18 +0100110 image_id)
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800111 waiters.wait_for_image_status(self.images_client, image_id, 'active')
lkuchlan76d80b52017-04-03 12:29:57 +0300112 waiters.wait_for_volume_resource_status(self.volumes_client,
lkuchlan52d7b0d2016-11-07 20:53:19 +0200113 self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530114
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800115 @decorators.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33')
zhangyanzi6b632432013-10-24 19:08:50 +0800116 def test_reserve_unreserve_volume(self):
117 # Mark volume as reserved.
lkuchlan76d80b52017-04-03 12:29:57 +0300118 body = self.volumes_client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800119 # To get the volume info
lkuchlan76d80b52017-04-03 12:29:57 +0300120 body = self.volumes_client.show_volume(self.volume['id'])['volume']
zhangyanzi6b632432013-10-24 19:08:50 +0800121 self.assertIn('attaching', body['status'])
122 # Unmark volume as reserved.
lkuchlan76d80b52017-04-03 12:29:57 +0300123 body = self.volumes_client.unreserve_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('available', body['status'])
127
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800128 @decorators.idempotent_id('fff74e1e-5bd3-4b33-9ea9-24c103bc3f59')
zhangyanziaa180072013-11-21 12:31:26 +0800129 def test_volume_readonly_update(self):
zhuflf9b46942016-10-09 11:23:46 +0800130 for readonly in [True, False]:
131 # Update volume readonly
lkuchlan76d80b52017-04-03 12:29:57 +0300132 self.volumes_client.update_volume_readonly(self.volume['id'],
133 readonly=readonly)
zhuflf9b46942016-10-09 11:23:46 +0800134 # Get Volume information
lkuchlan76d80b52017-04-03 12:29:57 +0300135 fetched_volume = self.volumes_client.show_volume(
zhuflf9b46942016-10-09 11:23:46 +0800136 self.volume['id'])['volume']
Masayuki Igawa50627462016-11-29 15:53:14 +0900137 # NOTE(masayukig): 'readonly' is "True" or "False" in the current
138 # cinder implementation. So we need to cast boolean values to str
139 # to compare here.
140 self.assertEqual(str(readonly),
141 fetched_volume['metadata']['readonly'])