From 374d5e5a3037a6b985933e734e902b2e05d805bb Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 28 Jan 2022 18:56:56 +0100 Subject: [PATCH] deploy_utils: only check glance for image properties kernel/ramdisk Other image services cannot have them, not use making a network call. Change-Id: I691ae5b67358ced5f0aa860b9ca6ccec58c897ad --- ironic/drivers/modules/deploy_utils.py | 8 ++---- .../unit/drivers/modules/test_deploy_utils.py | 27 +------------------ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/ironic/drivers/modules/deploy_utils.py b/ironic/drivers/modules/deploy_utils.py index f46250e2af..1aeda7acf5 100644 --- a/ironic/drivers/modules/deploy_utils.py +++ b/ironic/drivers/modules/deploy_utils.py @@ -580,14 +580,10 @@ def validate_image_properties(task, deploy_info): boot_option = get_boot_option(task.node) if boot_option == 'kickstart': properties.append('stage2_id') - else: - properties = ['kernel', 'ramdisk'] - - if image_href: image_props = get_image_properties(task.context, image_href) else: - # Ramdisk deploy, no image_source is present - image_props = [] + properties = ['kernel', 'ramdisk'] + image_props = {} missing_props = [] for prop in properties: diff --git a/ironic/tests/unit/drivers/modules/test_deploy_utils.py b/ironic/tests/unit/drivers/modules/test_deploy_utils.py index bfa662fa8a..c3ef5e2043 100644 --- a/ironic/tests/unit/drivers/modules/test_deploy_utils.py +++ b/ironic/tests/unit/drivers/modules/test_deploy_utils.py @@ -1432,41 +1432,16 @@ class ValidateImagePropertiesTestCase(db_base.DbTestCase): utils.validate_image_properties, self.task, inst_info) - @mock.patch.object(image_service.HttpImageService, 'show', autospec=True) - def test_validate_image_properties_nonglance_image( - self, image_service_show_mock): + def test_validate_image_properties_nonglance_image(self): instance_info = { 'image_source': 'http://ubuntu', 'kernel': 'kernel_uuid', 'ramdisk': 'file://initrd', 'root_gb': 100, } - image_service_show_mock.return_value = {'size': 1, 'properties': {}} self.node.instance_info = instance_info inst_info = utils.get_image_instance_info(self.node) utils.validate_image_properties(self.task, inst_info) - image_service_show_mock.assert_called_once_with( - mock.ANY, instance_info['image_source']) - - @mock.patch.object(image_service.HttpImageService, 'show', autospec=True) - def test_validate_image_properties_nonglance_image_validation_fail( - self, img_service_show_mock): - instance_info = { - 'image_source': 'http://ubuntu', - 'kernel': 'kernel_uuid', - 'ramdisk': 'file://initrd', - 'root_gb': 100, - } - img_service_show_mock.side_effect = exception.ImageRefValidationFailed( - image_href='http://ubuntu', reason='HTTPError') - self.node.instance_info = instance_info - inst_info = utils.get_image_instance_info(self.node) - expected_error = ('Validation of image href http://ubuntu ' - 'failed, reason: HTTPError') - error = self.assertRaises(exception.InvalidParameterValue, - utils.validate_image_properties, - self.task, inst_info) - self.assertEqual(expected_error, str(error)) def test_validate_image_properties_boot_iso_conflict(self): instance_info = {