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
This commit is contained in:
Victor Coutellier 2022-10-19 21:17:07 +02:00
parent 28349ee91b
commit 01afd1ba70
2 changed files with 14 additions and 6 deletions
openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance

@ -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) {

@ -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'},
];