blob: 0f92f011580466bc416eca5ee3331707a80636a6 [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 Liu3d6d9862014-06-16 16:43:59 +080024class VolumesV2ActionsTest(base.BaseVolumeTest):
Rohit Karajgia42fe442012-09-21 03:08:33 -070025
26 @classmethod
Masayuki Igawaa279a682014-03-14 13:29:42 +090027 @test.safe_setup
Rohit Karajgia42fe442012-09-21 03:08:33 -070028 def setUpClass(cls):
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080029 super(VolumesV2ActionsTest, cls).setUpClass()
Rohit Karajgia42fe442012-09-21 03:08:33 -070030 cls.client = cls.volumes_client
Giulio Fidente884e9da2013-06-21 17:25:42 +020031 cls.image_client = cls.os.image_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070032
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090033 # Create a test shared instance
wanghao5b981752013-10-22 11:41:41 +080034 srv_name = data_utils.rand_name(cls.__name__ + '-Instance-')
Rohit Karajgia42fe442012-09-21 03:08:33 -070035 resp, cls.server = cls.servers_client.create_server(srv_name,
36 cls.image_ref,
37 cls.flavor_ref)
38 cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE')
39
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090040 # Create a test shared volume for attach/detach tests
41 cls.volume = cls.create_volume()
Rohit Karajgia42fe442012-09-21 03:08:33 -070042
Attila Fazekas9fa29472014-08-18 09:48:00 +020043 def _delete_image_with_wait(self, image_id):
44 self.image_client.delete_image(image_id)
45 self.image_client.wait_for_resource_deletion(image_id)
46
Rohit Karajgia42fe442012-09-21 03:08:33 -070047 @classmethod
48 def tearDownClass(cls):
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090049 # Delete the test instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070050 cls.servers_client.delete_server(cls.server['id'])
Attila Fazekas4435bd82014-03-13 14:35:10 +010051 cls.servers_client.wait_for_server_termination(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070052
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080053 super(VolumesV2ActionsTest, cls).tearDownClass()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050054
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090055 @test.stresstest(class_setup_per='process')
56 @test.attr(type='smoke')
57 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070058 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050059 # Volume is attached and detached successfully from an instance
Giulio Fidente92f77192013-08-26 17:13:28 +020060 mountpoint = '/dev/vdc'
61 resp, body = self.client.attach_volume(self.volume['id'],
62 self.server['id'],
63 mountpoint)
64 self.assertEqual(202, resp.status)
65 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
66 resp, body = self.client.detach_volume(self.volume['id'])
67 self.assertEqual(202, resp.status)
68 self.client.wait_for_volume_status(self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070069
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090070 @test.stresstest(class_setup_per='process')
71 @test.attr(type='gate')
72 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070073 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050074 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070075 mountpoint = '/dev/vdc'
76 resp, body = self.client.attach_volume(self.volume['id'],
Zhongyue Luoe0884a32012-09-25 17:24:17 +080077 self.server['id'],
78 mountpoint)
Rohit Karajgia42fe442012-09-21 03:08:33 -070079 self.assertEqual(202, resp.status)
Giulio Fidente92f77192013-08-26 17:13:28 +020080 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
81 # NOTE(gfidente): added in reverse order because functions will be
82 # called in reverse order to the order they are added (LIFO)
83 self.addCleanup(self.client.wait_for_volume_status,
84 self.volume['id'],
85 'available')
86 self.addCleanup(self.client.detach_volume, self.volume['id'])
87 resp, volume = self.client.get_volume(self.volume['id'])
88 self.assertEqual(200, resp.status)
89 self.assertIn('attachments', volume)
anju tiwari789449a2013-08-29 16:56:17 +053090 attachment = self.client.get_attachment_from_volume(volume)
Giulio Fidente92f77192013-08-26 17:13:28 +020091 self.assertEqual(mountpoint, attachment['device'])
92 self.assertEqual(self.server['id'], attachment['server_id'])
93 self.assertEqual(self.volume['id'], attachment['id'])
94 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020095
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090096 @test.attr(type='gate')
97 @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
102 # using the Glance image_client and from Cinder via tearDownClass.
wanghao5b981752013-10-22 11:41:41 +0800103 image_name = data_utils.rand_name('Image-')
Ryan Hsua67f4632013-08-29 16:03:06 -0700104 resp, body = self.client.upload_volume(self.volume['id'],
105 image_name,
Matthew Treinish4d352bc2014-01-29 18:29:18 +0000106 CONF.volume.disk_format)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200107 image_id = body["image_id"]
Attila Fazekas9fa29472014-08-18 09:48:00 +0200108 self.addCleanup(self._delete_image_with_wait, image_id)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109 self.assertEqual(202, resp.status)
110 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600111 self.client.wait_for_volume_status(self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530112
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900113 @test.attr(type='gate')
zhangyanzi6b632432013-10-24 19:08:50 +0800114 def test_reserve_unreserve_volume(self):
115 # Mark volume as reserved.
116 resp, body = self.client.reserve_volume(self.volume['id'])
117 self.assertEqual(202, resp.status)
118 # To get the volume info
119 resp, body = self.client.get_volume(self.volume['id'])
120 self.assertEqual(200, resp.status)
121 self.assertIn('attaching', body['status'])
122 # Unmark volume as reserved.
123 resp, body = self.client.unreserve_volume(self.volume['id'])
124 self.assertEqual(202, resp.status)
125 # To get the volume info
126 resp, body = self.client.get_volume(self.volume['id'])
127 self.assertEqual(200, resp.status)
128 self.assertIn('available', body['status'])
129
zhangyanziaa180072013-11-21 12:31:26 +0800130 def _is_true(self, val):
131 return val in ['true', 'True', True]
132
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900133 @test.attr(type='gate')
zhangyanziaa180072013-11-21 12:31:26 +0800134 def test_volume_readonly_update(self):
135 # Update volume readonly true
136 readonly = True
137 resp, body = self.client.update_volume_readonly(self.volume['id'],
138 readonly)
139 self.assertEqual(202, resp.status)
140
141 # Get Volume information
142 resp, fetched_volume = self.client.get_volume(self.volume['id'])
143 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
144 self.assertEqual(200, resp.status)
145 self.assertEqual(True, bool_flag)
146
147 # Update volume readonly false
148 readonly = False
149 resp, body = self.client.update_volume_readonly(self.volume['id'],
150 readonly)
151 self.assertEqual(202, resp.status)
152
153 # Get Volume information
154 resp, fetched_volume = self.client.get_volume(self.volume['id'])
155 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
156 self.assertEqual(200, resp.status)
157 self.assertEqual(False, bool_flag)
158
anju tiwari789449a2013-08-29 16:56:17 +0530159
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800160class VolumesV2ActionsTestXML(VolumesV2ActionsTest):
161 _interface = "xml"
162
163
164class VolumesV1ActionsTest(VolumesV2ActionsTest):
165 _api_version = 1
166
167
168class VolumesV1ActionsTestXML(VolumesV1ActionsTest):
anju tiwari789449a2013-08-29 16:56:17 +0530169 _interface = "xml"