blob: 3c5feede599031f9ac71098db47981de83b2c479 [file] [log] [blame]
Matt Riedemannbc8dbd32013-08-02 14:02:12 -07001# Copyright 2013 IBM Corp.
Dan Smithc18d8c62012-07-02 08:09:26 -07002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
ivan-zhu1feeb382013-01-24 10:14:39 +080016import testtools
Dan Smithc18d8c62012-07-02 08:09:26 -070017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Masayuki Igawa209fd502014-02-17 14:46:43 +090019from tempest.common.utils.linux import remote_client
Sean Dague86bd8422013-12-20 09:56:44 -050020from tempest import config
Masayuki Igawa209fd502014-02-17 14:46:43 +090021from tempest import test
Dan Smithc18d8c62012-07-02 08:09:26 -070022
Sean Dague86bd8422013-12-20 09:56:44 -050023CONF = config.CONF
24
Dan Smithc18d8c62012-07-02 08:09:26 -070025
ivan-zhuf2b00502013-10-18 10:06:52 +080026class AttachVolumeTestJSON(base.BaseV2ComputeTest):
Sean Dague86bd8422013-12-20 09:56:44 -050027 run_ssh = CONF.compute.run_ssh
Dan Smithc18d8c62012-07-02 08:09:26 -070028
ivan-zhu2f54b282013-03-11 16:39:25 +080029 def __init__(self, *args, **kwargs):
30 super(AttachVolumeTestJSON, self).__init__(*args, **kwargs)
31 self.server = None
32 self.volume = None
33 self.attached = False
34
Attila Fazekas19044d52013-02-16 07:35:06 +010035 @classmethod
Dan Smithc18d8c62012-07-02 08:09:26 -070036 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010037 super(AttachVolumeTestJSON, cls).setUpClass()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000038 cls.device = CONF.compute.volume_device_name
39 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040040 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
41 raise cls.skipException(skip_msg)
Dan Smithc18d8c62012-07-02 08:09:26 -070042
43 def _detach(self, server_id, volume_id):
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070044 if self.attached:
45 self.servers_client.detach_volume(server_id, volume_id)
46 self.volumes_client.wait_for_volume_status(volume_id, 'available')
Dan Smithc18d8c62012-07-02 08:09:26 -070047
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070048 def _delete_volume(self):
ivan-zhu2f54b282013-03-11 16:39:25 +080049 if self.volume:
50 self.volumes_client.delete_volume(self.volume['id'])
51 self.volume = None
Dan Smithc18d8c62012-07-02 08:09:26 -070052
53 def _create_and_attach(self):
Dan Smithc18d8c62012-07-02 08:09:26 -070054 # Start a server and wait for it to become ready
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090055 admin_pass = self.image_ssh_password
56 resp, server = self.create_test_server(wait_until='ACTIVE',
57 adminPass=admin_pass)
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')
Masayuki Igawa209fd502014-02-17 14:46:43 +090080 @test.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
Masayuki Igawa209fd502014-02-17 14:46:43 +090094 linux_client = remote_client.RemoteClient(server, self.image_ssh_user,
95 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
Masayuki Igawa209fd502014-02-17 14:46:43 +0900108 linux_client = remote_client.RemoteClient(server, self.image_ssh_user,
109 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'