blob: 315472e9425c1ebf5f167fe0602df7efc6abe1a5 [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
Matthew Treinish4217a702016-10-07 17:27:11 -040022from tempest.lib import exceptions
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090023from tempest import test
Rohit Karajgia42fe442012-09-21 03:08:33 -070024
Matthew Treinish4d352bc2014-01-29 18:29:18 +000025CONF = config.CONF
26
Rohit Karajgia42fe442012-09-21 03:08:33 -070027
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070028class VolumesActionsTest(base.BaseVolumeTest):
Rohit Karajgia42fe442012-09-21 03:08:33 -070029
30 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053031 def setup_clients(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070032 super(VolumesActionsTest, cls).setup_clients()
Rohit Karajgia42fe442012-09-21 03:08:33 -070033 cls.client = cls.volumes_client
Matt Riedemann2aa19d42016-06-06 17:45:41 -040034 if CONF.service_available.glance:
35 # Check if glance v1 is available to determine which client to use.
36 if CONF.image_feature_enabled.api_v1:
37 cls.image_client = cls.os.image_client
38 elif CONF.image_feature_enabled.api_v2:
39 cls.image_client = cls.os.image_client_v2
40 else:
41 raise exceptions.InvalidConfiguration(
42 'Either api_v1 or api_v2 must be True in '
43 '[image-feature-enabled].')
Rohit Karajgia42fe442012-09-21 03:08:33 -070044
Rohan Kanade05749152015-01-30 17:15:18 +053045 @classmethod
46 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070047 super(VolumesActionsTest, cls).resource_setup()
Rohit Karajgia42fe442012-09-21 03:08:33 -070048
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090049 # Create a test shared volume for attach/detach tests
50 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070051
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080052 @decorators.idempotent_id('fff42874-7db5-4487-a8e1-ddda5fb5288d')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090053 @test.attr(type='smoke')
54 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070055 def test_attach_detach_volume_to_instance(self):
lkuchlan5fc69362016-09-05 08:42:34 +030056 # Create a server
zhufl7867a6e2016-10-18 15:37:12 +080057 server = self.create_server(wait_until='ACTIVE')
Sean Dague72a00382013-01-03 17:53:38 -050058 # Volume is attached and detached successfully from an instance
Joseph Lanoux6809bab2014-12-18 14:57:18 +000059 self.client.attach_volume(self.volume['id'],
lkuchlan5fc69362016-09-05 08:42:34 +030060 instance_uuid=server['id'],
bkopilovbc830d02016-03-27 14:09:47 +030061 mountpoint='/dev/%s' %
62 CONF.compute.volume_device_name)
lkuchlan52d7b0d2016-11-07 20:53:19 +020063 waiters.wait_for_volume_resource_status(self.client,
64 self.volume['id'], 'in-use')
Joseph Lanoux6809bab2014-12-18 14:57:18 +000065 self.client.detach_volume(self.volume['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020066 waiters.wait_for_volume_resource_status(self.client,
67 self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070068
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080069 @decorators.idempotent_id('63e21b4c-0a0c-41f6-bfc3-7c2816815599')
bkopilov8a657ae2015-05-11 11:45:23 +030070 def test_volume_bootable(self):
71 # Verify that a volume bootable flag is retrieved
72 for bool_bootable in [True, False]:
Ghanshyam58a9e872015-12-18 10:46:07 +090073 self.client.set_bootable_volume(self.volume['id'],
74 bootable=bool_bootable)
John Warren6177c9e2015-08-19 20:00:17 +000075 fetched_volume = self.client.show_volume(
76 self.volume['id'])['volume']
bkopilov8a657ae2015-05-11 11:45:23 +030077 # Get Volume information
Masayuki Igawa50627462016-11-29 15:53:14 +090078 # NOTE(masayukig): 'bootable' is "true" or "false" in the current
79 # cinder implementation. So we need to cast boolean values to str
80 # and make it lower to compare here.
81 self.assertEqual(str(bool_bootable).lower(),
82 fetched_volume['bootable'])
bkopilov8a657ae2015-05-11 11:45:23 +030083
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080084 @decorators.idempotent_id('9516a2c8-9135-488c-8dd6-5677a7e5f371')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090085 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070086 def test_get_volume_attachment(self):
lkuchlan5fc69362016-09-05 08:42:34 +030087 # Create a server
zhufl7867a6e2016-10-18 15:37:12 +080088 server = self.create_server(wait_until='ACTIVE')
Sean Dague72a00382013-01-03 17:53:38 -050089 # Verify that a volume's attachment information is retrieved
Joseph Lanoux6809bab2014-12-18 14:57:18 +000090 self.client.attach_volume(self.volume['id'],
lkuchlan5fc69362016-09-05 08:42:34 +030091 instance_uuid=server['id'],
bkopilovbc830d02016-03-27 14:09:47 +030092 mountpoint='/dev/%s' %
93 CONF.compute.volume_device_name)
lkuchlan52d7b0d2016-11-07 20:53:19 +020094 waiters.wait_for_volume_resource_status(self.client, self.volume['id'],
95 'in-use')
96 self.addCleanup(waiters.wait_for_volume_resource_status, self.client,
97 self.volume['id'], 'available')
Giulio Fidente92f77192013-08-26 17:13:28 +020098 self.addCleanup(self.client.detach_volume, self.volume['id'])
John Warren6177c9e2015-08-19 20:00:17 +000099 volume = self.client.show_volume(self.volume['id'])['volume']
Giulio Fidente92f77192013-08-26 17:13:28 +0200100 self.assertIn('attachments', volume)
Ken'ichi Ohmichi84a5f962016-08-26 15:34:26 -0700101 attachment = volume['attachments'][0]
102
bkopilovbc830d02016-03-27 14:09:47 +0300103 self.assertEqual('/dev/%s' %
104 CONF.compute.volume_device_name,
105 attachment['device'])
lkuchlan5fc69362016-09-05 08:42:34 +0300106 self.assertEqual(server['id'], attachment['server_id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200107 self.assertEqual(self.volume['id'], attachment['id'])
108 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800110 @decorators.idempotent_id('d8f1ca95-3d5b-44a3-b8ca-909691c9532d')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900111 @test.services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +0200112 def test_volume_upload(self):
113 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
114 # it is shared with the other tests. After it is uploaded in Glance,
115 # there is no way to delete it from Cinder, so we delete it from Glance
116 # using the Glance image_client and from Cinder via tearDownClass.
zhuflc6ce5392016-08-17 14:34:37 +0800117 image_name = data_utils.rand_name(self.__class__.__name__ + '-Image')
John Warren6177c9e2015-08-19 20:00:17 +0000118 body = self.client.upload_volume(
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900119 self.volume['id'], image_name=image_name,
120 disk_format=CONF.volume.disk_format)['os-volume_upload_image']
Giulio Fidente884e9da2013-06-21 17:25:42 +0200121 image_id = body["image_id"]
Jordan Pittier9e227c52016-02-09 14:35:18 +0100122 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
123 self.image_client.delete_image,
124 image_id)
Yaroslav Lobankov2fea4052016-04-19 15:05:57 +0300125 waiters.wait_for_image_status(self.image_client, image_id, 'active')
lkuchlan52d7b0d2016-11-07 20:53:19 +0200126 waiters.wait_for_volume_resource_status(self.client,
127 self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530128
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800129 @decorators.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33')
zhangyanzi6b632432013-10-24 19:08:50 +0800130 def test_reserve_unreserve_volume(self):
131 # Mark volume as reserved.
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000132 body = self.client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800133 # To get the volume info
John Warren6177c9e2015-08-19 20:00:17 +0000134 body = self.client.show_volume(self.volume['id'])['volume']
zhangyanzi6b632432013-10-24 19:08:50 +0800135 self.assertIn('attaching', body['status'])
136 # Unmark volume as reserved.
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000137 body = self.client.unreserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800138 # To get the volume info
John Warren6177c9e2015-08-19 20:00:17 +0000139 body = self.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):
zhuflf9b46942016-10-09 11:23:46 +0800144 for readonly in [True, False]:
145 # Update volume readonly
146 self.client.update_volume_readonly(self.volume['id'],
147 readonly=readonly)
148 # Get Volume information
149 fetched_volume = self.client.show_volume(
150 self.volume['id'])['volume']
Masayuki Igawa50627462016-11-29 15:53:14 +0900151 # NOTE(masayukig): 'readonly' is "True" or "False" in the current
152 # cinder implementation. So we need to cast boolean values to str
153 # to compare here.
154 self.assertEqual(str(readonly),
155 fetched_volume['metadata']['readonly'])