blob: 5c1ad0d219285ec8f271117deb46637507b4f4de [file] [log] [blame]
Dan Smithc18d8c62012-07-02 08:09:26 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
Matt Riedemannbc8dbd32013-08-02 14:02:12 -07003# Copyright 2013 IBM Corp.
Dan Smithc18d8c62012-07-02 08:09:26 -07004# 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
ivan-zhu1feeb382013-01-24 10:14:39 +080018import testtools
Dan Smithc18d8c62012-07-02 08:09:26 -070019
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.compute import base
Dan Smithc18d8c62012-07-02 08:09:26 -070021from tempest.common.utils.linux.remote_client import RemoteClient
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022import tempest.config
Chris Yeoh9465b0b2013-02-09 22:19:15 +103023from tempest.test import attr
Dan Smithc18d8c62012-07-02 08:09:26 -070024
25
Attila Fazekas19044d52013-02-16 07:35:06 +010026class AttachVolumeTestJSON(base.BaseComputeTest):
27 _interface = 'json'
Dan Smithc18d8c62012-07-02 08:09:26 -070028 run_ssh = tempest.config.TempestConfig().compute.run_ssh
Ryan Hsucb2e1252013-09-03 21:44:49 -070029 device = tempest.config.TempestConfig().compute.volume_device_name
Dan Smithc18d8c62012-07-02 08:09:26 -070030
ivan-zhu2f54b282013-03-11 16:39:25 +080031 def __init__(self, *args, **kwargs):
32 super(AttachVolumeTestJSON, self).__init__(*args, **kwargs)
33 self.server = None
34 self.volume = None
35 self.attached = False
36
Attila Fazekas19044d52013-02-16 07:35:06 +010037 @classmethod
Dan Smithc18d8c62012-07-02 08:09:26 -070038 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010039 super(AttachVolumeTestJSON, cls).setUpClass()
Ryan Hsucb2e1252013-09-03 21:44:49 -070040
Matthew Treinish4c412922013-07-16 15:27:42 -040041 if not cls.config.service_available.cinder:
42 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
43 raise cls.skipException(skip_msg)
Dan Smithc18d8c62012-07-02 08:09:26 -070044
45 def _detach(self, server_id, volume_id):
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070046 if self.attached:
47 self.servers_client.detach_volume(server_id, volume_id)
48 self.volumes_client.wait_for_volume_status(volume_id, 'available')
Dan Smithc18d8c62012-07-02 08:09:26 -070049
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070050 def _delete_volume(self):
ivan-zhu2f54b282013-03-11 16:39:25 +080051 if self.volume:
52 self.volumes_client.delete_volume(self.volume['id'])
53 self.volume = None
Dan Smithc18d8c62012-07-02 08:09:26 -070054
55 def _create_and_attach(self):
Dan Smithc18d8c62012-07-02 08:09:26 -070056 # Start a server and wait for it to become ready
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -040057 resp, server = self.create_server(wait_until='ACTIVE',
Ryan Hsucb2e1252013-09-03 21:44:49 -070058 adminPass=self.image_ssh_password)
Ryan Hsu6a7a2d52013-08-19 20:00:36 -070059 self.server = server
Dan Smithc18d8c62012-07-02 08:09:26 -070060
61 # Record addresses so that we can ssh later
62 resp, server['addresses'] = \
63 self.servers_client.list_addresses(server['id'])
64
65 # Create a volume and wait for it to become ready
66 resp, volume = self.volumes_client.create_volume(1,
67 display_name='test')
ivan-zhu2f54b282013-03-11 16:39:25 +080068 self.volume = volume
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070069 self.addCleanup(self._delete_volume)
Dan Smithc18d8c62012-07-02 08:09:26 -070070 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
71
72 # Attach the volume to the server
73 self.servers_client.attach_volume(server['id'], volume['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +080074 device='/dev/%s' % self.device)
Dan Smithc18d8c62012-07-02 08:09:26 -070075 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
76
ivan-zhu2f54b282013-03-11 16:39:25 +080077 self.attached = True
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070078 self.addCleanup(self._detach, server['id'], volume['id'])
Dan Smithc18d8c62012-07-02 08:09:26 -070079
ivan-zhu1feeb382013-01-24 10:14:39 +080080 @testtools.skipIf(not run_ssh, 'SSH required for this test')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020081 @attr(type='gate')
Dan Smithc18d8c62012-07-02 08:09:26 -070082 def test_attach_detach_volume(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050083 # Stop and Start a server with an attached volume, ensuring that
84 # the volume remains attached.
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070085 self._create_and_attach()
86 server = self.server
87 volume = self.volume
ivan-zhu2f54b282013-03-11 16:39:25 +080088
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070089 self.servers_client.stop(server['id'])
90 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
Dan Smithc18d8c62012-07-02 08:09:26 -070091
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070092 self.servers_client.start(server['id'])
93 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Dan Smithc18d8c62012-07-02 08:09:26 -070094
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070095 linux_client = RemoteClient(server,
Ryan Hsucb2e1252013-09-03 21:44:49 -070096 self.image_ssh_user, server['adminPass'])
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070097 partitions = linux_client.get_partitions()
98 self.assertIn(self.device, partitions)
Dan Smithc18d8c62012-07-02 08:09:26 -070099
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700100 self._detach(server['id'], volume['id'])
101 self.attached = False
Dan Smithc18d8c62012-07-02 08:09:26 -0700102
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700103 self.servers_client.stop(server['id'])
104 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
Dan Smithc18d8c62012-07-02 08:09:26 -0700105
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700106 self.servers_client.start(server['id'])
107 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Dan Smithc18d8c62012-07-02 08:09:26 -0700108
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700109 linux_client = RemoteClient(server,
Ryan Hsucb2e1252013-09-03 21:44:49 -0700110 self.image_ssh_user, server['adminPass'])
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700111 partitions = linux_client.get_partitions()
112 self.assertNotIn(self.device, partitions)
Dan Smith1ced8422012-08-16 10:35:19 -0700113
114
Attila Fazekas19044d52013-02-16 07:35:06 +0100115class AttachVolumeTestXML(AttachVolumeTestJSON):
116 _interface = 'xml'