use of org.ovirt.engine.core.bll.validator.NetworkValidator in project ovirt-engine by oVirt.
the class RemoveProviderValidatorTest method networksUsedTest.
private void networksUsedTest(boolean vmsNotUsingNetwork, boolean templatesNotUsingNetwork, Matcher<ValidationResult> matcher) {
NetworkValidator networkValidator = mock(NetworkValidator.class);
for (Network network : networks) {
when(validator.getValidator(network)).thenReturn(networkValidator);
}
when(networkValidator.networkNotUsedByVms()).thenReturn(createValidationResult(vmsNotUsingNetwork));
when(networkValidator.networkNotUsedByTemplates()).thenReturn(createValidationResult(templatesNotUsingNetwork));
assertThat(validator.providerNetworksNotUsed(), matcher);
}
use of org.ovirt.engine.core.bll.validator.NetworkValidator in project ovirt-engine by oVirt.
the class ImportExternalNetworkCommand method validate.
@Override
protected boolean validate() {
NetworkProviderValidator providerValidator = new NetworkProviderValidator(getProvider());
NetworkValidator networkValidator = new NetworkValidator(null, getNetwork());
return validate(providerValidator.providerIsSet()) && validate(providerValidator.providerTypeIsNetwork()) && validate(providerValidator.validateAuthentication()) && validate(networkValidator.networkIsSet(getParameters().getNetworkExternalId()));
}
use of org.ovirt.engine.core.bll.validator.NetworkValidator in project ovirt-engine by oVirt.
the class UpdateNetworkCommand method validate.
@Override
protected boolean validate() {
if (onlyPermittedFieldsChanged() && allowedNetworkLabelManipulation()) {
return true;
}
final HasStoragePoolValidator hasStoragePoolValidator = new HasStoragePoolValidator(getNetwork());
final NetworkValidator validatorNew = new NetworkValidator(vmDao, getNetwork());
final UpdateNetworkValidator validatorOld = new UpdateNetworkValidator(getOldNetwork(), vmDao, interfaceDao);
return validate(hasStoragePoolValidator.storagePoolExists()) && validate(validatorNew.stpForVmNetworkOnly()) && validate(validatorNew.mtuValid()) && validate(validatorNew.networkPrefixValid()) && validate(validatorNew.qosExistsInDc()) && validate(validatorOld.networkIsSet(getNetwork().getId())) && validate(validatorOld.notChangingDataCenterId(getNetwork().getDataCenterId())) && validate(validatorNew.networkNameNotUsed()) && validate(validatorNew.networkNameNotUsedAsVdsmName()) && validate(validatorOld.nonVmNetworkNotUsedByVms(getNetwork())) && validate(validatorOld.nonVmNetworkNotUsedByTemplates(getNetwork())) && validate(validatorOld.notRenamingUsedNetwork(getNetworkName())) && validate(validatorOld.notRenamingLabel(getNetwork().getLabel())) && (oldAndNewNetworkIsNotExternal() || validate(validatorOld.externalNetworkDetailsUnchanged(getNetwork())));
}
use of org.ovirt.engine.core.bll.validator.NetworkValidator in project ovirt-engine by oVirt.
the class UpdateStoragePoolCommand method validate.
@Override
protected boolean validate() {
StoragePoolValidator spValidator = createStoragePoolValidator();
if (!validate(spValidator.exists())) {
return false;
}
// Name related validations
if (!StringUtils.equals(getOldStoragePool().getName(), getStoragePool().getName()) && !isStoragePoolUnique(getStoragePool().getName())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NAME_ALREADY_EXIST);
}
if (!checkStoragePoolNameLengthValid()) {
return false;
}
List<StorageDomainStatic> poolDomains = storageDomainStaticDao.getAllForStoragePool(getStoragePool().getId());
if (getOldStoragePool().isLocal() && !getStoragePool().isLocal() && poolDomains.stream().anyMatch(sdc -> sdc.getStorageType() == StorageType.LOCALFS)) {
return failValidation(EngineMessage.ERROR_CANNOT_CHANGE_STORAGE_POOL_TYPE_WITH_LOCAL);
}
if (!getOldStoragePool().isLocal() && getStoragePool().isLocal()) {
List<Cluster> clusters = clusterDao.getAllForStoragePool(getStoragePool().getId());
if (clusters.size() > 1) {
return failValidation(EngineMessage.CLUSTER_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE);
}
List<VDS> hosts = vdsDao.getAllForStoragePool(getStoragePool().getId());
if (hosts.size() > 1) {
return failValidation(EngineMessage.VDS_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE);
}
}
if (!getOldStoragePool().getCompatibilityVersion().equals(getStoragePool().getCompatibilityVersion())) {
if (!isStoragePoolVersionSupported()) {
return failValidation(VersionSupport.getUnsupportedVersionMessage());
} else // decreasing of compatibility version is allowed under conditions
if (getStoragePool().getCompatibilityVersion().compareTo(getOldStoragePool().getCompatibilityVersion()) < 0) {
if (!poolDomains.isEmpty() && !isCompatibilityVersionChangeAllowedForDomains(poolDomains)) {
return false;
}
List<Network> networks = networkDao.getAllForDataCenter(getStoragePoolId());
for (Network network : networks) {
NetworkValidator validator = getNetworkValidator(network);
if (!getManagementNetworkUtil().isManagementNetwork(network.getId()) || !validator.canNetworkCompatibilityBeDecreased()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_DATA_CENTER_COMPATIBILITY_VERSION);
}
}
} else if (!checkAllClustersLevel()) {
// Check all clusters has at least the same compatibility version.
return false;
}
}
return validate(spValidator.isNotLocalfsWithDefaultCluster()) && validate(allMacsInEveryClusterCanBeMigratedToAnotherPool());
}
use of org.ovirt.engine.core.bll.validator.NetworkValidator in project ovirt-engine by oVirt.
the class UpdateStoragePoolCommandTest method setupNetworkValidator.
private void setupNetworkValidator(boolean valid) {
NetworkValidator validator = mock(NetworkValidator.class);
when(validator.canNetworkCompatibilityBeDecreased()).thenReturn(valid);
when(cmd.getNetworkValidator(any())).thenReturn(validator);
}
Aggregations