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 | |
Steve Noyes | 83a1412 | 2018-01-11 16:12:40 -0500 | [diff] [blame] | 16 | import testtools |
| 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 |
Matt Riedemann | 81fa9b6 | 2016-01-14 13:04:38 -0800 | [diff] [blame] | 20 | from tempest.common import 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 |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 24 | from tempest.lib import decorators |
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 | |
Matt Riedemann | 039740a | 2018-01-02 15:47:40 -0500 | [diff] [blame] | 29 | class BaseAttachVolumeTest(base.BaseV2ComputeTest): |
| 30 | """Base class for the attach volume tests in this module.""" |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 31 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 32 | @classmethod |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 33 | def skip_checks(cls): |
Matt Riedemann | 039740a | 2018-01-02 15:47:40 -0500 | [diff] [blame] | 34 | super(BaseAttachVolumeTest, cls).skip_checks() |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 35 | if not CONF.service_available.cinder: |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 36 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 37 | raise cls.skipException(skip_msg) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 38 | |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 39 | @classmethod |
| 40 | def setup_credentials(cls): |
| 41 | cls.prepare_instance_network() |
Matt Riedemann | 039740a | 2018-01-02 15:47:40 -0500 | [diff] [blame] | 42 | super(BaseAttachVolumeTest, cls).setup_credentials() |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 43 | |
| 44 | @classmethod |
| 45 | def resource_setup(cls): |
Matt Riedemann | 039740a | 2018-01-02 15:47:40 -0500 | [diff] [blame] | 46 | super(BaseAttachVolumeTest, cls).resource_setup() |
Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 47 | cls.device = CONF.compute.volume_device_name |
| 48 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 49 | def _create_server(self): |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 50 | # Start a server and wait for it to become ready |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 51 | validation_resources = self.get_test_validation_resources( |
| 52 | self.os_primary) |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 53 | server = self.create_test_server( |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 54 | validatable=True, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 55 | validation_resources=validation_resources, |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 56 | wait_until='ACTIVE', |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 57 | adminPass=self.image_ssh_password) |
Kevin_Zheng | 7a547df | 2017-04-27 18:00:13 +0800 | [diff] [blame] | 58 | self.addCleanup(self.delete_server, server['id']) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 59 | # Record addresses so that we can ssh later |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 60 | server['addresses'] = self.servers_client.list_addresses( |
| 61 | server['id'])['addresses'] |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 62 | return server, validation_resources |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 63 | |
Matt Riedemann | 039740a | 2018-01-02 15:47:40 -0500 | [diff] [blame] | 64 | |
| 65 | class AttachVolumeTestJSON(BaseAttachVolumeTest): |
| 66 | |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 67 | @decorators.idempotent_id('52e9045a-e90d-4c0d-9087-79d657faffff') |
Matt Riedemann | 9968315 | 2019-02-14 14:35:38 -0500 | [diff] [blame] | 68 | # This test is conditionally marked slow if SSH validation is enabled. |
| 69 | @decorators.attr(type='slow', condition=CONF.validation.run_validation) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 70 | def test_attach_detach_volume(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 71 | # Stop and Start a server with an attached volume, ensuring that |
| 72 | # the volume remains attached. |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 73 | server, validation_resources = self._create_server() |
Andrea Frittoli | cec4494 | 2017-03-24 14:44:19 +0000 | [diff] [blame] | 74 | |
| 75 | # NOTE(andreaf) Create one remote client used throughout the test. |
| 76 | if CONF.validation.run_validation: |
| 77 | linux_client = remote_client.RemoteClient( |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 78 | self.get_server_ip(server, validation_resources), |
Andrea Frittoli | cec4494 | 2017-03-24 14:44:19 +0000 | [diff] [blame] | 79 | self.image_ssh_user, |
| 80 | self.image_ssh_password, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 81 | validation_resources['keypair']['private_key'], |
Andrea Frittoli | cec4494 | 2017-03-24 14:44:19 +0000 | [diff] [blame] | 82 | server=server, |
| 83 | servers_client=self.servers_client) |
| 84 | # NOTE(andreaf) We need to ensure the ssh key has been |
| 85 | # injected in the guest before we power cycle |
| 86 | linux_client.validate_authentication() |
| 87 | |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 88 | volume = self.create_volume() |
zhufl | 2c9d962 | 2018-08-30 16:03:07 +0800 | [diff] [blame] | 89 | |
| 90 | # NOTE: As of the 12.0.0 Liberty release, the Nova libvirt driver |
| 91 | # no longer honors a user-supplied device name, in that case |
| 92 | # CONF.compute.volume_device_name must be set the equal value as |
| 93 | # the libvirt auto-assigned one |
zhufl | 36f0a97 | 2017-02-28 15:43:33 +0800 | [diff] [blame] | 94 | attachment = self.attach_volume(server, volume, |
| 95 | device=('/dev/%s' % self.device)) |
ivan-zhu | 2f54b28 | 2013-03-11 16:39:25 +0800 | [diff] [blame] | 96 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 97 | self.servers_client.stop_server(server['id']) |
| 98 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 99 | 'SHUTOFF') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 100 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 101 | self.servers_client.start_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 | 'ACTIVE') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 104 | |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 105 | if CONF.validation.run_validation: |
Evgeny Antyshev | 4894a91 | 2016-11-21 12:17:18 +0000 | [diff] [blame] | 106 | disks = linux_client.get_disks() |
| 107 | device_name_to_match = '\n' + self.device + ' ' |
| 108 | self.assertIn(device_name_to_match, disks) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 109 | |
zhufl | 36f0a97 | 2017-02-28 15:43:33 +0800 | [diff] [blame] | 110 | self.servers_client.detach_volume(server['id'], attachment['volumeId']) |
| 111 | waiters.wait_for_volume_resource_status( |
| 112 | self.volumes_client, attachment['volumeId'], 'available') |
| 113 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 114 | self.servers_client.stop_server(server['id']) |
| 115 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 116 | 'SHUTOFF') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 117 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 118 | self.servers_client.start_server(server['id']) |
| 119 | waiters.wait_for_server_status(self.servers_client, server['id'], |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 120 | 'ACTIVE') |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 121 | |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 122 | if CONF.validation.run_validation: |
Evgeny Antyshev | 4894a91 | 2016-11-21 12:17:18 +0000 | [diff] [blame] | 123 | disks = linux_client.get_disks() |
| 124 | self.assertNotIn(device_name_to_match, disks) |
Dan Smith | 1ced842 | 2012-08-16 10:35:19 -0700 | [diff] [blame] | 125 | |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 126 | @decorators.idempotent_id('7fa563fe-f0f7-43eb-9e22-a1ece036b513') |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 127 | def test_list_get_volume_attachments(self): |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 128 | # List volume attachment of the server |
afazekas | 5d06623 | 2019-03-25 18:35:36 +0100 | [diff] [blame] | 129 | server, validation_resources = self._create_server() |
zhufl | 16dd62c | 2017-05-03 15:46:16 +0800 | [diff] [blame] | 130 | volume_1st = self.create_volume() |
zhufl | 2c9d962 | 2018-08-30 16:03:07 +0800 | [diff] [blame] | 131 | attachment_1st = self.attach_volume(server, volume_1st) |
David Kranz | 3ebc721 | 2015-02-10 12:19:19 -0500 | [diff] [blame] | 132 | body = self.servers_client.list_volume_attachments( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 133 | server['id'])['volumeAttachments'] |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 134 | self.assertEqual(1, len(body)) |
zhufl | 16dd62c | 2017-05-03 15:46:16 +0800 | [diff] [blame] | 135 | self.assertIn(attachment_1st, body) |
Ghanshyam | 5c2a558 | 2014-04-14 17:16:57 +0900 | [diff] [blame] | 136 | |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 137 | # Get volume attachment of the server |
Ken'ichi Ohmichi | 277d188 | 2015-11-20 00:44:06 +0000 | [diff] [blame] | 138 | body = self.servers_client.show_volume_attachment( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 139 | server['id'], |
zhufl | 16dd62c | 2017-05-03 15:46:16 +0800 | [diff] [blame] | 140 | attachment_1st['id'])['volumeAttachment'] |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 141 | self.assertEqual(server['id'], body['serverId']) |
zhufl | 16dd62c | 2017-05-03 15:46:16 +0800 | [diff] [blame] | 142 | self.assertEqual(volume_1st['id'], body['volumeId']) |
| 143 | self.assertEqual(attachment_1st['id'], body['id']) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 144 | |
zhufl | 16dd62c | 2017-05-03 15:46:16 +0800 | [diff] [blame] | 145 | # attach one more volume to server |
Ken'ichi Ohmichi | 0913928 | 2016-12-01 14:36:22 -0800 | [diff] [blame] | 146 | volume_2nd = self.create_volume() |
zhufl | 36f0a97 | 2017-02-28 15:43:33 +0800 | [diff] [blame] | 147 | attachment_2nd = self.attach_volume(server, volume_2nd) |
Ken'ichi Ohmichi | 0913928 | 2016-12-01 14:36:22 -0800 | [diff] [blame] | 148 | body = self.servers_client.list_volume_attachments( |
| 149 | server['id'])['volumeAttachments'] |
| 150 | self.assertEqual(2, len(body)) |
| 151 | |
afazekas | 5d06623 | 2019-03-25 18:35:36 +0100 | [diff] [blame] | 152 | if CONF.validation.run_validation: |
| 153 | linux_client = remote_client.RemoteClient( |
| 154 | self.get_server_ip(server, validation_resources), |
| 155 | self.image_ssh_user, |
| 156 | self.image_ssh_password, |
| 157 | validation_resources['keypair']['private_key'], |
| 158 | server=server, |
| 159 | servers_client=self.servers_client) |
| 160 | linux_client.validate_authentication() |
| 161 | |
zhufl | 16dd62c | 2017-05-03 15:46:16 +0800 | [diff] [blame] | 162 | for attachment in [attachment_1st, attachment_2nd]: |
| 163 | body = self.servers_client.show_volume_attachment( |
| 164 | server['id'], attachment['id'])['volumeAttachment'] |
| 165 | self.assertEqual(server['id'], body['serverId']) |
| 166 | self.assertEqual(attachment['volumeId'], body['volumeId']) |
| 167 | self.assertEqual(attachment['id'], body['id']) |
Steve Noyes | 5026c50 | 2017-08-10 11:12:31 -0400 | [diff] [blame] | 168 | self.servers_client.detach_volume(server['id'], |
| 169 | attachment['volumeId']) |
| 170 | waiters.wait_for_volume_resource_status( |
| 171 | self.volumes_client, attachment['volumeId'], 'available') |
Ken'ichi Ohmichi | 0913928 | 2016-12-01 14:36:22 -0800 | [diff] [blame] | 172 | |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 173 | |
Matt Riedemann | 039740a | 2018-01-02 15:47:40 -0500 | [diff] [blame] | 174 | class AttachVolumeShelveTestJSON(BaseAttachVolumeTest): |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 175 | """Testing volume with shelved instance. |
| 176 | |
| 177 | This test checks the attaching and detaching volumes from |
Tianbiao Qi | 0d1d24e | 2016-09-28 14:17:12 +0800 | [diff] [blame] | 178 | a shelved or shelved offload instance. |
Matt Riedemann | b572053 | 2018-09-19 16:02:05 -0400 | [diff] [blame] | 179 | |
| 180 | Note that these are uncommon scenarios until blueprint detach-boot-volume |
| 181 | is implemented in the compute service. |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 182 | """ |
| 183 | |
| 184 | min_microversion = '2.20' |
| 185 | max_microversion = 'latest' |
| 186 | |
zhufl | 11289db | 2017-08-29 10:59:39 +0800 | [diff] [blame] | 187 | @classmethod |
| 188 | def skip_checks(cls): |
| 189 | super(AttachVolumeShelveTestJSON, cls).skip_checks() |
| 190 | if not CONF.compute_feature_enabled.shelve: |
| 191 | raise cls.skipException('Shelve is not available.') |
| 192 | |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 193 | def _count_volumes(self, server, validation_resources): |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 194 | # Count number of volumes on an instance |
| 195 | volumes = 0 |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 196 | if CONF.validation.run_validation: |
| 197 | linux_client = remote_client.RemoteClient( |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 198 | self.get_server_ip(server, validation_resources), |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 199 | self.image_ssh_user, |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 200 | self.image_ssh_password, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 201 | validation_resources['keypair']['private_key'], |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 202 | server=server, |
Andrea Frittoli (andreaf) | 3f5aa98 | 2016-07-08 12:10:36 +0100 | [diff] [blame] | 203 | servers_client=self.servers_client) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 204 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 205 | command = 'grep -c -E [vs]d.$ /proc/partitions' |
| 206 | volumes = int(linux_client.exec_command(command).strip()) |
| 207 | return volumes |
| 208 | |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 209 | def _shelve_server(self, server, validation_resources): |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 210 | # NOTE(andreaf) If we are going to shelve a server, we should |
| 211 | # check first whether the server is ssh-able. Otherwise we |
| 212 | # won't be able to distinguish failures introduced by shelve |
| 213 | # from pre-existing ones. Also it's good to wait for cloud-init |
| 214 | # to be done and sshd server to be running before shelving to |
| 215 | # avoid breaking the VM |
| 216 | if CONF.validation.run_validation: |
| 217 | linux_client = remote_client.RemoteClient( |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 218 | self.get_server_ip(server, validation_resources), |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 219 | self.image_ssh_user, |
| 220 | self.image_ssh_password, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 221 | validation_resources['keypair']['private_key'], |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 222 | server=server, |
| 223 | servers_client=self.servers_client) |
| 224 | linux_client.validate_authentication() |
| 225 | |
| 226 | # If validation went ok, or it was skipped, shelve the server |
| 227 | compute.shelve_server(self.servers_client, server['id']) |
| 228 | |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 229 | def _unshelve_server_and_check_volumes(self, server, |
| 230 | validation_resources, |
| 231 | number_of_volumes): |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 232 | # Unshelve the instance and check that there are expected volumes |
| 233 | self.servers_client.unshelve_server(server['id']) |
| 234 | waiters.wait_for_server_status(self.servers_client, |
| 235 | server['id'], |
| 236 | 'ACTIVE') |
| 237 | if CONF.validation.run_validation: |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 238 | counted_volumes = self._count_volumes( |
| 239 | server, validation_resources) |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 240 | self.assertEqual(number_of_volumes, counted_volumes) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 241 | |
Matt Riedemann | b572053 | 2018-09-19 16:02:05 -0400 | [diff] [blame] | 242 | # NOTE(mriedem): Marked as slow since this is an uncommon scenario until |
| 243 | # attach/detach root volume is supported in nova, and it's slow. |
| 244 | @decorators.attr(type='slow') |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 245 | @decorators.idempotent_id('13a940b6-3474-4c3c-b03f-29b89112bfee') |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 246 | def test_attach_volume_shelved_or_offload_server(self): |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 247 | # Create server, count number of volumes on it, shelve |
| 248 | # server and attach pre-created volume to shelved server |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 249 | server, validation_resources = self._create_server() |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 250 | volume = self.create_volume() |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 251 | num_vol = self._count_volumes(server, validation_resources) |
| 252 | self._shelve_server(server, validation_resources) |
zhufl | 2c9d962 | 2018-08-30 16:03:07 +0800 | [diff] [blame] | 253 | attachment = self.attach_volume(server, volume) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 254 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 255 | # Unshelve the instance and check that attached volume exists |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 256 | self._unshelve_server_and_check_volumes( |
| 257 | server, validation_resources, num_vol + 1) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 258 | |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 259 | # Get volume attachment of the server |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 260 | volume_attachment = self.servers_client.show_volume_attachment( |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 261 | server['id'], |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 262 | attachment['id'])['volumeAttachment'] |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 263 | self.assertEqual(server['id'], volume_attachment['serverId']) |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 264 | self.assertEqual(attachment['id'], volume_attachment['id']) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 265 | # Check the mountpoint is not None after unshelve server even in |
| 266 | # case of shelved_offloaded. |
| 267 | self.assertIsNotNone(volume_attachment['device']) |
| 268 | |
Matt Riedemann | b572053 | 2018-09-19 16:02:05 -0400 | [diff] [blame] | 269 | # NOTE(mriedem): Marked as slow since this is an uncommon scenario until |
| 270 | # attach/detach root volume is supported in nova, and it's slow. |
| 271 | @decorators.attr(type='slow') |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 272 | @decorators.idempotent_id('b54e86dd-a070-49c4-9c07-59ae6dae15aa') |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 273 | def test_detach_volume_shelved_or_offload_server(self): |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 274 | # Count number of volumes on instance, shelve |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 275 | # server and attach pre-created volume to shelved server |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 276 | server, validation_resources = self._create_server() |
Benny Kopilov | 5c5f7d8 | 2016-09-13 14:19:53 +0300 | [diff] [blame] | 277 | volume = self.create_volume() |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 278 | num_vol = self._count_volumes(server, validation_resources) |
| 279 | self._shelve_server(server, validation_resources) |
zhufl | 36f0a97 | 2017-02-28 15:43:33 +0800 | [diff] [blame] | 280 | |
| 281 | # Attach and then detach the volume |
zhufl | 2c9d962 | 2018-08-30 16:03:07 +0800 | [diff] [blame] | 282 | self.attach_volume(server, volume) |
zhufl | 36f0a97 | 2017-02-28 15:43:33 +0800 | [diff] [blame] | 283 | self.servers_client.detach_volume(server['id'], volume['id']) |
| 284 | waiters.wait_for_volume_resource_status(self.volumes_client, |
| 285 | volume['id'], 'available') |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 286 | |
Fabian Zimmermann | bbef276 | 2016-06-23 14:05:33 +0200 | [diff] [blame] | 287 | # Unshelve the instance and check that we have the expected number of |
| 288 | # volume(s) |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 289 | self._unshelve_server_and_check_volumes( |
| 290 | server, validation_resources, num_vol) |
Matt Riedemann | 81fa9b6 | 2016-01-14 13:04:38 -0800 | [diff] [blame] | 291 | |
| 292 | |
| 293 | class AttachVolumeMultiAttachTest(BaseAttachVolumeTest): |
| 294 | min_microversion = '2.60' |
| 295 | max_microversion = 'latest' |
| 296 | |
| 297 | @classmethod |
| 298 | def skip_checks(cls): |
| 299 | super(AttachVolumeMultiAttachTest, cls).skip_checks() |
| 300 | if not CONF.compute_feature_enabled.volume_multiattach: |
| 301 | raise cls.skipException('Volume multi-attach is not available.') |
| 302 | |
| 303 | def _attach_volume_to_servers(self, volume, servers): |
| 304 | """Attaches the given volume to the list of servers. |
| 305 | |
| 306 | :param volume: The multiattach volume to use. |
| 307 | :param servers: list of server instances on which the volume will be |
| 308 | attached |
| 309 | :returns: dict of server ID to volumeAttachment dict entries |
| 310 | """ |
| 311 | attachments = {} |
| 312 | for server in servers: |
| 313 | # map the server id to the volume attachment |
| 314 | attachments[server['id']] = self.attach_volume(server, volume) |
| 315 | # NOTE(mriedem): In the case of multi-attach, after the first |
| 316 | # attach the volume will be in-use. On the second attach, nova will |
| 317 | # 'reserve' the volume which puts it back into 'attaching' status |
| 318 | # and then the volume shouldn't go back to in-use until the compute |
| 319 | # actually attaches the server to the volume. |
| 320 | return attachments |
| 321 | |
| 322 | def _detach_multiattach_volume(self, volume_id, server_id): |
| 323 | """Detaches a multiattach volume from the given server. |
| 324 | |
| 325 | Depending on the number of attachments the volume has, this method |
| 326 | will wait for the volume to go to back to 'in-use' status if there are |
| 327 | more attachments or 'available' state if there are no more attachments. |
| 328 | """ |
| 329 | # Count the number of attachments before starting the detach. |
| 330 | volume = self.volumes_client.show_volume(volume_id)['volume'] |
| 331 | attachments = volume['attachments'] |
| 332 | wait_status = 'in-use' if len(attachments) > 1 else 'available' |
| 333 | # Now detach the volume from the given server. |
| 334 | self.servers_client.detach_volume(server_id, volume_id) |
| 335 | # Now wait for the volume status to change. |
| 336 | waiters.wait_for_volume_resource_status( |
| 337 | self.volumes_client, volume_id, wait_status) |
| 338 | |
| 339 | def _create_multiattach_volume(self, bootable=False): |
| 340 | kwargs = {} |
| 341 | if bootable: |
| 342 | kwargs['image_ref'] = CONF.compute.image_ref |
| 343 | return self.create_volume(multiattach=True, **kwargs) |
| 344 | |
| 345 | def _create_and_multiattach(self): |
| 346 | """Creates two server instances and a volume and attaches to both. |
| 347 | |
| 348 | :returns: A three-item tuple of the list of created servers, |
| 349 | the created volume, and dict of server ID to volumeAttachment |
| 350 | dict entries |
| 351 | """ |
| 352 | servers = [] |
| 353 | for x in range(2): |
| 354 | name = 'multiattach-server-%i' % x |
| 355 | servers.append(self.create_test_server(name=name)) |
| 356 | |
| 357 | # Now wait for the servers to be ACTIVE. |
| 358 | for server in servers: |
| 359 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 360 | 'ACTIVE') |
| 361 | |
| 362 | volume = self._create_multiattach_volume() |
| 363 | |
| 364 | # Attach the volume to the servers |
| 365 | attachments = self._attach_volume_to_servers(volume, servers) |
| 366 | return servers, volume, attachments |
| 367 | |
| 368 | @decorators.idempotent_id('8d5853f7-56e7-4988-9b0c-48cea3c7049a') |
| 369 | def test_list_get_volume_attachments_multiattach(self): |
| 370 | # Attach a single volume to two servers. |
| 371 | servers, volume, attachments = self._create_and_multiattach() |
| 372 | |
| 373 | # List attachments from the volume and make sure the server uuids |
| 374 | # are in that list. |
| 375 | vol_attachments = self.volumes_client.show_volume( |
| 376 | volume['id'])['volume']['attachments'] |
| 377 | attached_server_ids = [attachment['server_id'] |
| 378 | for attachment in vol_attachments] |
| 379 | self.assertEqual(2, len(attached_server_ids)) |
| 380 | |
| 381 | # List Volume attachment of the servers |
| 382 | for server in servers: |
| 383 | self.assertIn(server['id'], attached_server_ids) |
| 384 | vol_attachments = self.servers_client.list_volume_attachments( |
| 385 | server['id'])['volumeAttachments'] |
| 386 | self.assertEqual(1, len(vol_attachments)) |
| 387 | attachment = attachments[server['id']] |
| 388 | self.assertDictEqual(attachment, vol_attachments[0]) |
| 389 | # Detach the volume from this server. |
| 390 | self._detach_multiattach_volume(volume['id'], server['id']) |
| 391 | |
| 392 | def _boot_from_multiattach_volume(self): |
| 393 | """Boots a server from a multiattach volume. |
| 394 | |
| 395 | The volume will not be deleted when the server is deleted. |
| 396 | |
| 397 | :returns: 2-item tuple of (server, volume) |
| 398 | """ |
| 399 | volume = self._create_multiattach_volume(bootable=True) |
| 400 | # Now create a server from the bootable volume. |
| 401 | bdm = [{ |
| 402 | 'uuid': volume['id'], |
| 403 | 'source_type': 'volume', |
| 404 | 'destination_type': 'volume', |
| 405 | 'boot_index': 0, |
| 406 | 'delete_on_termination': False}] |
| 407 | server = self.create_test_server( |
| 408 | image_id='', block_device_mapping_v2=bdm, wait_until='ACTIVE') |
| 409 | # Assert the volume is attached to the server. |
| 410 | attachments = self.servers_client.list_volume_attachments( |
| 411 | server['id'])['volumeAttachments'] |
| 412 | self.assertEqual(1, len(attachments)) |
| 413 | self.assertEqual(volume['id'], attachments[0]['volumeId']) |
| 414 | return server, volume |
| 415 | |
| 416 | @decorators.idempotent_id('65e33aa2-185b-44c8-b22e-e524973ed625') |
| 417 | def test_boot_from_multiattach_volume(self): |
| 418 | """Simple test to boot an instance from a multiattach volume.""" |
| 419 | self._boot_from_multiattach_volume() |
| 420 | |
| 421 | @utils.services('image') |
| 422 | @decorators.idempotent_id('885ac48a-2d7a-40c5-ae8b-1993882d724c') |
| 423 | def test_snapshot_volume_backed_multiattach(self): |
| 424 | """Boots a server from a multiattach volume and snapshots the server. |
| 425 | |
| 426 | Creating the snapshot of the server will also create a snapshot of |
| 427 | the volume. |
| 428 | """ |
| 429 | server, volume = self._boot_from_multiattach_volume() |
| 430 | # Create a snapshot of the server (and volume implicitly). |
| 431 | self.create_image_from_server( |
| 432 | server['id'], name='multiattach-snapshot', |
| 433 | wait_until='active', wait_for_server=True) |
| 434 | # TODO(mriedem): Make sure the volume snapshot exists. This requires |
| 435 | # adding the volume snapshots client to BaseV2ComputeTest. |
| 436 | # Delete the server, wait for it to be gone, and make sure the volume |
| 437 | # still exists. |
| 438 | self.servers_client.delete_server(server['id']) |
| 439 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
| 440 | # Delete the volume and cascade the delete of the volume snapshot. |
| 441 | self.volumes_client.delete_volume(volume['id'], cascade=True) |
| 442 | # Now we have to wait for the volume to be gone otherwise the normal |
| 443 | # teardown will fail since it will race with our call and the snapshot |
| 444 | # might still exist. |
| 445 | self.volumes_client.wait_for_resource_deletion(volume['id']) |
| 446 | |
Steve Noyes | 83a1412 | 2018-01-11 16:12:40 -0500 | [diff] [blame] | 447 | @decorators.idempotent_id('f01c7169-a124-4fc7-ae60-5e380e247c9c') |
| 448 | @testtools.skipUnless(CONF.compute_feature_enabled.resize, |
| 449 | 'Resize not available.') |
| 450 | def test_resize_server_with_multiattached_volume(self): |
| 451 | # Attach a single volume to multiple servers, then resize the servers |
| 452 | servers, volume, _ = self._create_and_multiattach() |
| 453 | |
| 454 | for server in servers: |
| 455 | self.resize_server(server['id'], self.flavor_ref_alt) |
| 456 | |
| 457 | for server in servers: |
| 458 | self._detach_multiattach_volume(volume['id'], server['id']) |
| 459 | |
Matt Riedemann | 81fa9b6 | 2016-01-14 13:04:38 -0800 | [diff] [blame] | 460 | # TODO(mriedem): Might be interesting to create a bootable multiattach |
| 461 | # volume with delete_on_termination=True, create server1 from the |
| 462 | # volume, then attach it to server2, and then delete server1 in which |
| 463 | # case the volume won't be deleted because it's still attached to |
| 464 | # server2 and make sure the volume is still attached to server2. |