Merge "Set minimum volume size based on the flavor selected"

This commit is contained in:
Jenkins 2017-05-04 20:25:07 +00:00 committed by Gerrit Code Review
commit b76df4315c
2 changed files with 28 additions and 3 deletions
openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source

@ -401,6 +401,18 @@
}
);
var flavorWatcher = $scope.$watchCollection(function () {
return $scope.model.newInstanceSpec.flavor;
}, function setVolumeSize() {
// Set the volume size if a flavor is selected and it requires
// more disk space than what the user specified.
var newInstanceSpec = $scope.model.newInstanceSpec;
var flavor = newInstanceSpec.flavor;
if (flavor && (newInstanceSpec.vol_size < flavor.disk)) {
newInstanceSpec.vol_size = flavor.disk;
}
});
// Explicitly remove watchers on destruction of this controller
$scope.$on('$destroy', function() {
allowedBootSourcesWatcher();
@ -411,6 +423,7 @@
imageSnapshotsWatcher();
volumeWatcher();
snapshotWatcher();
flavorWatcher();
});
////////////////////

@ -223,19 +223,31 @@
scope.model.allowedBootSources = [{type: 'test_type', label: 'test'}];
scope.$apply();
});
it("establishes eight watches", function () {
it("establishes nine watches", function () {
// Count calls to $watch (note: $watchCollection
// also calls $watch)
expect(scope.$watch.calls.count()).toBe(8);
expect(scope.$watch.calls.count()).toBe(9);
});
it("establishes five watch collections", function () {
expect(scope.$watchCollection.calls.count()).toBe(5);
expect(scope.$watchCollection.calls.count()).toBe(6);
});
it('should set source type on new allowedbootsources', function() {
expect(angular.equals(scope.model.newInstanceSpec.source_type,
{type: 'test_type', label: 'test'})).toBe(true);
expect(ctrl.currentBootSource).toBe('test_type');
});
it('should set the minimum volume size', function () {
scope.model.newInstanceSpec.flavor = {name: 'small', disk: 20};
scope.model.newInstanceSpec.vol_size = 5;
scope.$apply();
expect(scope.model.newInstanceSpec.vol_size).toBe(20);
});
it('should not change the volume size', function () {
scope.model.newInstanceSpec.flavor = {name: 'tiny', disk: 1};
scope.model.newInstanceSpec.vol_size = 5;
scope.$apply();
expect(scope.model.newInstanceSpec.vol_size).toBe(5);
});
});
describe('updateBootSourceSelection', function() {