Select correct boot source when launching instance from different sources

When launching instance from snapshot, volume or volume snapshot,
the selected boot source was always image.
This was due to a reset to image boot source when receiving "change allowed boot
sources" event.
From now:
 - The "change allowed boot source" event does not flush a preselection
if the preselection boot source type is in the allowed sources.
 - Set the bootsource with preselection update correctly the form for each
different type of boot source.

Change-Id: I6907652731fa89b303d997fe2e3c331a68f085b6
Closes-bug: #1608565
This commit is contained in:
David Gutman 2018-09-06 11:33:09 +02:00
parent 0afe450101
commit 87f5e21b03
2 changed files with 40 additions and 13 deletions

View File

@ -404,14 +404,21 @@
// When the allowedboot list changes, change the source_type
// and update the table for the new source selection. Only done
// with the first item for the list
// The boot source is changed only if the selected value is not included
// in the updated list (newValue)
var allowedBootSourcesWatcher = $scope.$watchCollection(
function getAllowedBootSources() {
return $scope.model.allowedBootSources;
},
function changeBootSource(newValue) {
if (angular.isArray(newValue) && newValue.length > 0) {
updateBootSourceSelection(newValue[0].type);
$scope.model.newInstanceSpec.source_type = newValue[0];
if (angular.isArray(newValue) && newValue.length > 0 ) {
if (!$scope.model.newInstanceSpec.source_type ||
newValue.filter(function(value) {
return value.type === $scope.model.newInstanceSpec.source_type.type;
}).length === 0) {
updateBootSourceSelection(newValue[0].type);
$scope.model.newInstanceSpec.source_type = newValue[0];
}
}
}
);
@ -443,7 +450,7 @@
////////////////////
function updateBootSourceSelection(selectedSource) {
function updateBootSourceSelection(selectedSource, preSelection) {
if (ctrl.currentBootSource !== selectedSource) {
ctrl.selection.length = 0;
ctrl.currentBootSource = selectedSource;
@ -456,7 +463,7 @@
$scope.model.newInstanceSpec.vol_create = false;
}
$scope.model.newInstanceSpec.vol_delete_on_instance_delete = false;
changeBootSource(selectedSource);
changeBootSource(selectedSource, preSelection);
validateBootSourceType();
}
@ -564,48 +571,44 @@
function setSourceImageWithId(id) {
var pre = findSourceById($scope.model.images, id);
if (pre) {
changeBootSource(bootSourceTypes.IMAGE, [pre]);
updateBootSourceSelection(bootSourceTypes.IMAGE, [pre]);
$scope.model.newInstanceSpec.source_type = {
type: bootSourceTypes.IMAGE,
label: gettext('Image')
};
ctrl.currentBootSource = bootSourceTypes.IMAGE;
}
}
function setSourceImageSnapshotWithId(id) {
var pre = findSourceById($scope.model.imageSnapshots, id);
if (pre) {
changeBootSource(bootSourceTypes.INSTANCE_SNAPSHOT, [pre]);
updateBootSourceSelection(bootSourceTypes.INSTANCE_SNAPSHOT, [pre]);
$scope.model.newInstanceSpec.source_type = {
type: bootSourceTypes.INSTANCE_SNAPSHOT,
label: gettext('Snapshot')
};
ctrl.currentBootSource = bootSourceTypes.INSTANCE_SNAPSHOT;
}
}
function setSourceVolumeWithId(id) {
var pre = findSourceById($scope.model.volumes, id);
if (pre) {
changeBootSource(bootSourceTypes.VOLUME, [pre]);
updateBootSourceSelection(bootSourceTypes.VOLUME, [pre]);
$scope.model.newInstanceSpec.source_type = {
type: bootSourceTypes.VOLUME,
label: gettext('Volume')
};
ctrl.currentBootSource = bootSourceTypes.VOLUME;
}
}
function setSourceSnapshotWithId(id) {
var pre = findSourceById($scope.model.volumeSnapshots, id);
if (pre) {
changeBootSource(bootSourceTypes.VOLUME_SNAPSHOT, [pre]);
updateBootSourceSelection(bootSourceTypes.VOLUME_SNAPSHOT, [pre]);
$scope.model.newInstanceSpec.source_type = {
type: bootSourceTypes.VOLUME_SNAPSHOT,
label: gettext('Snapshot')
};
ctrl.currentBootSource = bootSourceTypes.VOLUME_SNAPSHOT;
}
}
}

View File

@ -121,6 +121,30 @@
expect(ctrl.currentBootSource).toBe('image');
});
it('defaults source should not be flushed when allowed boot sources change if it ' +
'is included in them',
function() {
scope.launchContext = { imageId: 'imageSnapshot-1' };
deferred.resolve();
$browser.defer.flush();
// The boot source is set
expect(scope.model.newInstanceSpec.source_type.type).toBe('snapshot');
expect(ctrl.currentBootSource).toBe('snapshot');
// Change the allowed boot sources
scope.model.allowedBootSources = [{type: 'image', label: 'Image'},
{type: 'snapshot', label: 'Snapshot'}];
scope.$apply();
// The boot source has not been flushed
expect(scope.model.newInstanceSpec.source_type.type).toBe('snapshot');
expect(ctrl.currentBootSource).toBe('snapshot');
}
);
describe('facets', function() {
it('should set facets for search by default', function() {
expect(ctrl.sourceFacets).toBeDefined();