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