blob: f12d4bbf103178a4c501c70bec2c54ef55ac55a7 [file] [log] [blame]
Rohit Karajgia42fe442012-09-21 03:08:33 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Rohit Karajgia42fe442012-09-21 03:08:33 -07004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.volume.base import BaseVolumeTest
wanghao5b981752013-10-22 11:41:41 +080019from tempest.common.utils import data_utils
Chris Yeoh01cb2792013-02-09 22:25:37 +103020from tempest.test import attr
Matthew Treinish660a4c12013-09-09 20:06:12 +000021from tempest.test import services
Marc Koderer32221b8e2013-08-23 13:57:50 +020022from tempest.test import stresstest
Rohit Karajgia42fe442012-09-21 03:08:33 -070023
24
25class VolumesActionsTest(BaseVolumeTest):
Attila Fazekas786236c2013-01-31 16:06:51 +010026 _interface = "json"
Rohit Karajgia42fe442012-09-21 03:08:33 -070027
28 @classmethod
29 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
34 # Create a test shared instance and volume for attach/detach tests
wanghao5b981752013-10-22 11:41:41 +080035 srv_name = data_utils.rand_name(cls.__name__ + '-Instance-')
36 vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
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
42 resp, cls.volume = cls.client.create_volume(size=1,
43 display_name=vol_name)
44 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
45
46 @classmethod
47 def tearDownClass(cls):
Rohit Karajgia42fe442012-09-21 03:08:33 -070048 # Delete the test instance and volume
49 cls.client.delete_volume(cls.volume['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070050 cls.client.wait_for_resource_deletion(cls.volume['id'])
51
Rohit Karajgia42fe442012-09-21 03:08:33 -070052 cls.servers_client.delete_server(cls.server['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070053 cls.client.wait_for_resource_deletion(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070054
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050055 super(VolumesActionsTest, cls).tearDownClass()
56
Marc Koderer32221b8e2013-08-23 13:57:50 +020057 @stresstest(class_setup_per='process')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020058 @attr(type='smoke')
Matthew Treinish660a4c12013-09-09 20:06:12 +000059 @services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070060 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050061 # Volume is attached and detached successfully from an instance
Giulio Fidente92f77192013-08-26 17:13:28 +020062 mountpoint = '/dev/vdc'
63 resp, body = self.client.attach_volume(self.volume['id'],
64 self.server['id'],
65 mountpoint)
66 self.assertEqual(202, resp.status)
67 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
68 resp, body = self.client.detach_volume(self.volume['id'])
69 self.assertEqual(202, resp.status)
70 self.client.wait_for_volume_status(self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070071
Marc Koderer32221b8e2013-08-23 13:57:50 +020072 @stresstest(class_setup_per='process')
Giulio Fidente8b311902013-05-12 15:40:31 +020073 @attr(type='gate')
Matthew Treinish660a4c12013-09-09 20:06:12 +000074 @services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070075 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050076 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070077 mountpoint = '/dev/vdc'
78 resp, body = self.client.attach_volume(self.volume['id'],
Zhongyue Luoe0884a32012-09-25 17:24:17 +080079 self.server['id'],
80 mountpoint)
Rohit Karajgia42fe442012-09-21 03:08:33 -070081 self.assertEqual(202, resp.status)
Giulio Fidente92f77192013-08-26 17:13:28 +020082 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
83 # NOTE(gfidente): added in reverse order because functions will be
84 # called in reverse order to the order they are added (LIFO)
85 self.addCleanup(self.client.wait_for_volume_status,
86 self.volume['id'],
87 'available')
88 self.addCleanup(self.client.detach_volume, self.volume['id'])
89 resp, volume = self.client.get_volume(self.volume['id'])
90 self.assertEqual(200, resp.status)
91 self.assertIn('attachments', volume)
anju tiwari789449a2013-08-29 16:56:17 +053092 attachment = self.client.get_attachment_from_volume(volume)
Giulio Fidente92f77192013-08-26 17:13:28 +020093 self.assertEqual(mountpoint, attachment['device'])
94 self.assertEqual(self.server['id'], attachment['server_id'])
95 self.assertEqual(self.volume['id'], attachment['id'])
96 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020097
98 @attr(type='gate')
Matthew Treinish660a4c12013-09-09 20:06:12 +000099 @services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +0200100 def test_volume_upload(self):
101 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
102 # it is shared with the other tests. After it is uploaded in Glance,
103 # there is no way to delete it from Cinder, so we delete it from Glance
104 # using the Glance image_client and from Cinder via tearDownClass.
wanghao5b981752013-10-22 11:41:41 +0800105 image_name = data_utils.rand_name('Image-')
Ryan Hsua67f4632013-08-29 16:03:06 -0700106 resp, body = self.client.upload_volume(self.volume['id'],
107 image_name,
108 self.config.volume.disk_format)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109 image_id = body["image_id"]
110 self.addCleanup(self.image_client.delete_image, image_id)
111 self.assertEqual(202, resp.status)
112 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600113 self.client.wait_for_volume_status(self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530114
wanghao5b981752013-10-22 11:41:41 +0800115 @attr(type='gate')
116 def test_volume_extend(self):
117 # Extend Volume Test.
118 extend_size = int(self.volume['size']) + 1
119 resp, body = self.client.extend_volume(self.volume['id'], extend_size)
120 self.assertEqual(202, resp.status)
121 self.client.wait_for_volume_status(self.volume['id'], 'available')
122 resp, volume = self.client.get_volume(self.volume['id'])
123 self.assertEqual(200, resp.status)
124 self.assertEqual(int(volume['size']), extend_size)
125
anju tiwari789449a2013-08-29 16:56:17 +0530126
127class VolumesActionsTestXML(VolumesActionsTest):
128 _interface = "xml"