blob: ab9d144ffd0997f92f591418f052251e2e26e279 [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):
Dan Smithc18d8c62012-07-02 08:09:26 -070027
ivan-zhu2f54b282013-03-11 16:39:25 +080028 def __init__(self, *args, **kwargs):
29 super(AttachVolumeTestJSON, self).__init__(*args, **kwargs)
30 self.server = None
31 self.volume = None
32 self.attached = False
33
Attila Fazekas19044d52013-02-16 07:35:06 +010034 @classmethod
Dan Smithc18d8c62012-07-02 08:09:26 -070035 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010036 super(AttachVolumeTestJSON, cls).setUpClass()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000037 cls.device = CONF.compute.volume_device_name
38 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040039 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
40 raise cls.skipException(skip_msg)
Dan Smithc18d8c62012-07-02 08:09:26 -070041
42 def _detach(self, server_id, volume_id):
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070043 if self.attached:
44 self.servers_client.detach_volume(server_id, volume_id)
45 self.volumes_client.wait_for_volume_status(volume_id, 'available')
Dan Smithc18d8c62012-07-02 08:09:26 -070046
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070047 def _delete_volume(self):
ivan-zhu2f54b282013-03-11 16:39:25 +080048 if self.volume:
49 self.volumes_client.delete_volume(self.volume['id'])
50 self.volume = None
Dan Smithc18d8c62012-07-02 08:09:26 -070051
52 def _create_and_attach(self):
Dan Smithc18d8c62012-07-02 08:09:26 -070053 # Start a server and wait for it to become ready
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090054 admin_pass = self.image_ssh_password
55 resp, server = self.create_test_server(wait_until='ACTIVE',
56 adminPass=admin_pass)
Ryan Hsu6a7a2d52013-08-19 20:00:36 -070057 self.server = server
Dan Smithc18d8c62012-07-02 08:09:26 -070058
59 # Record addresses so that we can ssh later
60 resp, server['addresses'] = \
61 self.servers_client.list_addresses(server['id'])
62
63 # Create a volume and wait for it to become ready
64 resp, volume = self.volumes_client.create_volume(1,
65 display_name='test')
ivan-zhu2f54b282013-03-11 16:39:25 +080066 self.volume = volume
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070067 self.addCleanup(self._delete_volume)
Dan Smithc18d8c62012-07-02 08:09:26 -070068 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
69
70 # Attach the volume to the server
71 self.servers_client.attach_volume(server['id'], volume['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +080072 device='/dev/%s' % self.device)
Dan Smithc18d8c62012-07-02 08:09:26 -070073 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
74
ivan-zhu2f54b282013-03-11 16:39:25 +080075 self.attached = True
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070076 self.addCleanup(self._detach, server['id'], volume['id'])
Dan Smithc18d8c62012-07-02 08:09:26 -070077
Matt Riedemann6c668202014-03-24 09:17:10 -070078 @testtools.skipUnless(CONF.compute.run_ssh, 'SSH required for this test')
Masayuki Igawa209fd502014-02-17 14:46:43 +090079 @test.attr(type='gate')
Dan Smithc18d8c62012-07-02 08:09:26 -070080 def test_attach_detach_volume(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050081 # Stop and Start a server with an attached volume, ensuring that
82 # the volume remains attached.
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070083 self._create_and_attach()
84 server = self.server
85 volume = self.volume
ivan-zhu2f54b282013-03-11 16:39:25 +080086
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070087 self.servers_client.stop(server['id'])
88 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
Dan Smithc18d8c62012-07-02 08:09:26 -070089
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070090 self.servers_client.start(server['id'])
91 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Dan Smithc18d8c62012-07-02 08:09:26 -070092
Masayuki Igawa209fd502014-02-17 14:46:43 +090093 linux_client = remote_client.RemoteClient(server, self.image_ssh_user,
94 server['adminPass'])
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070095 partitions = linux_client.get_partitions()
96 self.assertIn(self.device, partitions)
Dan Smithc18d8c62012-07-02 08:09:26 -070097
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070098 self._detach(server['id'], volume['id'])
99 self.attached = False
Dan Smithc18d8c62012-07-02 08:09:26 -0700100
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700101 self.servers_client.stop(server['id'])
102 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
Dan Smithc18d8c62012-07-02 08:09:26 -0700103
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700104 self.servers_client.start(server['id'])
105 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Dan Smithc18d8c62012-07-02 08:09:26 -0700106
Masayuki Igawa209fd502014-02-17 14:46:43 +0900107 linux_client = remote_client.RemoteClient(server, self.image_ssh_user,
108 server['adminPass'])
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700109 partitions = linux_client.get_partitions()
110 self.assertNotIn(self.device, partitions)
Dan Smith1ced8422012-08-16 10:35:19 -0700111
112
Attila Fazekas19044d52013-02-16 07:35:06 +0100113class AttachVolumeTestXML(AttachVolumeTestJSON):
114 _interface = 'xml'