Search in sources :

Example 16 with EngineMessage

use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.

the class DiskImagesValidator method diskImagesSnapshotsAttachedToVm.

public ValidationResult diskImagesSnapshotsAttachedToVm(Guid vmId) {
    LinkedList<String> diskSnapshotInfo = new LinkedList<>();
    VM vm = getVmDao().get(vmId);
    for (DiskImage diskImage : diskImages) {
        List<VmDevice> devices = getVmDeviceDao().getVmDevicesByDeviceId(diskImage.getId(), vmId);
        if (devices.isEmpty()) {
            // The specified disk image does not belong to the vm
            Snapshot snapshot = getSnapshotDao().get(diskImage.getSnapshotId());
            Disk disk = getDbFacade().getDiskDao().get(diskImage.getId());
            diskSnapshotInfo.add(String.format("%s ,%s", disk.getDiskAlias(), snapshot.getDescription()));
        }
    }
    if (!diskSnapshotInfo.isEmpty()) {
        EngineMessage message = EngineMessage.ACTION_TYPE_FAILED_VM_DISK_SNAPSHOT_NOT_ATTACHED_TO_VM;
        return new ValidationResult(message, String.format("$disksInfo %s", String.format(StringUtils.join(diskSnapshotInfo, "%n"))), String.format("$vmName %s", vm.getName()));
    }
    return ValidationResult.VALID;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LinkedList(java.util.LinkedList) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 17 with EngineMessage

use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.

the class UpdateStorageDomainCommandTest method validateFailsUnSupportedVersionForDiscardAfterDelete.

@Test
public void validateFailsUnSupportedVersionForDiscardAfterDelete() {
    EngineMessage message = EngineMessage.ACTION_TYPE_FAILED_DISCARD_AFTER_DELETE_NOT_SUPPORTED_BY_DC_VERSION;
    when(storageDomainValidator.isDiscardAfterDeleteSupportedByDcVersion(any())).thenReturn(new ValidationResult(message));
    ValidateTestUtils.runAndAssertValidateFailure(cmd, message);
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 18 with EngineMessage

use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.

the class UpdateStorageDomainCommandTest method validateFailsIllegalDiscardAfterDelete.

@Test
public void validateFailsIllegalDiscardAfterDelete() {
    EngineMessage message = EngineMessage.ACTION_TYPE_FAILED_DISCARD_AFTER_DELETE_NOT_SUPPORTED_BY_UNDERLYING_STORAGE;
    when(storageDomainValidator.isDiscardAfterDeleteLegalForExistingStorageDomain()).thenReturn(new ValidationResult(message));
    ValidateTestUtils.runAndAssertValidateFailure(cmd, message);
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 19 with EngineMessage

use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.

the class VmInitToOpenStackMetadataAdapter method validate.

public List<EngineMessage> validate(VmInit vmInit) {
    if (vmInit == null || vmInit.getNetworks() == null) {
        return null;
    }
    List<EngineMessage> msgs = new LinkedList<>();
    List<VmInitNetwork> vmInitNetworks = vmInit.getNetworks();
    for (VmInitNetwork vmInitNetwork : vmInitNetworks) {
        if (!isStartOnBoot(vmInitNetwork)) {
            msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_START_ON_BOOT_INVALID);
        }
        if (isStaticIPv4AndAddressMissing(vmInitNetwork)) {
            msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_STATIC_IPV4_ADDRESS_MISSING);
        }
        if (isStaticIPv6AndAddressMissing(vmInitNetwork)) {
            msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_STATIC_IPV6_ADDRESS_MISSING);
        }
        if (isAutoConfIPv6(vmInitNetwork)) {
            msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_IPV6_AUTOCONF_UNSUPPORTED);
        }
    }
    return msgs;
}
Also used : VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) LinkedList(java.util.LinkedList)

Example 20 with EngineMessage

use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.

the class HostSetupNetworksValidator method validateNotRemovingUsedNetworkByVms.

@SuppressWarnings("unchecked")
ValidationResult validateNotRemovingUsedNetworkByVms(String removedNetworkName) {
    final List<String> removedNetworkNames = Collections.singletonList(removedNetworkName);
    final List<String> vmsNames = findActiveVmsUsingNetwork.findNamesOfActiveVmsUsingNetworks(host.getId(), removedNetworkNames);
    if (vmsNames.isEmpty()) {
        return ValidationResult.VALID;
    }
    EngineMessage engineMessage = EngineMessage.NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS;
    return new ValidationResult(engineMessage, Stream.concat(ReplacementUtils.replaceWith(VAR_NETWORK_NAME, removedNetworkNames, SEPARATOR).stream(), ReplacementUtils.replaceWith(VAR_VM_NAMES, vmsNames, SEPARATOR).stream()).collect(Collectors.toList()));
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Aggregations

EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)69 Test (org.junit.Test)31 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)27 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)17 Network (org.ovirt.engine.core.common.businessentities.network.Network)16 Guid (org.ovirt.engine.core.compat.Guid)16 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)14 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)13 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Map (java.util.Map)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)6 VM (org.ovirt.engine.core.common.businessentities.VM)6 Version (org.ovirt.engine.core.compat.Version)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Collectors (java.util.stream.Collectors)3 VmWatchdogValidator (org.ovirt.engine.core.bll.validator.VmWatchdogValidator)3 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)3