blob: 487337eee57b73ba1e74e6ac08e1df2d26e57844 [file] [log] [blame]
Paras Babbar0d622082020-10-19 13:06:56 -04001# 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
16import six
17
18from tempest.api.compute import base
19from tempest.common import waiters
20from tempest import config
21from tempest.lib import decorators
22
23CONF = config.CONF
24
25
26class 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 """
51 image = self.image_client.show_image(CONF.compute.image_ref)
52 image_data = self.image_client.show_image_file(
53 CONF.compute.image_ref).data
54 image_file = six.BytesIO(image_data)
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)
63 new_image = self.image_client.create_image(**create_dict)
64 self.addCleanup(self.image_client.delete_image, new_image['id'])
65 self.image_client.store_image_file(new_image['id'], image_file)
66
67 return new_image['id']
68
69
70class AttachSCSIVolumeTestJSON(BaseAttachSCSIVolumeTest):
71 """Test attaching scsi volume to server"""
72
73 @decorators.idempotent_id('777e468f-17ca-4da4-b93d-b7dbf56c0494')
74 def test_attach_scsi_disk_with_config_drive(self):
75 """Test the attach/detach volume with config drive/scsi disk
76
77 Enable the config drive, followed by booting an instance
78 from an image with meta properties hw_cdrom: scsi and use
79 virtio-scsi mode with further asserting list volume attachments
80 in instance after attach and detach of the volume.
81 """
82 custom_img = self._create_image_with_custom_property(
83 hw_scsi_model='virtio-scsi',
84 hw_disk_bus='scsi',
85 hw_cdrom_bus='scsi')
86 server = self.create_test_server(image_id=custom_img,
87 config_drive=True,
88 wait_until='ACTIVE')
89 volume = self.create_volume()
90 attachment = self.attach_volume(server, volume)
91 waiters.wait_for_volume_resource_status(
92 self.volumes_client, attachment['volumeId'], 'in-use')
93 volume_after_attach = self.servers_client.list_volume_attachments(
94 server['id'])['volumeAttachments']
95 self.assertEqual(1, len(volume_after_attach),
96 "Failed to attach volume")
97 self.servers_client.detach_volume(
98 server['id'], attachment['volumeId'])
99 waiters.wait_for_volume_resource_status(
100 self.volumes_client, attachment['volumeId'], 'available')
101 volume_after_detach = self.servers_client.list_volume_attachments(
102 server['id'])['volumeAttachments']
103 self.assertEqual(0, len(volume_after_detach),
104 "Failed to detach volume")