summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Coutellier <victor.coutellier@gmail.com>2022-10-19 21:17:07 +0200
committerVictor Coutellier <victor.coutellier@gmail.com>2022-10-20 10:33:28 +0200
commit01afd1ba70c207932a6574c9ab13036d40abe3fe (patch)
tree0085dc7201fdd5cfa4bd7fb8de949629f6e4154e
parent28349ee91bb5443224281b4b02dac30922184aff (diff)
downloadhorizon-01afd1ba70c207932a6574c9ab13036d40abe3fe.tar.gz
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
-rw-r--r--openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.js15
-rw-r--r--openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.spec.js5
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 26086bc14..c38d75bc4 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 fa15af910..27a580698 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'},
];