blob: a086c17d08ee1e59c5758c3a4558a05fc2456521 [file] [log] [blame]
Dan Smithc18d8c62012-07-02 08:09:26 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
Kurt Taylor6a6f5be2013-04-02 18:53:47 -04003# Copyright 2012 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()
Dan Smithc18d8c62012-07-02 08:09:26 -070039 cls.device = 'vdb'
40
41 def _detach(self, server_id, volume_id):
42 self.servers_client.detach_volume(server_id, volume_id)
43 self.volumes_client.wait_for_volume_status(volume_id, 'available')
44
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -040045 def _delete(self, volume):
ivan-zhu2f54b282013-03-11 16:39:25 +080046 if self.volume:
47 self.volumes_client.delete_volume(self.volume['id'])
48 self.volume = None
Dan Smithc18d8c62012-07-02 08:09:26 -070049
50 def _create_and_attach(self):
Dan Smithc18d8c62012-07-02 08:09:26 -070051 # Start a server and wait for it to become ready
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -040052 resp, server = self.create_server(wait_until='ACTIVE',
53 adminPass='password')
Dan Smithc18d8c62012-07-02 08:09:26 -070054
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')
ivan-zhu2f54b282013-03-11 16:39:25 +080062 self.volume = volume
Dan Smithc18d8c62012-07-02 08:09:26 -070063 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
64
65 # Attach the volume to the server
66 self.servers_client.attach_volume(server['id'], volume['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +080067 device='/dev/%s' % self.device)
Dan Smithc18d8c62012-07-02 08:09:26 -070068 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
69
ivan-zhu2f54b282013-03-11 16:39:25 +080070 self.attached = True
Dan Smithc18d8c62012-07-02 08:09:26 -070071
72 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +080073 @testtools.skipIf(not run_ssh, 'SSH required for this test')
Dan Smithc18d8c62012-07-02 08:09:26 -070074 def test_attach_detach_volume(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050075 # Stop and Start a server with an attached volume, ensuring that
76 # the volume remains attached.
Dan Smithc18d8c62012-07-02 08:09:26 -070077 try:
ivan-zhu2f54b282013-03-11 16:39:25 +080078 self._create_and_attach()
79 server = self.server
80 volume = self.volume
81
Dan Smithc18d8c62012-07-02 08:09:26 -070082 self.servers_client.stop(server['id'])
83 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
84
85 self.servers_client.start(server['id'])
86 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
87
88 linux_client = RemoteClient(server,
89 self.ssh_user, server['adminPass'])
90 partitions = linux_client.get_partitions()
91 self.assertTrue(self.device in partitions)
92
93 self._detach(server['id'], volume['id'])
Attila Fazekas954add72013-03-26 22:56:49 +010094 self.attached = False
Dan Smithc18d8c62012-07-02 08:09:26 -070095
96 self.servers_client.stop(server['id'])
97 self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
98
99 self.servers_client.start(server['id'])
100 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
101
102 linux_client = RemoteClient(server,
103 self.ssh_user, server['adminPass'])
104 partitions = linux_client.get_partitions()
105 self.assertFalse(self.device in partitions)
ivan-zhu2f54b282013-03-11 16:39:25 +0800106 except Exception:
107 self.fail("The test_attach_detach_volume is faild!")
Dan Smithc18d8c62012-07-02 08:09:26 -0700108 finally:
ivan-zhu2f54b282013-03-11 16:39:25 +0800109 if self.attached:
Dan Smithc18d8c62012-07-02 08:09:26 -0700110 self._detach(server['id'], volume['id'])
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -0400111 # NOTE(maurosr): here we do the cleanup for volume, servers are
112 # dealt on BaseComputeTest.tearDownClass
113 self._delete(self.volume)
Dan Smith1ced8422012-08-16 10:35:19 -0700114
115
Attila Fazekas19044d52013-02-16 07:35:06 +0100116class AttachVolumeTestXML(AttachVolumeTestJSON):
117 _interface = 'xml'