blob: 8664a7dfd9e05da89a6a42bf88e4dd734d2e45e9 [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
Rohit Karajgia42fe442012-09-21 03:08:33 -070018from tempest.common.utils.data_utils import rand_name
Chris Yeoh01cb2792013-02-09 22:25:37 +103019from tempest.test import attr
Rohit Karajgia42fe442012-09-21 03:08:33 -070020from tempest.tests.volume.base import BaseVolumeTest
21
22
23class VolumesActionsTest(BaseVolumeTest):
Attila Fazekas786236c2013-01-31 16:06:51 +010024 _interface = "json"
Rohit Karajgia42fe442012-09-21 03:08:33 -070025
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 Karajgia42fe442012-09-21 03:08:33 -070046 # Delete the test instance and volume
47 cls.client.delete_volume(cls.volume['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070048 cls.client.wait_for_resource_deletion(cls.volume['id'])
49
Rohit Karajgia42fe442012-09-21 03:08:33 -070050 cls.servers_client.delete_server(cls.server['id'])
john-griffith8ae54d62013-01-09 11:29:05 -070051 cls.client.wait_for_resource_deletion(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070052
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050053 super(VolumesActionsTest, cls).tearDownClass()
54
Chris Yeohcf3fb7c2013-05-19 15:59:00 +093055 @attr(type=['smoke'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070056 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050057 # Volume is attached and detached successfully from an instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070058 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 Treinish05d9fb92012-12-07 16:14:05 -050065 except Exception:
Rohit Karajgia42fe442012-09-21 03:08:33 -070066 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 Fidente8b311902013-05-12 15:40:31 +020073 @attr(type='gate')
Rohit Karajgia42fe442012-09-21 03:08:33 -070074 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050075 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070076 mountpoint = '/dev/vdc'
77 resp, body = self.client.attach_volume(self.volume['id'],
Zhongyue Luoe0884a32012-09-25 17:24:17 +080078 self.server['id'],
79 mountpoint)
Rohit Karajgia42fe442012-09-21 03:08:33 -070080 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 Treinish05d9fb92012-12-07 16:14:05 -050091 except Exception:
Rohit Karajgia42fe442012-09-21 03:08:33 -070092 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')