From 1a2b742fe9fe5f37e8b68b9b63ab3bb332a6af31 Mon Sep 17 00:00:00 2001 From: "wei.ying" Date: Fri, 17 Nov 2017 12:03:56 +0800 Subject: [PATCH] Fix incorrect volume type value in ng images create volume form The value of the 'volume_type' is determined by the 'volumeType' object [1]. The value of the 'volume_type' changes only the 'volumeType' object changes. However, the current value of the 'volume_type' is changed according to the volume object change [2]. It will cause a phenomenon, when the page is initialized, the value of 'volume_type' is empty, when we switch volume types drop-down box, its value is also empty, only change the name, description, size and availability zone, the value of 'volume_type' is the page selection. [1] https://github.com/openstack/horizon/blob/master/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.html#L45 [2] https://github.com/openstack/horizon/blob/master/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.js#L140 Change-Id: If754d0c2ced844414c35829d4cefa1fb861522d5 Closes-Bug:#1737900 (cherry picked from commit 3aee4cbac666f080133671790baa9dd42223c996) --- .../create-volume/create-volume.controller.js | 10 +++++----- .../create-volume/create-volume.controller.spec.js | 14 +++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.js b/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.js index 92acbcf009..a0144a48f9 100644 --- a/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.js +++ b/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.js @@ -135,11 +135,11 @@ updateStorageGraph ); - var volumeWatcher = $scope.$watch( + var volumeTypeWatcher = $scope.$watch( function() { - return ctrl.volume; + return ctrl.volumeType; }, - volumeChangeEvent, + updateVolumeType, true ); @@ -222,13 +222,13 @@ return image.name + ' (' + $filter('bytes')(image.size) + ')'; } - function volumeChangeEvent() { + function updateVolumeType() { ctrl.volume.volume_type = ctrl.volumeType.name || ''; } function deregisterWatchers() { capacityWatcher(); - volumeWatcher(); + volumeTypeWatcher(); } } })(); diff --git a/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.spec.js b/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.spec.js index c21678e7c5..ee80ba6c2b 100644 --- a/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.spec.js +++ b/openstack_dashboard/static/app/core/images/steps/create-volume/create-volume.controller.spec.js @@ -272,16 +272,12 @@ expect(graph.maxLimit).toEqual(graph.maxLimit); }); - it('should update volume type from volume name', function() { + it('should update volume type when ctrl.volumeType changes', function() { var ctrl = createController(); - + ctrl.volumeType = {name: 'spam'}; $scope.$apply(); - ctrl.volume.volume_type = 'spam'; - ctrl.volume.name = 'nova2'; - $scope.$apply(); - - expect(ctrl.volume.volume_type).toEqual('lvmdriver-1'); + expect(ctrl.volume.volume_type).toEqual('spam'); }); it('should set the validity of the volume size input field based on the limit', function() { @@ -342,13 +338,13 @@ expect(graph.overMax).toBeFalsy(); }); - it('should deregister the volume watcher when the destroy event is thrown', function() { + it('should deregister the volume type watcher when the destroy event is thrown', function() { var ctrl = createController(); $scope.$emit('$destroy'); $scope.$emit.calls.reset(); - ctrl.volume.size = 100; + ctrl.volumeType = {name: 'spam'}; $scope.$apply(); expect($scope.$emit).not.toHaveBeenCalled();