blob: 155acb6445ba8bd29f8572218077a31142ab8540 [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
18from nose.plugins.attrib import attr
19
20from tempest.common.utils.data_utils import rand_name
21from tempest.tests.volume.base import BaseVolumeTest
22
23
24class 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-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
54 @attr(type='smoke')
55 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050056 # Volume is attached and detached successfully from an instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070057 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 Treinish05d9fb92012-12-07 16:14:05 -050064 except Exception:
Rohit Karajgia42fe442012-09-21 03:08:33 -070065 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 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.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 Treinish05d9fb92012-12-07 16:14:05 -050089 except Exception:
Rohit Karajgia42fe442012-09-21 03:08:33 -070090 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')