Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.volume.base import BaseVolumeTest |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 20 | from tempest.test import attr |
Marc Koderer | 32221b8e | 2013-08-23 13:57:50 +0200 | [diff] [blame] | 21 | from tempest.test import stresstest |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class VolumesActionsTest(BaseVolumeTest): |
Attila Fazekas | 786236c | 2013-01-31 16:06:51 +0100 | [diff] [blame] | 25 | _interface = "json" |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 26 | |
| 27 | @classmethod |
| 28 | def setUpClass(cls): |
| 29 | super(VolumesActionsTest, cls).setUpClass() |
| 30 | cls.client = cls.volumes_client |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 31 | cls.image_client = cls.os.image_client |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 32 | |
| 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 Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 47 | # Delete the test instance and volume |
| 48 | cls.client.delete_volume(cls.volume['id']) |
john-griffith | 8ae54d6 | 2013-01-09 11:29:05 -0700 | [diff] [blame] | 49 | cls.client.wait_for_resource_deletion(cls.volume['id']) |
| 50 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 51 | cls.servers_client.delete_server(cls.server['id']) |
john-griffith | 8ae54d6 | 2013-01-09 11:29:05 -0700 | [diff] [blame] | 52 | cls.client.wait_for_resource_deletion(cls.server['id']) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 53 | |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame] | 54 | super(VolumesActionsTest, cls).tearDownClass() |
| 55 | |
Marc Koderer | 32221b8e | 2013-08-23 13:57:50 +0200 | [diff] [blame] | 56 | @stresstest(class_setup_per='process') |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 57 | @attr(type='smoke') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 58 | def test_attach_detach_volume_to_instance(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 59 | # Volume is attached and detached successfully from an instance |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 60 | 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 Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 69 | |
Marc Koderer | 32221b8e | 2013-08-23 13:57:50 +0200 | [diff] [blame] | 70 | @stresstest(class_setup_per='process') |
Giulio Fidente | 8b31190 | 2013-05-12 15:40:31 +0200 | [diff] [blame] | 71 | @attr(type='gate') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 72 | def test_get_volume_attachment(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 73 | # Verify that a volume's attachment information is retrieved |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 74 | mountpoint = '/dev/vdc' |
| 75 | resp, body = self.client.attach_volume(self.volume['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 76 | self.server['id'], |
| 77 | mountpoint) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 78 | self.assertEqual(202, resp.status) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 79 | 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 Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 94 | |
| 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 Griffith | a05038b | 2013-07-29 10:54:01 -0600 | [diff] [blame] | 107 | self.client.wait_for_volume_status(self.volume['id'], 'available') |