From 01afd1ba70c207932a6574c9ab13036d40abe3fe Mon Sep 17 00:00:00 2001 From: Victor Coutellier Date: Wed, 19 Oct 2022 21:17:07 +0200 Subject: [PATCH] Handle empty image_type in launch-instance workflow Fix the getImageType function to handle edge case when image_type attribute is present but is an empty string. Closes-Bug: 1993579 Change-Id: Ie08cf1010d64ff927515b4792e9b052a76b6344d --- .../launch-instance-model.service.js | 15 +++++++++------ .../launch-instance-model.service.spec.js | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.js index 26086bc14e..c38d75bc4e 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.js +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.js @@ -676,14 +676,17 @@ } function getImageType(image) { - if (image === null || !angular.isDefined(image.properties) || - !(angular.isDefined(image.properties.image_type) || - angular.isDefined(image.properties.block_device_mapping))) { + if (image === null || !image.properties) { return 'image'; } - return image.properties.image_type || - angular.fromJson(image.properties.block_device_mapping)[0].source_type || - 'image'; + if (image.properties.image_type) { + return image.properties.image_type; + } + var bdm = angular.fromJson(image.properties.block_device_mapping || "[]"); + if (bdm[0] && bdm[0].source_type) { + return bdm[0].source_type; + } + return 'image'; } function isValidImage(image) { diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.spec.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.spec.js index fa15af9100..27a580698c 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.spec.js +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.spec.js @@ -151,6 +151,8 @@ {id: '4', container_format: 'raw', properties: {}, name: 'raw_image'}, {id: '5', container_format: 'ami', properties: {image_type: 'image'}}, {id: '6', container_format: 'raw', properties: {image_type: 'image'}}, + {id: '11', container_format: 'raw', properties: {image_type: ''}}, + {id: '12', container_format: 'raw', properties: {block_device_mapping: '[]'}}, // The following images are considered as "snapshot" sources. {id: '7', container_format: 'ami', properties: {block_device_mapping: '[{"source_type": "snapshot"}]'}}, @@ -393,6 +395,9 @@ name_or_id: 'raw_image'}, {id: '5', container_format: 'ami', properties: {image_type: 'image'}, name_or_id: '5'}, {id: '6', container_format: 'raw', properties: {image_type: 'image'}, name_or_id: '6'}, + {id: '11', container_format: 'raw', properties: {image_type: ''}, name_or_id: '11'}, + {id: '12', container_format: 'raw', properties: {block_device_mapping: '[]'}, + name_or_id: '12'}, {id: '10', container_format: 'raw', properties: {image_type: 'image'}, name_or_id: '10', visibility: 'community'}, ];