Search in sources :

Example 31 with EngineMessage

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

the class HostSetupNetworksValidatorTest method testInvalidNetworkAttachmentIpConfiguration.

@Test
public void testInvalidNetworkAttachmentIpConfiguration() {
    HostSetupNetworksValidator validator = initValidator();
    NetworkAttachment networkAttachment = validator.getAttachmentsToConfigure().iterator().next();
    Collection<String> replacements = createReplacement(networkAttachment);
    EngineMessage engineMessage = EngineMessage.NETWORK_ATTACHMENT_MISSING_IP_CONFIGURATION;
    initMockNetworkAttachmentIpConfigurationValidator(engineMessage, replacements);
    assertThat(validator.validNewOrModifiedNetworkAttachments(), failsWith(engineMessage, replacements));
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 32 with EngineMessage

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

the class HostSetupNetworksValidatorTest method notMovingLabeledNetworkToDifferentNicCommonTest.

private void notMovingLabeledNetworkToDifferentNicCommonTest(boolean nicContainslabel, boolean labelShouldBeRemovedFromNic, boolean labelShouldBeAddedToNic, boolean valid) {
    VdsNetworkInterface nic = createNic("nicWithLabel");
    if (nicContainslabel) {
        nic.setLabels(Collections.singleton("lbl1"));
    }
    Network movedNetwork = createNetworkWithNameAndLabel("net", "lbl1");
    NetworkAttachment existingAttachment = createNetworkAttachment(movedNetwork, nic);
    NetworkAttachment updatedAttachment = new NetworkAttachment(existingAttachment);
    updatedAttachment.setNicId(Guid.newGuid());
    updatedAttachment.setNicName(nic.getName() + "not");
    HostSetupNetworksParameters params = new HostSetupNetworksParameters(host.getId());
    if (labelShouldBeRemovedFromNic) {
        params.getRemovedLabels().add("lbl1");
    }
    if (labelShouldBeAddedToNic) {
        NicLabel nicLabel = new NicLabel(nic.getId(), nic.getName(), "lbl1");
        params.getLabels().add(nicLabel);
    }
    HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(params).addExistingInterfaces(nic).addExistingAttachments(existingAttachment).addNetworks(movedNetwork).build();
    if (valid) {
        assertThat(validator.notMovingLabeledNetworkToDifferentNic(updatedAttachment), isValid());
    } else {
        EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_MOVE_LABELED_NETWORK_TO_ANOTHER_NIC;
        assertThat(validator.notMovingLabeledNetworkToDifferentNic(updatedAttachment), failsWith(engineMessage, ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, movedNetwork.getName()), ReplacementUtils.getVariableAssignmentString(engineMessage, movedNetwork.getLabel())));
    }
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 33 with EngineMessage

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

the class HostSetupNetworksValidatorTest method testValidModifiedBondsFailsWhenReferencingExistingNonBondInterface.

@Test
public void testValidModifiedBondsFailsWhenReferencingExistingNonBondInterface() throws Exception {
    CreateOrUpdateBond createOrUpdateBond = createNewCreateOrUpdateBondWithNameAndId();
    final EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_IS_NOT_BOND;
    ValidationResult notABondValidationResult = new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, createOrUpdateBond.getName()));
    doTestValidModifiedBonds(createOrUpdateBond, notABondValidationResult, notABondValidationResult, ValidationResult.VALID);
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Test(org.junit.Test)

Example 34 with EngineMessage

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

the class HostSetupNetworksValidatorTest method testValidRemovedBondsWhenReferencedInterfaceBondViaInexistingId.

@Test
public void testValidRemovedBondsWhenReferencedInterfaceBondViaInexistingId() throws Exception {
    Guid idOfInexistingInterface = Guid.newGuid();
    HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedBonds(idOfInexistingInterface)).build();
    EngineMessage engineMessage = EngineMessage.NETWORK_BOND_RECORDS_DOES_NOT_EXISTS;
    assertThat(validator.validRemovedBonds(Collections.emptyList()), failsWith(engineMessage, ReplacementUtils.getListVariableAssignmentString(engineMessage, Collections.singletonList(idOfInexistingInterface))));
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Test(org.junit.Test)

Example 35 with EngineMessage

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

the class MoveMacs method canMigrateMacsToAnotherMacPool.

public ValidationResult canMigrateMacsToAnotherMacPool(ReadMacPool targetPool, List<String> macsToMigrate) {
    if (targetPool.isDuplicateMacAddressesAllowed()) {
        return ValidationResult.VALID;
    }
    Map<String, Long> occurrenceCount = macsToMigrate.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    List<String> problematicMacs = macsToMigrate.stream().distinct().filter(mac -> targetPool.isMacInUse(mac) || occurrenceCount.get(mac) > 1).collect(Collectors.toList());
    EngineMessage engineMessage = ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES;
    Collection<String> replacements = ReplacementUtils.getListVariableAssignmentString(engineMessage, problematicMacs);
    return ValidationResult.failWith(engineMessage, replacements).when(!problematicMacs.isEmpty());
}
Also used : ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES(org.ovirt.engine.core.common.errors.EngineMessage.ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) VmNicDao(org.ovirt.engine.core.dao.network.VmNicDao) Objects(java.util.Objects) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Map(java.util.Map) MacPoolPerCluster(org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster) MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) 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