blob: 9fa86b6ac350328de200cd375f93b506bd289a59 [file] [log] [blame]
Rohit Karajgia42fe442012-09-21 03:08:33 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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
Rohit Karajgia42fe442012-09-21 03:08:33 -070019from tempest.common.utils.data_utils import rand_name
Chris Yeoh01cb2792013-02-09 22:25:37 +103020from tempest.test import attr
Marc Koderer32221b8e2013-08-23 13:57:50 +020021from tempest.test import stresstest
Rohit Karajgia42fe442012-09-21 03:08:33 -070022
23
24class VolumesActionsTest(BaseVolumeTest):
Attila Fazekas786236c2013-01-31 16:06:51 +010025 _interface = "json"
Rohit Karajgia42fe442012-09-21 03:08:33 -070026
27 @classmethod
28 def setUpClass(cls):
29 super(VolumesActionsTest, cls).setUpClass()
30 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
33 # Create a test shared instance and volume for attach/detach tests
34 srv_name = rand_name('Instance-')
35 vol_name = rand_name('Volume-')
36 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
41 resp, cls.volume = cls.client.create_volume(size=1,
42 display_name=vol_name)
43 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
44
45 @classmethod
46 def tearDownClass(cls):
Rohit Karajgia42fe442012-09-21 03:08:33 -070047 # Delete the test instance and volume
48 cls.client.delete_volume(cls.volume['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070049 cls.client.wait_for_resource_deletion(cls.volume['id'])
50
Rohit Karajgia42fe442012-09-21 03:08:33 -070051 cls.servers_client.delete_server(cls.server['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070052 cls.client.wait_for_resource_deletion(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070053
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050054 super(VolumesActionsTest, cls).tearDownClass()
55
Marc Koderer32221b8e2013-08-23 13:57:50 +020056 @stresstest(class_setup_per='process')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020057 @attr(type='smoke')
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
Marc Koderer32221b8e2013-08-23 13:57:50 +020070 @stresstest(class_setup_per='process')
Giulio Fidente8b311902013-05-12 15:40:31 +020071 @attr(type='gate')
Rohit Karajgia42fe442012-09-21 03:08:33 -070072 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050073 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070074 mountpoint = '/dev/vdc'
75 resp, body = self.client.attach_volume(self.volume['id'],
Zhongyue Luoe0884a32012-09-25 17:24:17 +080076 self.server['id'],
77 mountpoint)
Rohit Karajgia42fe442012-09-21 03:08:33 -070078 self.assertEqual(202, resp.status)
Giulio Fidente92f77192013-08-26 17:13:28 +020079 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
80 # NOTE(gfidente): added in reverse order because functions will be
81 # called in reverse order to the order they are added (LIFO)
82 self.addCleanup(self.client.wait_for_volume_status,
83 self.volume['id'],
84 'available')
85 self.addCleanup(self.client.detach_volume, self.volume['id'])
86 resp, volume = self.client.get_volume(self.volume['id'])
87 self.assertEqual(200, resp.status)
88 self.assertIn('attachments', volume)
89 attachment = volume['attachments'][0]
90 self.assertEqual(mountpoint, attachment['device'])
91 self.assertEqual(self.server['id'], attachment['server_id'])
92 self.assertEqual(self.volume['id'], attachment['id'])
93 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020094
95 @attr(type='gate')
96 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.
101 image_name = rand_name('Image-')
102 resp, body = self.client.upload_volume(self.volume['id'], image_name)
103 image_id = body["image_id"]
104 self.addCleanup(self.image_client.delete_image, image_id)
105 self.assertEqual(202, resp.status)
106 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600107 self.client.wait_for_volume_status(self.volume['id'], 'available')