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 | |
| 18 | from nose.plugins.attrib import attr |
| 19 | |
| 20 | from tempest.common.utils.data_utils import rand_name |
| 21 | from tempest.tests.volume.base import BaseVolumeTest |
| 22 | |
| 23 | |
| 24 | class VolumesActionsTest(BaseVolumeTest): |
| 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): |
| 46 | super(VolumesActionsTest, cls).tearDownClass() |
| 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 | |
| 54 | @attr(type='smoke') |
| 55 | def test_attach_detach_volume_to_instance(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 56 | # Volume is attached and detached successfully from an instance |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 57 | try: |
| 58 | mountpoint = '/dev/vdc' |
| 59 | resp, body = self.client.attach_volume(self.volume['id'], |
| 60 | self.server['id'], |
| 61 | mountpoint) |
| 62 | self.assertEqual(202, resp.status) |
| 63 | self.client.wait_for_volume_status(self.volume['id'], 'in-use') |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 64 | except Exception: |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 65 | self.fail("Could not attach volume to instance") |
| 66 | finally: |
| 67 | # Detach the volume from the instance |
| 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') |
| 71 | |
| 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.client.wait_for_volume_status(self.volume['id'], 'in-use') |
| 79 | self.assertEqual(202, resp.status) |
| 80 | try: |
| 81 | resp, volume = self.client.get_volume(self.volume['id']) |
| 82 | self.assertEqual(200, resp.status) |
| 83 | self.assertTrue('attachments' in volume) |
| 84 | attachment = volume['attachments'][0] |
| 85 | self.assertEqual(mountpoint, attachment['device']) |
| 86 | self.assertEqual(self.server['id'], attachment['server_id']) |
| 87 | self.assertEqual(self.volume['id'], attachment['id']) |
| 88 | self.assertEqual(self.volume['id'], attachment['volume_id']) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 89 | except Exception: |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 90 | self.fail("Could not get attachment details from volume") |
| 91 | finally: |
| 92 | self.client.detach_volume(self.volume['id']) |
| 93 | self.client.wait_for_volume_status(self.volume['id'], 'available') |