CLOUDSTACK-2916: admin is not able to login through UI after setting GP "cluster.cpu.allocated.capacity.notificationthreshold" to some string

CLOUDSTACK-2457:  No check for input values,special character,-ive values can be assigne to GLobal parameter "cluster.cpu.allocated.capacity.disablethreshold"

Added validation for float values and checking limit for weight based parameters by creating a set of parameters.
Signed off by : nitin mehta<nitin.mehta@citrix.com>
This commit is contained in:
Harikrishna Patnala 2013-06-24 19:57:29 +05:30 committed by Nitin Mehta
parent da0006618f
commit f7b1d3d8d5
2 changed files with 46 additions and 3 deletions

View File

@ -324,6 +324,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
private int _maxVolumeSizeInGb = Integer.parseInt(Config.MaxVolumeSize.getDefaultValue());
private long _defaultPageSize = Long.parseLong(Config.DefaultPageSize.getDefaultValue());
protected Set<String> configValuesForValidation;
private Set<String> weightBasedParametersForValidation;
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
@ -336,6 +337,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
Long.parseLong(Config.DefaultPageSize.getDefaultValue()));
populateConfigValuesForValidationSet();
weightBasedParametersForValidation();
return true;
}
@ -361,6 +363,28 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
configValuesForValidation.add("incorrect.login.attempts.allowed");
}
private void weightBasedParametersForValidation() {
weightBasedParametersForValidation = new HashSet<String>();
weightBasedParametersForValidation.add(Config.CPUCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.StorageAllocatedCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.StorageCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.MemoryCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.PublicIpCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.PrivateIpCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.SecondaryStorageCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.VlanCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.DirectNetworkPublicIpCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.LocalStorageCapacityThreshold.key());
weightBasedParametersForValidation.add(Config.StorageAllocatedCapacityDisableThreshold.key());
weightBasedParametersForValidation.add(Config.StorageCapacityDisableThreshold.key());
weightBasedParametersForValidation.add(Config.CPUCapacityDisableThreshold.key());
weightBasedParametersForValidation.add(Config.MemoryCapacityDisableThreshold.key());
weightBasedParametersForValidation.add(Config.AgentLoadThreshold.key());
weightBasedParametersForValidation.add(Config.VmUserDispersionWeight.key());
}
@Override
public boolean start() {
@ -733,6 +757,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
if (type.equals(Float.class)) {
try {
Float val = Float.parseFloat(value);
if (weightBasedParametersForValidation.contains(name) && (val < 0f || val > 1f)) {
throw new InvalidParameterValueException("Please enter a value between 0 and 1 for the configuration parameter: "+ name);
}
} catch (NumberFormatException e) {
s_logger.error("There was an error trying to parse the float value for:" + name);
throw new InvalidParameterValueException("There was an error trying to parse the float value for:" + name);
}
}
String range = c.getRange();
if (range == null) {
return null;

View File

@ -142,7 +142,7 @@ class TestScaleVm(cloudstackTestCase):
#how does it work ??
cls._cleanup = [
cls.small_offering,
cls.account
#cls.account
]
@classmethod
@ -170,9 +170,10 @@ class TestScaleVm(cloudstackTestCase):
self.debug("Scaling VM-ID: %s to service offering: %s" % (
self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % (
self.virtual_machine.id,
self.big_offering.id
self.big_offering.id,
self.virtual_machine.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
@ -204,6 +205,12 @@ class TestScaleVm(cloudstackTestCase):
"Check virtual machine ID of scaled VM"
)
self.debug("Scaling VM-ID: %s from service offering: %s to new service offering %s and the response says %s" % (
self.virtual_machine.id,
self.virtual_machine.serviceofferingid,
self.big_offering.id,
vm_response.serviceofferingid
))
self.assertEqual(
vm_response.serviceofferingid,
self.big_offering.id,