Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
Kurt Taylor | 6a6f5be | 2013-04-02 18:53:47 -0400 | [diff] [blame] | 3 | # Copyright 2012 IBM Corp. |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 4 | # 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-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 18 | import testtools |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 19 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame^] | 20 | from tempest.api.compute import base |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 21 | from tempest.common.utils.linux.remote_client import RemoteClient |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 22 | import tempest.config |
Chris Yeoh | 9465b0b | 2013-02-09 22:19:15 +1030 | [diff] [blame] | 23 | from tempest.test import attr |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 24 | |
| 25 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 26 | class AttachVolumeTestJSON(base.BaseComputeTest): |
| 27 | _interface = 'json' |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 28 | run_ssh = tempest.config.TempestConfig().compute.run_ssh |
| 29 | |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 30 | 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 Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 36 | @classmethod |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 37 | def setUpClass(cls): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 38 | super(AttachVolumeTestJSON, cls).setUpClass() |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 39 | 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. Rodrigues | 0a1bdff | 2013-03-11 11:41:18 -0400 | [diff] [blame] | 45 | def _delete(self, volume): |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 46 | if self.volume: |
| 47 | self.volumes_client.delete_volume(self.volume['id']) |
| 48 | self.volume = None |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 49 | |
| 50 | def _create_and_attach(self): |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 51 | # Start a server and wait for it to become ready |
Mauro S. M. Rodrigues | 0a1bdff | 2013-03-11 11:41:18 -0400 | [diff] [blame] | 52 | resp, server = self.create_server(wait_until='ACTIVE', |
| 53 | adminPass='password') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 54 | |
| 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-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 62 | self.volume = volume |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 63 | 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 Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 67 | device='/dev/%s' % self.device) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 68 | self.volumes_client.wait_for_volume_status(volume['id'], 'in-use') |
| 69 | |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 70 | self.attached = True |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 71 | |
| 72 | @attr(type='positive') |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 73 | @testtools.skipIf(not run_ssh, 'SSH required for this test') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 74 | def test_attach_detach_volume(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 75 | # Stop and Start a server with an attached volume, ensuring that |
| 76 | # the volume remains attached. |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 77 | try: |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 78 | self._create_and_attach() |
| 79 | server = self.server |
| 80 | volume = self.volume |
| 81 | |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 82 | 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 Fazekas | 954add7 | 2013-03-26 22:56:49 +0100 | [diff] [blame] | 94 | self.attached = False |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 95 | |
| 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-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 106 | except Exception: |
| 107 | self.fail("The test_attach_detach_volume is faild!") |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 108 | finally: |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 109 | if self.attached: |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 110 | self._detach(server['id'], volume['id']) |
Mauro S. M. Rodrigues | 0a1bdff | 2013-03-11 11:41:18 -0400 | [diff] [blame] | 111 | # NOTE(maurosr): here we do the cleanup for volume, servers are |
| 112 | # dealt on BaseComputeTest.tearDownClass |
| 113 | self._delete(self.volume) |
Dan Smith | 1ced842 | 2012-08-16 10:35:19 -0700 | [diff] [blame] | 114 | |
| 115 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 116 | class AttachVolumeTestXML(AttachVolumeTestJSON): |
| 117 | _interface = 'xml' |