blob: 067c0c13e26f00e94564ff9567b613dd7ecfab6d [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_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
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090020from tempest import test
bkopilov8a657ae2015-05-11 11:45:23 +030021import testtools
Rohit Karajgia42fe442012-09-21 03:08:33 -070022
Matthew Treinish4d352bc2014-01-29 18:29:18 +000023CONF = config.CONF
24
Rohit Karajgia42fe442012-09-21 03:08:33 -070025
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080026class VolumesV2ActionsTest(base.BaseVolumeTest):
Rohit Karajgia42fe442012-09-21 03:08:33 -070027
28 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053029 def setup_clients(cls):
30 super(VolumesV2ActionsTest, cls).setup_clients()
Rohit Karajgia42fe442012-09-21 03:08:33 -070031 cls.client = cls.volumes_client
Giulio Fidente884e9da2013-06-21 17:25:42 +020032 cls.image_client = cls.os.image_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070033
Rohan Kanade05749152015-01-30 17:15:18 +053034 @classmethod
35 def resource_setup(cls):
36 super(VolumesV2ActionsTest, cls).resource_setup()
37
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090038 # Create a test shared instance
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000039 srv_name = data_utils.rand_name(cls.__name__ + '-Instance')
Rohan Kanade9ce97df2013-12-10 18:59:35 +053040 cls.server = cls.create_server(srv_name)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000041 waiters.wait_for_server_status(cls.servers_client, cls.server['id'],
42 'ACTIVE')
Rohit Karajgia42fe442012-09-21 03:08:33 -070043
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090044 # Create a test shared volume for attach/detach tests
45 cls.volume = cls.create_volume()
JordanP0a27a352015-02-16 11:16:51 +010046 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070047
Attila Fazekas9fa29472014-08-18 09:48:00 +020048 def _delete_image_with_wait(self, image_id):
49 self.image_client.delete_image(image_id)
50 self.image_client.wait_for_resource_deletion(image_id)
51
Rohit Karajgia42fe442012-09-21 03:08:33 -070052 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010053 def resource_cleanup(cls):
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090054 # Delete the test instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070055 cls.servers_client.delete_server(cls.server['id'])
Attila Fazekas4435bd82014-03-13 14:35:10 +010056 cls.servers_client.wait_for_server_termination(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070057
Andrea Frittoli61a12e22014-09-15 13:14:54 +010058 super(VolumesV2ActionsTest, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050059
Chris Hoge7579c1a2015-02-26 14:12:15 -080060 @test.idempotent_id('fff42874-7db5-4487-a8e1-ddda5fb5288d')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090061 @test.stresstest(class_setup_per='process')
62 @test.attr(type='smoke')
63 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070064 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050065 # Volume is attached and detached successfully from an instance
Giulio Fidente92f77192013-08-26 17:13:28 +020066 mountpoint = '/dev/vdc'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000067 self.client.attach_volume(self.volume['id'],
68 self.server['id'],
69 mountpoint)
Giulio Fidente92f77192013-08-26 17:13:28 +020070 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
Joseph Lanoux6809bab2014-12-18 14:57:18 +000071 self.client.detach_volume(self.volume['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020072 self.client.wait_for_volume_status(self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070073
bkopilov8a657ae2015-05-11 11:45:23 +030074 @test.idempotent_id('63e21b4c-0a0c-41f6-bfc3-7c2816815599')
75 @testtools.skipUnless(CONF.volume_feature_enabled.bootable,
76 'Update bootable status of a volume is not enabled.')
77 def test_volume_bootable(self):
78 # Verify that a volume bootable flag is retrieved
79 for bool_bootable in [True, False]:
80 self.client.set_bootable_volume(self.volume['id'], bool_bootable)
81 fetched_volume = self.client.show_volume(self.volume['id'])
82 # Get Volume information
83 bool_flag = self._is_true(fetched_volume['bootable'])
84 self.assertEqual(bool_bootable, bool_flag)
85
Chris Hoge7579c1a2015-02-26 14:12:15 -080086 @test.idempotent_id('9516a2c8-9135-488c-8dd6-5677a7e5f371')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090087 @test.stresstest(class_setup_per='process')
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090088 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070089 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050090 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070091 mountpoint = '/dev/vdc'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000092 self.client.attach_volume(self.volume['id'],
93 self.server['id'],
94 mountpoint)
Giulio Fidente92f77192013-08-26 17:13:28 +020095 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
96 # NOTE(gfidente): added in reverse order because functions will be
97 # called in reverse order to the order they are added (LIFO)
98 self.addCleanup(self.client.wait_for_volume_status,
99 self.volume['id'],
100 'available')
101 self.addCleanup(self.client.detach_volume, self.volume['id'])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000102 volume = self.client.show_volume(self.volume['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200103 self.assertIn('attachments', volume)
anju tiwari789449a2013-08-29 16:56:17 +0530104 attachment = self.client.get_attachment_from_volume(volume)
Giulio Fidente92f77192013-08-26 17:13:28 +0200105 self.assertEqual(mountpoint, attachment['device'])
106 self.assertEqual(self.server['id'], attachment['server_id'])
107 self.assertEqual(self.volume['id'], attachment['id'])
108 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109
Chris Hoge7579c1a2015-02-26 14:12:15 -0800110 @test.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.
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +0000117 image_name = data_utils.rand_name('Image')
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000118 body = self.client.upload_volume(self.volume['id'],
119 image_name,
120 CONF.volume.disk_format)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200121 image_id = body["image_id"]
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000122 self.addCleanup(self.image_client.delete_image, image_id)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200123 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600124 self.client.wait_for_volume_status(self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530125
Chris Hoge7579c1a2015-02-26 14:12:15 -0800126 @test.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33')
zhangyanzi6b632432013-10-24 19:08:50 +0800127 def test_reserve_unreserve_volume(self):
128 # Mark volume as reserved.
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000129 body = self.client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800130 # To get the volume info
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000131 body = self.client.show_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800132 self.assertIn('attaching', body['status'])
133 # Unmark volume as reserved.
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000134 body = self.client.unreserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800135 # To get the volume info
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000136 body = self.client.show_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800137 self.assertIn('available', body['status'])
138
zhangyanziaa180072013-11-21 12:31:26 +0800139 def _is_true(self, val):
140 return val in ['true', 'True', True]
141
Chris Hoge7579c1a2015-02-26 14:12:15 -0800142 @test.idempotent_id('fff74e1e-5bd3-4b33-9ea9-24c103bc3f59')
zhangyanziaa180072013-11-21 12:31:26 +0800143 def test_volume_readonly_update(self):
144 # Update volume readonly true
145 readonly = True
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000146 self.client.update_volume_readonly(self.volume['id'],
147 readonly)
zhangyanziaa180072013-11-21 12:31:26 +0800148 # Get Volume information
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000149 fetched_volume = self.client.show_volume(self.volume['id'])
zhangyanziaa180072013-11-21 12:31:26 +0800150 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
zhangyanziaa180072013-11-21 12:31:26 +0800151 self.assertEqual(True, bool_flag)
152
153 # Update volume readonly false
154 readonly = False
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000155 self.client.update_volume_readonly(self.volume['id'], readonly)
zhangyanziaa180072013-11-21 12:31:26 +0800156
157 # Get Volume information
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000158 fetched_volume = self.client.show_volume(self.volume['id'])
zhangyanziaa180072013-11-21 12:31:26 +0800159 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
zhangyanziaa180072013-11-21 12:31:26 +0800160 self.assertEqual(False, bool_flag)
161
anju tiwari789449a2013-08-29 16:56:17 +0530162
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800163class VolumesV1ActionsTest(VolumesV2ActionsTest):
164 _api_version = 1