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 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 18 | from tempest.common.utils.data_utils import rand_name |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 19 | from tempest.test import attr |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 20 | from tempest.tests.volume.base import BaseVolumeTest |
| 21 | |
| 22 | |
| 23 | class VolumesActionsTest(BaseVolumeTest): |
Attila Fazekas | 786236c | 2013-01-31 16:06:51 +0100 | [diff] [blame] | 24 | _interface = "json" |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(VolumesActionsTest, cls).setUpClass() |
| 29 | cls.client = cls.volumes_client |
| 30 | cls.servers_client = cls.servers_client |
| 31 | |
| 32 | # Create a test shared instance and volume for attach/detach tests |
| 33 | srv_name = rand_name('Instance-') |
| 34 | vol_name = rand_name('Volume-') |
| 35 | 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 | |
| 40 | resp, cls.volume = cls.client.create_volume(size=1, |
| 41 | display_name=vol_name) |
| 42 | cls.client.wait_for_volume_status(cls.volume['id'], 'available') |
| 43 | |
| 44 | @classmethod |
| 45 | def tearDownClass(cls): |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 46 | # Delete the test instance and volume |
| 47 | cls.client.delete_volume(cls.volume['id']) |
john-griffith | 8ae54d6 | 2013-01-09 11:29:05 -0700 | [diff] [blame] | 48 | cls.client.wait_for_resource_deletion(cls.volume['id']) |
| 49 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 50 | cls.servers_client.delete_server(cls.server['id']) |
john-griffith | 8ae54d6 | 2013-01-09 11:29:05 -0700 | [diff] [blame] | 51 | cls.client.wait_for_resource_deletion(cls.server['id']) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 52 | |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame] | 53 | super(VolumesActionsTest, cls).tearDownClass() |
| 54 | |
Chris Yeoh | cf3fb7c | 2013-05-19 15:59:00 +0930 | [diff] [blame^] | 55 | @attr(type=['smoke']) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 56 | def test_attach_detach_volume_to_instance(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 57 | # Volume is attached and detached successfully from an instance |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 58 | try: |
| 59 | mountpoint = '/dev/vdc' |
| 60 | resp, body = self.client.attach_volume(self.volume['id'], |
| 61 | self.server['id'], |
| 62 | mountpoint) |
| 63 | self.assertEqual(202, resp.status) |
| 64 | self.client.wait_for_volume_status(self.volume['id'], 'in-use') |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 65 | except Exception: |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 66 | self.fail("Could not attach volume to instance") |
| 67 | finally: |
| 68 | # Detach the volume from the instance |
| 69 | resp, body = self.client.detach_volume(self.volume['id']) |
| 70 | self.assertEqual(202, resp.status) |
| 71 | self.client.wait_for_volume_status(self.volume['id'], 'available') |
| 72 | |
Giulio Fidente | 8b31190 | 2013-05-12 15:40:31 +0200 | [diff] [blame] | 73 | @attr(type='gate') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 74 | def test_get_volume_attachment(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 75 | # Verify that a volume's attachment information is retrieved |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 76 | mountpoint = '/dev/vdc' |
| 77 | resp, body = self.client.attach_volume(self.volume['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 78 | self.server['id'], |
| 79 | mountpoint) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 80 | self.client.wait_for_volume_status(self.volume['id'], 'in-use') |
| 81 | self.assertEqual(202, resp.status) |
| 82 | try: |
| 83 | resp, volume = self.client.get_volume(self.volume['id']) |
| 84 | self.assertEqual(200, resp.status) |
| 85 | self.assertTrue('attachments' in volume) |
| 86 | attachment = volume['attachments'][0] |
| 87 | self.assertEqual(mountpoint, attachment['device']) |
| 88 | self.assertEqual(self.server['id'], attachment['server_id']) |
| 89 | self.assertEqual(self.volume['id'], attachment['id']) |
| 90 | self.assertEqual(self.volume['id'], attachment['volume_id']) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 91 | except Exception: |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 92 | self.fail("Could not get attachment details from volume") |
| 93 | finally: |
| 94 | self.client.detach_volume(self.volume['id']) |
| 95 | self.client.wait_for_volume_status(self.volume['id'], 'available') |