blob: 5924c7ea99095b87dd9b366430ef65834bc5a953 [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
wanghao5b981752013-10-22 11:41:41 +080017from tempest.common.utils import data_utils
Matthew Treinish4d352bc2014-01-29 18:29:18 +000018from tempest import config
Chris Yeoh01cb2792013-02-09 22:25:37 +103019from tempest.test import attr
Matthew Treinish660a4c12013-09-09 20:06:12 +000020from tempest.test import services
Marc Koderer32221b8e2013-08-23 13:57:50 +020021from tempest.test import stresstest
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 Liubb363a22013-11-28 18:47:39 +080026class VolumesActionsTest(base.BaseVolumeV1Test):
Attila Fazekas786236c2013-01-31 16:06:51 +010027 _interface = "json"
Rohit Karajgia42fe442012-09-21 03:08:33 -070028
29 @classmethod
30 def setUpClass(cls):
31 super(VolumesActionsTest, cls).setUpClass()
32 cls.client = cls.volumes_client
Giulio Fidente884e9da2013-06-21 17:25:42 +020033 cls.image_client = cls.os.image_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070034
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090035 # Create a test shared instance
wanghao5b981752013-10-22 11:41:41 +080036 srv_name = data_utils.rand_name(cls.__name__ + '-Instance-')
Rohit Karajgia42fe442012-09-21 03:08:33 -070037 resp, cls.server = cls.servers_client.create_server(srv_name,
38 cls.image_ref,
39 cls.flavor_ref)
40 cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE')
41
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090042 # Create a test shared volume for attach/detach tests
43 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070044
45 @classmethod
46 def tearDownClass(cls):
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090047 # Delete the test instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070048 cls.servers_client.delete_server(cls.server['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070049 cls.client.wait_for_resource_deletion(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070050
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050051 super(VolumesActionsTest, cls).tearDownClass()
52
Marc Koderer32221b8e2013-08-23 13:57:50 +020053 @stresstest(class_setup_per='process')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020054 @attr(type='smoke')
Matthew Treinish660a4c12013-09-09 20:06:12 +000055 @services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070056 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050057 # Volume is attached and detached successfully from an instance
Giulio Fidente92f77192013-08-26 17:13:28 +020058 mountpoint = '/dev/vdc'
59 resp, body = self.client.attach_volume(self.volume['id'],
60 self.server['id'],
61 mountpoint)
62 self.assertEqual(202, resp.status)
63 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
64 resp, body = self.client.detach_volume(self.volume['id'])
65 self.assertEqual(202, resp.status)
66 self.client.wait_for_volume_status(self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070067
Marc Koderer32221b8e2013-08-23 13:57:50 +020068 @stresstest(class_setup_per='process')
Giulio Fidente8b311902013-05-12 15:40:31 +020069 @attr(type='gate')
Matthew Treinish660a4c12013-09-09 20:06:12 +000070 @services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070071 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050072 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070073 mountpoint = '/dev/vdc'
74 resp, body = self.client.attach_volume(self.volume['id'],
Zhongyue Luoe0884a32012-09-25 17:24:17 +080075 self.server['id'],
76 mountpoint)
Rohit Karajgia42fe442012-09-21 03:08:33 -070077 self.assertEqual(202, resp.status)
Giulio Fidente92f77192013-08-26 17:13:28 +020078 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
79 # NOTE(gfidente): added in reverse order because functions will be
80 # called in reverse order to the order they are added (LIFO)
81 self.addCleanup(self.client.wait_for_volume_status,
82 self.volume['id'],
83 'available')
84 self.addCleanup(self.client.detach_volume, self.volume['id'])
85 resp, volume = self.client.get_volume(self.volume['id'])
86 self.assertEqual(200, resp.status)
87 self.assertIn('attachments', volume)
anju tiwari789449a2013-08-29 16:56:17 +053088 attachment = self.client.get_attachment_from_volume(volume)
Giulio Fidente92f77192013-08-26 17:13:28 +020089 self.assertEqual(mountpoint, attachment['device'])
90 self.assertEqual(self.server['id'], attachment['server_id'])
91 self.assertEqual(self.volume['id'], attachment['id'])
92 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020093
94 @attr(type='gate')
Matthew Treinish660a4c12013-09-09 20:06:12 +000095 @services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +020096 def test_volume_upload(self):
97 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
98 # it is shared with the other tests. After it is uploaded in Glance,
99 # there is no way to delete it from Cinder, so we delete it from Glance
100 # using the Glance image_client and from Cinder via tearDownClass.
wanghao5b981752013-10-22 11:41:41 +0800101 image_name = data_utils.rand_name('Image-')
Ryan Hsua67f4632013-08-29 16:03:06 -0700102 resp, body = self.client.upload_volume(self.volume['id'],
103 image_name,
Matthew Treinish4d352bc2014-01-29 18:29:18 +0000104 CONF.volume.disk_format)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200105 image_id = body["image_id"]
106 self.addCleanup(self.image_client.delete_image, image_id)
107 self.assertEqual(202, resp.status)
108 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600109 self.client.wait_for_volume_status(self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530110
wanghao5b981752013-10-22 11:41:41 +0800111 @attr(type='gate')
112 def test_volume_extend(self):
113 # Extend Volume Test.
114 extend_size = int(self.volume['size']) + 1
115 resp, body = self.client.extend_volume(self.volume['id'], extend_size)
116 self.assertEqual(202, resp.status)
117 self.client.wait_for_volume_status(self.volume['id'], 'available')
118 resp, volume = self.client.get_volume(self.volume['id'])
119 self.assertEqual(200, resp.status)
120 self.assertEqual(int(volume['size']), extend_size)
121
zhangyanzi6b632432013-10-24 19:08:50 +0800122 @attr(type='gate')
123 def test_reserve_unreserve_volume(self):
124 # Mark volume as reserved.
125 resp, body = self.client.reserve_volume(self.volume['id'])
126 self.assertEqual(202, resp.status)
127 # To get the volume info
128 resp, body = self.client.get_volume(self.volume['id'])
129 self.assertEqual(200, resp.status)
130 self.assertIn('attaching', body['status'])
131 # Unmark volume as reserved.
132 resp, body = self.client.unreserve_volume(self.volume['id'])
133 self.assertEqual(202, resp.status)
134 # To get the volume info
135 resp, body = self.client.get_volume(self.volume['id'])
136 self.assertEqual(200, resp.status)
137 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
142 @attr(type='gate')
143 def test_volume_readonly_update(self):
144 # Update volume readonly true
145 readonly = True
146 resp, body = self.client.update_volume_readonly(self.volume['id'],
147 readonly)
148 self.assertEqual(202, resp.status)
149
150 # Get Volume information
151 resp, fetched_volume = self.client.get_volume(self.volume['id'])
152 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
153 self.assertEqual(200, resp.status)
154 self.assertEqual(True, bool_flag)
155
156 # Update volume readonly false
157 readonly = False
158 resp, body = self.client.update_volume_readonly(self.volume['id'],
159 readonly)
160 self.assertEqual(202, resp.status)
161
162 # Get Volume information
163 resp, fetched_volume = self.client.get_volume(self.volume['id'])
164 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
165 self.assertEqual(200, resp.status)
166 self.assertEqual(False, bool_flag)
167
anju tiwari789449a2013-08-29 16:56:17 +0530168
169class VolumesActionsTestXML(VolumesActionsTest):
170 _interface = "xml"