Improve Volume selection handling in LI

The code for updating the Volume Size error in the Launch Instance
source step appears to be incorrect. This patch updates and improves the
handling to also bump the current value to the minimum for the chosen
image (rather than just a form field error). Also changed the default to
create a new volume, as it was advised that this is the more common
workflow.

Change-Id: Iecb679d967b2285776278f23018e4151ebb18df2
Closes-Bug: 1568866
This commit is contained in:
Rob Cresswell 2016-04-11 14:38:31 +01:00
parent 8bf69bb0f9
commit 3e65e337ee
5 changed files with 18 additions and 18 deletions

View File

@ -178,7 +178,7 @@
source_type: null, source_type: null,
source: [], source: [],
// REQUIRED for JS logic // REQUIRED for JS logic
vol_create: false, vol_create: true,
// May be null // May be null
vol_device_name: 'vda', vol_device_name: 'vda',
vol_delete_on_instance_delete: false, vol_delete_on_instance_delete: false,

View File

@ -514,7 +514,7 @@
}); });
it('sets volume options appropriately', function() { it('sets volume options appropriately', function() {
expect(model.newInstanceSpec.vol_create).toBe(false); expect(model.newInstanceSpec.vol_create).toBe(true);
expect(model.newInstanceSpec.vol_device_name).toBe('vda'); expect(model.newInstanceSpec.vol_device_name).toBe('vda');
expect(model.newInstanceSpec.vol_delete_on_instance_delete).toBe(false); expect(model.newInstanceSpec.vol_delete_on_instance_delete).toBe(false);
expect(model.newInstanceSpec.vol_size).toBe(1); expect(model.newInstanceSpec.vol_size).toBe(1);

View File

@ -59,7 +59,6 @@
/*eslint-disable max-len */ /*eslint-disable max-len */
ctrl.bootSourceTypeError = gettext('Volumes can only be attached to 1 active instance at a time. Please either set your instance count to 1 or select a different source type.'); ctrl.bootSourceTypeError = gettext('Volumes can only be attached to 1 active instance at a time. Please either set your instance count to 1 or select a different source type.');
/*eslint-enable max-len */ /*eslint-enable max-len */
ctrl.volumeSizeError = gettext('Volume size is required and must be an integer');
// toggle button label/value defaults // toggle button label/value defaults
ctrl.toggleButtonOptions = [ ctrl.toggleButtonOptions = [
@ -399,7 +398,7 @@
function updateBootSourceSelection(selectedSource) { function updateBootSourceSelection(selectedSource) {
ctrl.currentBootSource = selectedSource; ctrl.currentBootSource = selectedSource;
$scope.model.newInstanceSpec.vol_create = false; $scope.model.newInstanceSpec.vol_create = true;
$scope.model.newInstanceSpec.vol_delete_on_instance_delete = false; $scope.model.newInstanceSpec.vol_delete_on_instance_delete = false;
changeBootSource(selectedSource); changeBootSource(selectedSource);
validateBootSourceType(); validateBootSourceType();
@ -465,14 +464,15 @@
var imageGb = source.size * 1e-9; var imageGb = source.size * 1e-9;
var imageDisk = source.min_disk; var imageDisk = source.min_disk;
ctrl.minVolumeSize = Math.ceil(Math.max(imageGb, imageDisk)); ctrl.minVolumeSize = Math.ceil(Math.max(imageGb, imageDisk));
if ($scope.model.newInstanceSpec.vol_size < ctrl.minVolumeSize) {
$scope.model.newInstanceSpec.vol_size = ctrl.minVolumeSize;
}
var volumeSizeText = gettext('The volume size must be at least %(minVolumeSize)s GB'); var volumeSizeText = gettext('The volume size must be at least %(minVolumeSize)s GB');
var volumeSizeObj = { minVolumeSize: ctrl.minVolumeSize }; var volumeSizeObj = { minVolumeSize: ctrl.minVolumeSize };
ctrl.minVolumeSizeError = interpolate(volumeSizeText, volumeSizeObj, true); ctrl.volumeSizeError = interpolate(volumeSizeText, volumeSizeObj, true);
} else { } else {
/*eslint-disable no-undefined */ ctrl.minVolumeSize = 0;
ctrl.minVolumeSize = undefined; ctrl.volumeSizeError = gettext('Volume size is required and must be an integer');
/*eslint-enable no-undefined */
} }
} }

View File

@ -232,7 +232,7 @@
ctrl.updateBootSourceSelection(selSource); ctrl.updateBootSourceSelection(selSource);
expect(ctrl.currentBootSource).toEqual('image'); expect(ctrl.currentBootSource).toEqual('image');
expect(scope.model.newInstanceSpec.vol_create).toBe(false); expect(scope.model.newInstanceSpec.vol_create).toBe(true);
expect(scope.model.newInstanceSpec.vol_delete_on_instance_delete).toBe(false); expect(scope.model.newInstanceSpec.vol_delete_on_instance_delete).toBe(false);
// check table data // check table data
@ -303,14 +303,14 @@
} }
); );
it('should set minVolumeSize to undefined if boot source is not image', function() { it('should set minVolumeSize to 0 if boot source is not image', function() {
var selSource = 'volume'; var selSource = 'volume';
ctrl.updateBootSourceSelection(selSource); ctrl.updateBootSourceSelection(selSource);
expect(ctrl.currentBootSource).toEqual('volume'); expect(ctrl.currentBootSource).toEqual('volume');
scope.$apply(); scope.$apply();
expect(ctrl.minVolumeSize).toBeUndefined(); expect(ctrl.minVolumeSize).toBe(0);
}); });
}); });
}); });

View File

@ -58,17 +58,17 @@
<span class="hz-icon-required fa fa-asterisk"></span> <span class="hz-icon-required fa fa-asterisk"></span>
</label> </label>
<input name="volume-size" <input name="volume-size"
min="0" min="{$ ctrl.minVolumeSize $}"
id="volume-size" id="volume-size"
type="number" type="number"
class="form-control" class="form-control"
ng-model="model.newInstanceSpec.vol_size" ng-model="model.newInstanceSpec.vol_size"
ng-pattern="/^[0-9]+$/" ng-pattern="/^[0-9]+$/"
ng-required="true" ng-required="true">
validate-number-min="{$ ctrl.minVolumeSize $}"> <span class="help-block"
<span class="help-block" ng-show="launchInstanceSourceForm['volume-size'].$invalid"> ng-show="launchInstanceSourceForm['volume-size'].$invalid">
{$ launchInstanceSourceForm['volume-size'].$error.validateNumberMin ? ctrl.minVolumeSizeError : ctrl.volumeSizeError $} {$ launchInstanceSourceForm['volume-size'].$error.validateNumberMin ? ctrl.minVolumeSizeError : ctrl.volumeSizeError $}
</span> </span>
</div> </div>
</div> </div>
</div> </div>