Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 1 | # Copyright 2013 IBM Corp. |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 2 | # 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-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 16 | import testtools |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 19 | from tempest.common import compute |
Anna Babich | 68f261d | 2016-09-13 11:32:13 +0300 | [diff] [blame] | 20 | from tempest.common.utils import data_utils |
Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 21 | from tempest.common.utils.linux import remote_client |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 22 | from tempest.common import waiters |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 23 | from tempest import config |
Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 24 | from tempest import test |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 25 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 26 | CONF = config.CONF |
| 27 | |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 28 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 29 | class AttachVolumeTestJSON(base.BaseV2ComputeTest): |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 30 | max_microversion = '2.19' |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 31 | |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 32 | def __init__(self, *args, **kwargs): |
| 33 | super(AttachVolumeTestJSON, self).__init__(*args, **kwargs) |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 34 | self.attachment = None |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 35 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 36 | @classmethod |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 37 | def skip_checks(cls): |
| 38 | super(AttachVolumeTestJSON, cls).skip_checks() |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 39 | if not CONF.service_available.cinder: |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 40 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 41 | raise cls.skipException(skip_msg) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 42 | |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 43 | @classmethod |
| 44 | def setup_credentials(cls): |
| 45 | cls.prepare_instance_network() |
| 46 | super(AttachVolumeTestJSON, cls).setup_credentials() |
| 47 | |
| 48 | @classmethod |
| 49 | def resource_setup(cls): |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 50 | cls.set_validation_resources() |
| 51 | |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 52 | super(AttachVolumeTestJSON, cls).resource_setup() |
| 53 | cls.device = CONF.compute.volume_device_name |
| 54 | |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 55 | def _detach(self, server_id, volume_id): |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 56 | if self.attachment: |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 57 | self.servers_client.detach_volume(server_id, volume_id) |
Yaroslav Lobankov | ed3a35b | 2016-03-24 22:41:30 -0500 | [diff] [blame] | 58 | waiters.wait_for_volume_status(self.volumes_client, |
| 59 | volume_id, 'available') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 60 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 61 | def _create_server(self): |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 62 | # Start a server and wait for it to become ready |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 63 | server = self.create_test_server( |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 64 | validatable=True, |
| 65 | wait_until='ACTIVE', |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 66 | adminPass=self.image_ssh_password) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 67 | |
| 68 | # Record addresses so that we can ssh later |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 69 | server['addresses'] = self.servers_client.list_addresses( |
| 70 | server['id'])['addresses'] |
| 71 | return server |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 72 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 73 | def _create_and_attach_volume(self, server): |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 74 | # Create a volume and wait for it to become ready |
Anna Babich | 68f261d | 2016-09-13 11:32:13 +0300 | [diff] [blame] | 75 | vol_name = data_utils.rand_name(self.__class__.__name__ + '-volume') |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 76 | volume = self.volumes_client.create_volume( |
Anna Babich | 68f261d | 2016-09-13 11:32:13 +0300 | [diff] [blame] | 77 | size=CONF.volume.volume_size, display_name=vol_name)['volume'] |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 78 | self.addCleanup(self.delete_volume, volume['id']) |
Yaroslav Lobankov | ed3a35b | 2016-03-24 22:41:30 -0500 | [diff] [blame] | 79 | waiters.wait_for_volume_status(self.volumes_client, |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 80 | volume['id'], 'available') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 81 | |
| 82 | # Attach the volume to the server |
David Kranz | 3ebc721 | 2015-02-10 12:19:19 -0500 | [diff] [blame] | 83 | self.attachment = self.servers_client.attach_volume( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 84 | server['id'], |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 85 | volumeId=volume['id'], |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 86 | device='/dev/%s' % self.device)['volumeAttachment'] |
Yaroslav Lobankov | ed3a35b | 2016-03-24 22:41:30 -0500 | [diff] [blame] | 87 | waiters.wait_for_volume_status(self.volumes_client, |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 88 | volume['id'], 'in-use') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 89 | |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 90 | self.addCleanup(self._detach, server['id'], volume['id']) |
| 91 | return volume |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 92 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 93 | @test.idempotent_id('52e9045a-e90d-4c0d-9087-79d657faffff') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 94 | def test_attach_detach_volume(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 95 | # Stop and Start a server with an attached volume, ensuring that |
| 96 | # the volume remains attached. |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 97 | server = self._create_server() |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 98 | volume = self._create_and_attach_volume(server) |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 99 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 100 | self.servers_client.stop_server(server['id']) |
| 101 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 102 | 'SHUTOFF') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 103 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 104 | self.servers_client.start_server(server['id']) |
| 105 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 106 | 'ACTIVE') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 107 | |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 108 | if CONF.validation.run_validation: |
| 109 | linux_client = remote_client.RemoteClient( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 110 | self.get_server_ip(server), |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 111 | self.image_ssh_user, |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 112 | self.image_ssh_password, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 113 | self.validation_resources['keypair']['private_key'], |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 114 | server=server, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 115 | servers_client=self.servers_client) |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 116 | |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 117 | partitions = linux_client.get_partitions() |
Emily Hugenbruch | fe757e3 | 2016-09-02 15:10:52 -0400 | [diff] [blame] | 118 | device_name_to_match = ' ' + self.device + '\n' |
| 119 | self.assertIn(device_name_to_match, partitions) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 120 | |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 121 | self._detach(server['id'], volume['id']) |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 122 | self.attachment = None |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 123 | self.servers_client.stop_server(server['id']) |
| 124 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 125 | 'SHUTOFF') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 126 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 127 | self.servers_client.start_server(server['id']) |
| 128 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 129 | 'ACTIVE') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 130 | |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 131 | if CONF.validation.run_validation: |
| 132 | linux_client = remote_client.RemoteClient( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 133 | self.get_server_ip(server), |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 134 | self.image_ssh_user, |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 135 | self.image_ssh_password, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 136 | self.validation_resources['keypair']['private_key'], |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 137 | server=server, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 138 | servers_client=self.servers_client) |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 139 | |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 140 | partitions = linux_client.get_partitions() |
Emily Hugenbruch | fe757e3 | 2016-09-02 15:10:52 -0400 | [diff] [blame] | 141 | self.assertNotIn(device_name_to_match, partitions) |
Dan Smith | 1ced842 | 2012-08-16 10:35:19 -0700 | [diff] [blame] | 142 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 143 | @test.idempotent_id('7fa563fe-f0f7-43eb-9e22-a1ece036b513') |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 144 | def test_list_get_volume_attachments(self): |
| 145 | # Create Server, Volume and attach that Volume to Server |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 146 | server = self._create_server() |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 147 | volume = self._create_and_attach_volume(server) |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 148 | |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 149 | # List Volume attachment of the server |
David Kranz | 3ebc721 | 2015-02-10 12:19:19 -0500 | [diff] [blame] | 150 | body = self.servers_client.list_volume_attachments( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 151 | server['id'])['volumeAttachments'] |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 152 | self.assertEqual(1, len(body)) |
| 153 | self.assertIn(self.attachment, body) |
| 154 | |
| 155 | # Get Volume attachment of the server |
Ken'ichi Ohmichi | 277d188 | 2015-11-20 00:44:06 +0000 | [diff] [blame] | 156 | body = self.servers_client.show_volume_attachment( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 157 | server['id'], |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 158 | self.attachment['id'])['volumeAttachment'] |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 159 | self.assertEqual(server['id'], body['serverId']) |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 160 | self.assertEqual(volume['id'], body['volumeId']) |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 161 | self.assertEqual(self.attachment['id'], body['id']) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 162 | |
| 163 | |
| 164 | class AttachVolumeShelveTestJSON(AttachVolumeTestJSON): |
| 165 | """Testing volume with shelved instance. |
| 166 | |
| 167 | This test checks the attaching and detaching volumes from |
| 168 | a shelved or shelved ofload instance. |
| 169 | """ |
| 170 | |
| 171 | min_microversion = '2.20' |
| 172 | max_microversion = 'latest' |
| 173 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 174 | def _count_volumes(self, server): |
| 175 | # Count number of volumes on an instance |
| 176 | volumes = 0 |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 177 | if CONF.validation.run_validation: |
| 178 | linux_client = remote_client.RemoteClient( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 179 | self.get_server_ip(server), |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 180 | self.image_ssh_user, |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 181 | self.image_ssh_password, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 182 | self.validation_resources['keypair']['private_key'], |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 183 | server=server, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 184 | servers_client=self.servers_client) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 185 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 186 | command = 'grep -c -E [vs]d.$ /proc/partitions' |
| 187 | volumes = int(linux_client.exec_command(command).strip()) |
| 188 | return volumes |
| 189 | |
| 190 | def _shelve_server(self, server): |
| 191 | # NOTE(andreaf) If we are going to shelve a server, we should |
| 192 | # check first whether the server is ssh-able. Otherwise we |
| 193 | # won't be able to distinguish failures introduced by shelve |
| 194 | # from pre-existing ones. Also it's good to wait for cloud-init |
| 195 | # to be done and sshd server to be running before shelving to |
| 196 | # avoid breaking the VM |
| 197 | if CONF.validation.run_validation: |
| 198 | linux_client = remote_client.RemoteClient( |
| 199 | self.get_server_ip(server), |
| 200 | self.image_ssh_user, |
| 201 | self.image_ssh_password, |
| 202 | self.validation_resources['keypair']['private_key'], |
| 203 | server=server, |
| 204 | servers_client=self.servers_client) |
| 205 | linux_client.validate_authentication() |
| 206 | |
| 207 | # If validation went ok, or it was skipped, shelve the server |
| 208 | compute.shelve_server(self.servers_client, server['id']) |
| 209 | |
| 210 | def _unshelve_server_and_check_volumes(self, server, number_of_volumes): |
| 211 | # Unshelve the instance and check that there are expected volumes |
| 212 | self.servers_client.unshelve_server(server['id']) |
| 213 | waiters.wait_for_server_status(self.servers_client, |
| 214 | server['id'], |
| 215 | 'ACTIVE') |
| 216 | if CONF.validation.run_validation: |
| 217 | counted_volumes = self._count_volumes(server) |
| 218 | self.assertEqual(number_of_volumes, counted_volumes) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 219 | |
| 220 | @test.idempotent_id('13a940b6-3474-4c3c-b03f-29b89112bfee') |
| 221 | @testtools.skipUnless(CONF.compute_feature_enabled.shelve, |
| 222 | 'Shelve is not available.') |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 223 | def test_attach_volume_shelved_or_offload_server(self): |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 224 | # Create server, count number of volumes on it, shelve |
| 225 | # server and attach pre-created volume to shelved server |
| 226 | server = self._create_server() |
| 227 | num_vol = self._count_volumes(server) |
| 228 | self._shelve_server(server) |
| 229 | self._create_and_attach_volume(server) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 230 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 231 | # Unshelve the instance and check that attached volume exists |
| 232 | self._unshelve_server_and_check_volumes(server, num_vol + 1) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 233 | |
| 234 | # Get Volume attachment of the server |
| 235 | volume_attachment = self.servers_client.show_volume_attachment( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 236 | server['id'], |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 237 | self.attachment['id'])['volumeAttachment'] |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 238 | self.assertEqual(server['id'], volume_attachment['serverId']) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 239 | self.assertEqual(self.attachment['id'], volume_attachment['id']) |
| 240 | # Check the mountpoint is not None after unshelve server even in |
| 241 | # case of shelved_offloaded. |
| 242 | self.assertIsNotNone(volume_attachment['device']) |
| 243 | |
| 244 | @test.idempotent_id('b54e86dd-a070-49c4-9c07-59ae6dae15aa') |
| 245 | @testtools.skipUnless(CONF.compute_feature_enabled.shelve, |
| 246 | 'Shelve is not available.') |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 247 | def test_detach_volume_shelved_or_offload_server(self): |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 248 | # Create server, count number of volumes on it, shelve |
| 249 | # server and attach pre-created volume to shelved server |
| 250 | server = self._create_server() |
| 251 | num_vol = self._count_volumes(server) |
| 252 | self._shelve_server(server) |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 253 | volume = self._create_and_attach_volume(server) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 254 | |
| 255 | # Detach the volume |
Anna Babich | 506efe2 | 2016-09-08 18:14:22 +0300 | [diff] [blame] | 256 | self._detach(server['id'], volume['id']) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 257 | self.attachment = None |
| 258 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 259 | # Unshelve the instance and check that we have the expected number of |
| 260 | # volume(s) |
| 261 | self._unshelve_server_and_check_volumes(server, num_vol) |