From 48862eb9b7f5789dee3362d9103416628c5d3e76 Mon Sep 17 00:00:00 2001 From: kairat_kushaev Date: Fri, 18 Aug 2017 13:30:59 +0400 Subject: [PATCH] do not flush selection on "old" boot source This fixes an issue introduced by watchers: when page initialized images watchers called before select boot source watcher.it leads to sutiation when we specify selection from user input and flush it on updateBootSource. as a result page come to inconsistent state described in the bug. Perhaps, this requires big refactoring but in the current patch we do not flush selection if boot type was not changed. it allows to use image, snapshot, volume from context as ctrl.selection. Change-Id: I4b23071a2a9e2c02cc1f46713165e5cb5155894f Closes-Bug: #1710890 --- .../launch-instance/source/source.controller.js | 7 +++++-- .../source/source.controller.spec.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js index d7a460b2f6..a789b001e4 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js @@ -428,7 +428,10 @@ //////////////////// function updateBootSourceSelection(selectedSource) { - ctrl.currentBootSource = selectedSource; + if (ctrl.currentBootSource !== selectedSource) { + ctrl.selection.length = 0; + ctrl.currentBootSource = selectedSource; + } if ((selectedSource === bootSourceTypes.IMAGE || selectedSource === bootSourceTypes.INSTANCE_SNAPSHOT) && $scope.model.volumeBootable) { $scope.model.newInstanceSpec.vol_create = @@ -451,8 +454,8 @@ } function updateDataSource(key, preSelection) { - selection.length = 0; if (preSelection) { + ctrl.selection.length = 0; push.apply(selection, preSelection); } angular.extend(ctrl.tableData, bootSources[key]); diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js index 79585b0501..3963c233ec 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js @@ -290,6 +290,20 @@ scope.$apply(); expect(scope.$broadcast).toHaveBeenCalled(); }); + it('should not flush selection if boot source still the same', function() { + ctrl.currentBootSource = 'image'; + ctrl.selection = ['test_selection']; + ctrl.updateBootSourceSelection('image'); + scope.$apply(); + expect(ctrl.selection).toEqual(['test_selection']); + }); + it('should flush selection on new boot source', function() { + ctrl.currentBootSource = 'image'; + ctrl.selection = ['test_selection']; + ctrl.updateBootSourceSelection('volume'); + scope.$apply(); + expect(ctrl.selection).toEqual([]); + }); }); describe('source allocation', function() {