blob: 07bd7aa5fea7826664fa52e4fb07b5a091effd90 [file] [log] [blame]
Dan Smithc18d8c62012-07-02 08:09:26 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 IBM
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
19import unittest2 as unittest
20
21import tempest.config
22from tempest.common.utils.data_utils import rand_name
23from tempest.common.utils.linux.remote_client import RemoteClient
24from tempest import openstack
25from tempest.tests.compute.base import BaseComputeTest
26
27
28class TestAttachVolume(BaseComputeTest):
29
30 run_ssh = tempest.config.TempestConfig().compute.run_ssh
31
32 @classmethod
33 def setUpClass(cls):
34 super(TestAttachVolume, cls).setUpClass()
35 cls.device = 'vdb'
36
37 def _detach(self, server_id, volume_id):
38 self.servers_client.detach_volume(server_id, volume_id)
39 self.volumes_client.wait_for_volume_status(volume_id, 'available')
40
41 def _delete(self, server_id, volume_id):
42 self.volumes_client.delete_volume(volume_id)
43 self.servers_client.delete_server(server_id)
44
45 def _create_and_attach(self):
46 name = rand_name('server')
47
48 # Start a server and wait for it to become ready
49 resp, server = self.servers_client.create_server(name,
50 self.image_ref,
51 self.flavor_ref,
52 adminPass='password')
53 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
54
55 # Record addresses so that we can ssh later
56 resp, server['addresses'] = \
57 self.servers_client.list_addresses(server['id'])
58
59 # Create a volume and wait for it to become ready
60 resp, volume = self.volumes_client.create_volume(1,
61 display_name='test')
62 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
63
64 # Attach the volume to the server
65 self.servers_client.attach_volume(server['id'], volume['id'],
66 device='/dev/%s' % self.device)
67 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
68
69 return server, volume
70
71 @attr(type='positive')
72 @unittest.skipIf(not run_ssh, 'SSH required for this test')
73 def test_attach_detach_volume(self):
74 """
75 Stop and Start a server with an attached volume, ensuring that
76 the volume remains attached.
77 """
78 server, volume = self._create_and_attach()
79
80 attached = True
81
82 try:
83 self.servers_client.stop(server['id'])
84 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
85
86 self.servers_client.start(server['id'])
87 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
88
89 linux_client = RemoteClient(server,
90 self.ssh_user, server['adminPass'])
91 partitions = linux_client.get_partitions()
92 self.assertTrue(self.device in partitions)
93
94 self._detach(server['id'], volume['id'])
95 attached = False
96
97 self.servers_client.stop(server['id'])
98 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
99
100 self.servers_client.start(server['id'])
101 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
102
103 linux_client = RemoteClient(server,
104 self.ssh_user, server['adminPass'])
105 partitions = linux_client.get_partitions()
106 self.assertFalse(self.device in partitions)
107 finally:
108 if attached:
109 self._detach(server['id'], volume['id'])
110 self._delete(server['id'], volume['id'])