blob: ee1ad9e5689b5023307c50bebf650a8cfac36160 [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
29
ivan-zhu2f54b282013-03-11 16:39:25 +080030 def __init__(self, *args, **kwargs):
31 super(AttachVolumeTestJSON, self).__init__(*args, **kwargs)
32 self.server = None
33 self.volume = None
34 self.attached = False
35
Attila Fazekas19044d52013-02-16 07:35:06 +010036 @classmethod
Dan Smithc18d8c62012-07-02 08:09:26 -070037 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010038 super(AttachVolumeTestJSON, cls).setUpClass()
Matthew Treinish6bd91db2013-09-09 17:30:16 +000039 cls.device = cls.config.compute.volume_device_name
Matthew Treinish4c412922013-07-16 15:27:42 -040040 if not cls.config.service_available.cinder:
41 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
42 raise cls.skipException(skip_msg)
Dan Smithc18d8c62012-07-02 08:09:26 -070043
44 def _detach(self, server_id, volume_id):
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070045 if self.attached:
46 self.servers_client.detach_volume(server_id, volume_id)
47 self.volumes_client.wait_for_volume_status(volume_id, 'available')
Dan Smithc18d8c62012-07-02 08:09:26 -070048
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070049 def _delete_volume(self):
ivan-zhu2f54b282013-03-11 16:39:25 +080050 if self.volume:
51 self.volumes_client.delete_volume(self.volume['id'])
52 self.volume = None
Dan Smithc18d8c62012-07-02 08:09:26 -070053
54 def _create_and_attach(self):
Dan Smithc18d8c62012-07-02 08:09:26 -070055 # Start a server and wait for it to become ready
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -040056 resp, server = self.create_server(wait_until='ACTIVE',
Ryan Hsucb2e1252013-09-03 21:44:49 -070057 adminPass=self.image_ssh_password)
Ryan Hsu6a7a2d52013-08-19 20:00:36 -070058 self.server = server
Dan Smithc18d8c62012-07-02 08:09:26 -070059
60 # Record addresses so that we can ssh later
61 resp, server['addresses'] = \
62 self.servers_client.list_addresses(server['id'])
63
64 # Create a volume and wait for it to become ready
65 resp, volume = self.volumes_client.create_volume(1,
66 display_name='test')
ivan-zhu2f54b282013-03-11 16:39:25 +080067 self.volume = volume
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070068 self.addCleanup(self._delete_volume)
Dan Smithc18d8c62012-07-02 08:09:26 -070069 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
70
71 # Attach the volume to the server
72 self.servers_client.attach_volume(server['id'], volume['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +080073 device='/dev/%s' % self.device)
Dan Smithc18d8c62012-07-02 08:09:26 -070074 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
75
ivan-zhu2f54b282013-03-11 16:39:25 +080076 self.attached = True
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070077 self.addCleanup(self._detach, server['id'], volume['id'])
Dan Smithc18d8c62012-07-02 08:09:26 -070078
ivan-zhu1feeb382013-01-24 10:14:39 +080079 @testtools.skipIf(not run_ssh, 'SSH required for this test')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020080 @attr(type='gate')
Dan Smithc18d8c62012-07-02 08:09:26 -070081 def test_attach_detach_volume(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050082 # Stop and Start a server with an attached volume, ensuring that
83 # the volume remains attached.
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070084 self._create_and_attach()
85 server = self.server
86 volume = self.volume
ivan-zhu2f54b282013-03-11 16:39:25 +080087
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070088 self.servers_client.stop(server['id'])
89 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
Dan Smithc18d8c62012-07-02 08:09:26 -070090
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070091 self.servers_client.start(server['id'])
92 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Dan Smithc18d8c62012-07-02 08:09:26 -070093
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070094 linux_client = RemoteClient(server,
Ryan Hsucb2e1252013-09-03 21:44:49 -070095 self.image_ssh_user, server['adminPass'])
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070096 partitions = linux_client.get_partitions()
97 self.assertIn(self.device, partitions)
Dan Smithc18d8c62012-07-02 08:09:26 -070098
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070099 self._detach(server['id'], volume['id'])
100 self.attached = False
Dan Smithc18d8c62012-07-02 08:09:26 -0700101
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700102 self.servers_client.stop(server['id'])
103 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
Dan Smithc18d8c62012-07-02 08:09:26 -0700104
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700105 self.servers_client.start(server['id'])
106 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Dan Smithc18d8c62012-07-02 08:09:26 -0700107
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700108 linux_client = RemoteClient(server,
Ryan Hsucb2e1252013-09-03 21:44:49 -0700109 self.image_ssh_user, server['adminPass'])
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700110 partitions = linux_client.get_partitions()
111 self.assertNotIn(self.device, partitions)
Dan Smith1ced8422012-08-16 10:35:19 -0700112
113
Attila Fazekas19044d52013-02-16 07:35:06 +0100114class AttachVolumeTestXML(AttachVolumeTestJSON):
115 _interface = 'xml'