From c62c16bd223a8da2262a3dadf1905ef3c2a7c88b Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 28 Jan 2022 19:14:09 +0100 Subject: [PATCH] Support img_type Glance property Follow-up to change I4ce5f7a2317d952f976194d2022328f4afbb0258. Change-Id: I36673c801d426ea9cb204ca52b6fb6f719eb396a Depends-On: https://review.opendev.org/c/openstack/glance/+/826684 --- .../install/configure-glance-images.rst | 40 +++++++++++-------- ironic/common/images.py | 4 ++ ironic/tests/unit/common/test_images.py | 14 +++++++ .../notes/image-type-ac259a90393bdd2c.yaml | 2 + 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/doc/source/install/configure-glance-images.rst b/doc/source/install/configure-glance-images.rst index 361a31a7b0..7c7f2ee57e 100644 --- a/doc/source/install/configure-glance-images.rst +++ b/doc/source/install/configure-glance-images.rst @@ -12,9 +12,30 @@ Add images to the Image service and note the image UUIDs in the Image service for each one as it is generated. - For *partition images*: + - For *whole disk images* just upload the image: - - Add the kernel and ramdisk images to the Image service: + .. code-block:: console + + $ openstack image create my-whole-disk-image --public \ + --disk-format qcow2 --container-format bare \ + --file my-whole-disk-image.qcow2 + + .. warning:: + The kernel/ramdisk pair must not be set for whole disk images, + otherwise they'll be mistaken for partition images. + + - For *partition images* to be used only with *local boot* (the default) + the ``img_type`` property must be set: + + .. code-block:: console + + $ openstack image create my-image --public \ + --disk-format qcow2 --container-format bare \ + --property img_type=partition --file my-image.qcow2 + + - For *partition images* to be used with both *local* and *network* boot: + + Add the kernel and ramdisk images to the Image service: .. code-block:: console @@ -30,7 +51,7 @@ Add images to the Image service Store the image UUID obtained from the above step as ``MY_INITRD_UUID``. - - Add the *my-image* to the Image service which is going to be the OS + Add the *my-image* to the Image service which is going to be the OS that the user is going to run. Also associate the above created images with this OS image. These two operations can be done by executing the following command: @@ -42,19 +63,6 @@ Add images to the Image service kernel_id=$MY_VMLINUZ_UUID --property \ ramdisk_id=$MY_INITRD_UUID --file my-image.qcow2 - For *whole disk images*, skip uploading and configuring kernel and ramdisk - images completely, proceed directly to uploading the main image: - - .. code-block:: console - - $ openstack image create my-whole-disk-image --public \ - --disk-format qcow2 --container-format bare \ - --file my-whole-disk-image.qcow2 - - .. warning:: - The kernel/initramfs pair must not be set for whole disk images, - otherwise they'll be mistaken for partition images. - #. Build or download the deploy images The deploy images are used initially for preparing the server (creating disk diff --git a/ironic/common/images.py b/ironic/common/images.py index 939fcb6767..275989f145 100644 --- a/ironic/common/images.py +++ b/ironic/common/images.py @@ -600,6 +600,10 @@ def is_whole_disk_image(ctx, instance_info): except Exception: return + image_type = iproperties.get('img_type') + if image_type: + return image_type != IMAGE_TYPE_PARTITION + is_whole_disk_image = (not iproperties.get('kernel_id') and not iproperties.get('ramdisk_id')) else: diff --git a/ironic/tests/unit/common/test_images.py b/ironic/tests/unit/common/test_images.py index f699fb7ce6..6170218390 100644 --- a/ironic/tests/unit/common/test_images.py +++ b/ironic/tests/unit/common/test_images.py @@ -242,6 +242,20 @@ class IronicImagesTestCase(base.TestCase): mock_igi.assert_called_once_with(image_source) mock_gip.assert_called_once_with('context', image_source) + @mock.patch.object(images, 'get_image_properties', autospec=True) + @mock.patch.object(glance_utils, 'is_glance_image', autospec=True) + def test_is_whole_disk_image_partition_image_with_type(self, mock_igi, + mock_gip): + mock_igi.return_value = True + mock_gip.return_value = {'img_type': images.IMAGE_TYPE_PARTITION} + instance_info = {'image_source': 'glance://partition_image'} + image_source = instance_info['image_source'] + is_whole_disk_image = images.is_whole_disk_image('context', + instance_info) + self.assertFalse(is_whole_disk_image) + mock_igi.assert_called_once_with(image_source) + mock_gip.assert_called_once_with('context', image_source) + @mock.patch.object(images, 'get_image_properties', autospec=True) @mock.patch.object(glance_utils, 'is_glance_image', autospec=True) def test_is_whole_disk_image_whole_disk_image(self, mock_igi, mock_gip): diff --git a/releasenotes/notes/image-type-ac259a90393bdd2c.yaml b/releasenotes/notes/image-type-ac259a90393bdd2c.yaml index 3d2dfd064f..b693f060ba 100644 --- a/releasenotes/notes/image-type-ac259a90393bdd2c.yaml +++ b/releasenotes/notes/image-type-ac259a90393bdd2c.yaml @@ -7,3 +7,5 @@ features: Adding ``kernel`` and ``ramdisk`` is no longer necessary for partition images if ``image_type`` is set to ``partition`` and local boot is used. + + The corresponding Image service property is called ``img_type``.