blob: 9fca8072ddf05b61b2da9c8049376605c8e6af7d [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
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090019from tempest import test
Rohit Karajgia42fe442012-09-21 03:08:33 -070020
Matthew Treinish4d352bc2014-01-29 18:29:18 +000021CONF = config.CONF
22
Rohit Karajgia42fe442012-09-21 03:08:33 -070023
Zhi Kun Liubb363a22013-11-28 18:47:39 +080024class VolumesActionsTest(base.BaseVolumeV1Test):
Attila Fazekas786236c2013-01-31 16:06:51 +010025 _interface = "json"
Rohit Karajgia42fe442012-09-21 03:08:33 -070026
27 @classmethod
Masayuki Igawaa279a682014-03-14 13:29:42 +090028 @test.safe_setup
Rohit Karajgia42fe442012-09-21 03:08:33 -070029 def setUpClass(cls):
30 super(VolumesActionsTest, cls).setUpClass()
31 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
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090034 # Create a test shared instance
wanghao5b981752013-10-22 11:41:41 +080035 srv_name = data_utils.rand_name(cls.__name__ + '-Instance-')
Rohit Karajgia42fe442012-09-21 03:08:33 -070036 resp, cls.server = cls.servers_client.create_server(srv_name,
37 cls.image_ref,
38 cls.flavor_ref)
39 cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE')
40
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090041 # Create a test shared volume for attach/detach tests
42 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070043
44 @classmethod
45 def tearDownClass(cls):
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090046 # Delete the test instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070047 cls.servers_client.delete_server(cls.server['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070048 cls.client.wait_for_resource_deletion(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070049
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050050 super(VolumesActionsTest, cls).tearDownClass()
51
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090052 @test.stresstest(class_setup_per='process')
53 @test.attr(type='smoke')
54 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070055 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050056 # Volume is attached and detached successfully from an instance
Giulio Fidente92f77192013-08-26 17:13:28 +020057 mountpoint = '/dev/vdc'
58 resp, body = self.client.attach_volume(self.volume['id'],
59 self.server['id'],
60 mountpoint)
61 self.assertEqual(202, resp.status)
62 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
63 resp, body = self.client.detach_volume(self.volume['id'])
64 self.assertEqual(202, resp.status)
65 self.client.wait_for_volume_status(self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070066
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090067 @test.stresstest(class_setup_per='process')
68 @test.attr(type='gate')
69 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070070 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050071 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070072 mountpoint = '/dev/vdc'
73 resp, body = self.client.attach_volume(self.volume['id'],
Zhongyue Luoe0884a32012-09-25 17:24:17 +080074 self.server['id'],
75 mountpoint)
Rohit Karajgia42fe442012-09-21 03:08:33 -070076 self.assertEqual(202, resp.status)
Giulio Fidente92f77192013-08-26 17:13:28 +020077 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
78 # NOTE(gfidente): added in reverse order because functions will be
79 # called in reverse order to the order they are added (LIFO)
80 self.addCleanup(self.client.wait_for_volume_status,
81 self.volume['id'],
82 'available')
83 self.addCleanup(self.client.detach_volume, self.volume['id'])
84 resp, volume = self.client.get_volume(self.volume['id'])
85 self.assertEqual(200, resp.status)
86 self.assertIn('attachments', volume)
anju tiwari789449a2013-08-29 16:56:17 +053087 attachment = self.client.get_attachment_from_volume(volume)
Giulio Fidente92f77192013-08-26 17:13:28 +020088 self.assertEqual(mountpoint, attachment['device'])
89 self.assertEqual(self.server['id'], attachment['server_id'])
90 self.assertEqual(self.volume['id'], attachment['id'])
91 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020092
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090093 @test.attr(type='gate')
94 @test.services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +020095 def test_volume_upload(self):
96 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
97 # it is shared with the other tests. After it is uploaded in Glance,
98 # there is no way to delete it from Cinder, so we delete it from Glance
99 # using the Glance image_client and from Cinder via tearDownClass.
wanghao5b981752013-10-22 11:41:41 +0800100 image_name = data_utils.rand_name('Image-')
Ryan Hsua67f4632013-08-29 16:03:06 -0700101 resp, body = self.client.upload_volume(self.volume['id'],
102 image_name,
Matthew Treinish4d352bc2014-01-29 18:29:18 +0000103 CONF.volume.disk_format)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200104 image_id = body["image_id"]
105 self.addCleanup(self.image_client.delete_image, image_id)
106 self.assertEqual(202, resp.status)
107 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600108 self.client.wait_for_volume_status(self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530109
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900110 @test.attr(type='gate')
wanghao5b981752013-10-22 11:41:41 +0800111 def test_volume_extend(self):
112 # Extend Volume Test.
113 extend_size = int(self.volume['size']) + 1
114 resp, body = self.client.extend_volume(self.volume['id'], extend_size)
115 self.assertEqual(202, resp.status)
116 self.client.wait_for_volume_status(self.volume['id'], 'available')
117 resp, volume = self.client.get_volume(self.volume['id'])
118 self.assertEqual(200, resp.status)
119 self.assertEqual(int(volume['size']), extend_size)
120
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900121 @test.attr(type='gate')
zhangyanzi6b632432013-10-24 19:08:50 +0800122 def test_reserve_unreserve_volume(self):
123 # Mark volume as reserved.
124 resp, body = self.client.reserve_volume(self.volume['id'])
125 self.assertEqual(202, resp.status)
126 # To get the volume info
127 resp, body = self.client.get_volume(self.volume['id'])
128 self.assertEqual(200, resp.status)
129 self.assertIn('attaching', body['status'])
130 # Unmark volume as reserved.
131 resp, body = self.client.unreserve_volume(self.volume['id'])
132 self.assertEqual(202, resp.status)
133 # To get the volume info
134 resp, body = self.client.get_volume(self.volume['id'])
135 self.assertEqual(200, resp.status)
136 self.assertIn('available', body['status'])
137
zhangyanziaa180072013-11-21 12:31:26 +0800138 def _is_true(self, val):
139 return val in ['true', 'True', True]
140
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900141 @test.attr(type='gate')
zhangyanziaa180072013-11-21 12:31:26 +0800142 def test_volume_readonly_update(self):
143 # Update volume readonly true
144 readonly = True
145 resp, body = self.client.update_volume_readonly(self.volume['id'],
146 readonly)
147 self.assertEqual(202, resp.status)
148
149 # Get Volume information
150 resp, fetched_volume = self.client.get_volume(self.volume['id'])
151 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
152 self.assertEqual(200, resp.status)
153 self.assertEqual(True, bool_flag)
154
155 # Update volume readonly false
156 readonly = False
157 resp, body = self.client.update_volume_readonly(self.volume['id'],
158 readonly)
159 self.assertEqual(202, resp.status)
160
161 # Get Volume information
162 resp, fetched_volume = self.client.get_volume(self.volume['id'])
163 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
164 self.assertEqual(200, resp.status)
165 self.assertEqual(False, bool_flag)
166
anju tiwari789449a2013-08-29 16:56:17 +0530167
168class VolumesActionsTestXML(VolumesActionsTest):
169 _interface = "xml"