Paras Babbar | 0d62208 | 2020-10-19 13:06:56 -0400 | [diff] [blame] | 1 | # Copyright 2020 Red Hat Inc. |
| 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 | |
songwenping | 8c3dac1 | 2021-02-22 09:12:37 +0800 | [diff] [blame] | 16 | import io |
Paras Babbar | 0d62208 | 2020-10-19 13:06:56 -0400 | [diff] [blame] | 17 | |
| 18 | from tempest.api.compute import base |
| 19 | from tempest.common import waiters |
| 20 | from tempest import config |
| 21 | from tempest.lib import decorators |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
| 26 | class BaseAttachSCSIVolumeTest(base.BaseV2ComputeAdminTest): |
| 27 | """Base class for the admin volume tests in this module.""" |
| 28 | create_default_network = True |
| 29 | |
| 30 | @classmethod |
| 31 | def skip_checks(cls): |
| 32 | super(BaseAttachSCSIVolumeTest, cls).skip_checks() |
| 33 | if not CONF.service_available.cinder: |
| 34 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 35 | raise cls.skipException(skip_msg) |
| 36 | |
| 37 | @classmethod |
| 38 | def setup_credentials(cls): |
| 39 | cls.prepare_instance_network() |
| 40 | super(BaseAttachSCSIVolumeTest, cls).setup_credentials() |
| 41 | |
| 42 | def _create_image_with_custom_property(self, **kwargs): |
| 43 | """Wrapper utility that returns the custom image. |
| 44 | |
| 45 | Creates a new image by downloading the default image's bits and |
| 46 | uploading them to a new image. Any kwargs are set as image properties |
| 47 | on the new image. |
| 48 | |
| 49 | :param return image_id: The UUID of the newly created image. |
| 50 | """ |
Artom Lifshitz | b0ee03e5 | 2021-12-01 14:04:15 -0500 | [diff] [blame] | 51 | image = self.admin_image_client.show_image(CONF.compute.image_ref) |
| 52 | image_data = self.admin_image_client.show_image_file( |
Paras Babbar | 0d62208 | 2020-10-19 13:06:56 -0400 | [diff] [blame] | 53 | CONF.compute.image_ref).data |
songwenping | 8c3dac1 | 2021-02-22 09:12:37 +0800 | [diff] [blame] | 54 | image_file = io.BytesIO(image_data) |
Paras Babbar | 0d62208 | 2020-10-19 13:06:56 -0400 | [diff] [blame] | 55 | create_dict = { |
| 56 | 'container_format': image['container_format'], |
| 57 | 'disk_format': image['disk_format'], |
| 58 | 'min_disk': image['min_disk'], |
| 59 | 'min_ram': image['min_ram'], |
| 60 | 'visibility': 'public', |
| 61 | } |
| 62 | create_dict.update(kwargs) |
Artom Lifshitz | b0ee03e5 | 2021-12-01 14:04:15 -0500 | [diff] [blame] | 63 | new_image = self.admin_image_client.create_image(**create_dict) |
| 64 | self.addCleanup(self.admin_image_client.wait_for_resource_deletion, |
Ghanshyam Mann | 7d9b50a | 2020-11-26 22:49:10 -0600 | [diff] [blame] | 65 | new_image['id']) |
Artom Lifshitz | b0ee03e5 | 2021-12-01 14:04:15 -0500 | [diff] [blame] | 66 | self.addCleanup(self.admin_image_client.delete_image, new_image['id']) |
| 67 | self.admin_image_client.store_image_file(new_image['id'], image_file) |
Paras Babbar | 0d62208 | 2020-10-19 13:06:56 -0400 | [diff] [blame] | 68 | |
| 69 | return new_image['id'] |
| 70 | |
| 71 | |
| 72 | class AttachSCSIVolumeTestJSON(BaseAttachSCSIVolumeTest): |
| 73 | """Test attaching scsi volume to server""" |
| 74 | |
| 75 | @decorators.idempotent_id('777e468f-17ca-4da4-b93d-b7dbf56c0494') |
| 76 | def test_attach_scsi_disk_with_config_drive(self): |
| 77 | """Test the attach/detach volume with config drive/scsi disk |
| 78 | |
| 79 | Enable the config drive, followed by booting an instance |
| 80 | from an image with meta properties hw_cdrom: scsi and use |
| 81 | virtio-scsi mode with further asserting list volume attachments |
| 82 | in instance after attach and detach of the volume. |
| 83 | """ |
| 84 | custom_img = self._create_image_with_custom_property( |
| 85 | hw_scsi_model='virtio-scsi', |
| 86 | hw_disk_bus='scsi', |
| 87 | hw_cdrom_bus='scsi') |
| 88 | server = self.create_test_server(image_id=custom_img, |
| 89 | config_drive=True, |
| 90 | wait_until='ACTIVE') |
Lee Yarwood | adcddce | 2020-11-26 12:23:16 +0000 | [diff] [blame] | 91 | |
Ghanshyam Mann | 7d9b50a | 2020-11-26 22:49:10 -0600 | [diff] [blame] | 92 | # NOTE(lyarwood): self.create_test_server delete the server |
| 93 | # at class level cleanup so add server cleanup to ensure that |
| 94 | # the instance is deleted first before created image. This |
| 95 | # avoids failures when using the rbd backend is used for both |
| 96 | # Glance and Nova ephemeral storage. Also wait until server is |
| 97 | # deleted otherwise image deletion can start before server is |
| 98 | # deleted. |
| 99 | self.addCleanup(waiters.wait_for_server_termination, |
| 100 | self.servers_client, server['id']) |
| 101 | self.addCleanup(self.servers_client.delete_server, server['id']) |
Lee Yarwood | adcddce | 2020-11-26 12:23:16 +0000 | [diff] [blame] | 102 | |
Paras Babbar | 0d62208 | 2020-10-19 13:06:56 -0400 | [diff] [blame] | 103 | volume = self.create_volume() |
| 104 | attachment = self.attach_volume(server, volume) |
| 105 | waiters.wait_for_volume_resource_status( |
| 106 | self.volumes_client, attachment['volumeId'], 'in-use') |
| 107 | volume_after_attach = self.servers_client.list_volume_attachments( |
| 108 | server['id'])['volumeAttachments'] |
| 109 | self.assertEqual(1, len(volume_after_attach), |
| 110 | "Failed to attach volume") |
| 111 | self.servers_client.detach_volume( |
| 112 | server['id'], attachment['volumeId']) |
| 113 | waiters.wait_for_volume_resource_status( |
| 114 | self.volumes_client, attachment['volumeId'], 'available') |
Balazs Gibizer | 2e515fe | 2020-12-07 15:10:11 +0100 | [diff] [blame] | 115 | waiters.wait_for_volume_attachment_remove_from_server( |
| 116 | self.servers_client, server['id'], attachment['volumeId']) |