Search in sources :

Example 91 with Network

use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.

the class UnmanagedNetworkValidatorTest method testValidateRemovedUnmanagedNetworks.

@Test
public void testValidateRemovedUnmanagedNetworks() {
    String networkName = "networkName";
    Nic nic = createNicWithNetworkImplementationDetails("eth0", false);
    nic.setNetworkName(networkName);
    Network network = new Network();
    network.setName(networkName);
    ValidationResult result = validator.validateRemovedUnmanagedNetworks(Collections.singletonList(networkName), Collections.singletonList(nic), new BusinessEntityMap<>(Collections.emptySet()));
    assertTrue(result.isValid());
    result = validator.validateRemovedUnmanagedNetworks(Collections.singletonList(networkName), Collections.singletonList(nic), new BusinessEntityMap<>(Collections.singletonList(network)));
    assertThat(result, failsWith(EngineMessage.REMOVED_UNMANAGED_NETWORK_IS_A_CLUSTER_NETWORK, ReplacementUtils.createSetVariableString(NETWORK, networkName)));
    String unmanagedNetworkNotPresentOnAnyNic = "unmanagedNetworkNotPresentOnAnyNic";
    result = validator.validateRemovedUnmanagedNetworks(Arrays.asList(networkName, unmanagedNetworkNotPresentOnAnyNic), Collections.singletonList(nic), new BusinessEntityMap<>(Collections.emptySet()));
    assertThat(result, failsWith(EngineMessage.REMOVED_UNMANAGED_NETWORK_DOES_NOT_EXISIT_ON_HOST, ReplacementUtils.createSetVariableString(NETWORK, unmanagedNetworkNotPresentOnAnyNic)));
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 92 with Network

use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.

the class VfSchedulerImplTest method mockVnic.

private VmNetworkInterface mockVnic(boolean passthrough, String networkName) {
    VmNetworkInterface vnic = mock(VmNetworkInterface.class);
    when(vnic.getId()).thenReturn(Guid.newGuid());
    when(vnic.getName()).thenReturn(getRandomString());
    when(vnic.isPassthrough()).thenReturn(passthrough);
    Network network = createNetwork(networkName);
    when(vnic.getNetworkName()).thenReturn(network.getName());
    when(vnic.isPlugged()).thenReturn(true);
    when(vnic.getVmId()).thenReturn(vmId);
    return vnic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 93 with Network

use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.

the class HostSetupNetworksValidatorTest method testValidateCustomPropertiesWhenCustomPropertyValidationFailed.

@Test
public void testValidateCustomPropertiesWhenCustomPropertyValidationFailed() throws Exception {
    Network networkA = createNetworkWithName("networkA");
    NetworkAttachment networkAttachment = createNetworkAttachment(networkA);
    Map<String, String> customProperties = new HashMap<>();
    customProperties.put("a", "b");
    networkAttachment.setProperties(customProperties);
    HostSetupNetworksValidator validator = spy(new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(networkAttachment)).addNetworks(networkA).build());
    // this was added just because of DI issues with 'Backend.getInstance().getErrorsTranslator()' is 'spyed' method
    // noinspection unchecked
    doReturn(Collections.emptyList()).when(validator).translateErrorMessages(any());
    EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_NETWORK_CUSTOM_PROPERTIES_BAD_INPUT;
    assertThat(validator.validateCustomProperties(SimpleCustomPropertiesUtil.getInstance(), Collections.emptyMap(), Collections.emptyMap()), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentStringWithMultipleValues(engineMessage, networkA.getName())));
}
Also used : HashMap(java.util.HashMap) FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) 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 94 with Network

use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.

the class HostSetupNetworksValidatorTest method validateBondOptionsForNewAttachementWithOutOfSyncVmNetworOverridden.

@Test
public void validateBondOptionsForNewAttachementWithOutOfSyncVmNetworOverridden() {
    NetworkAttachment modifiedAttachment = createNetworkAttachment(new Network());
    HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedNetworkAttachments(modifiedAttachment)).build();
    assertThat(validator.modifiedAttachmentNotRemoved(modifiedAttachment), failsWith(EngineMessage.NETWORK_ATTACHMENT_IN_BOTH_LISTS, ReplacementUtils.createSetVariableString("NETWORK_ATTACHMENT_IN_BOTH_LISTS_ENTITY", modifiedAttachment.getId().toString())));
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 95 with Network

use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.

the class HostSetupNetworksValidatorTest method testNotRemovingLabeledNetworksLabelRemovedFromNicValid.

@Test
public void testNotRemovingLabeledNetworksLabelRemovedFromNicValid() {
    VdsNetworkInterface nicWithLabel = createNic("nicWithLabel");
    final String labelName = "lbl1";
    nicWithLabel.setLabels(Collections.singleton(labelName));
    Network network = createNetworkWithNameAndLabel("net", labelName);
    NetworkAttachment removedAttachment = createNetworkAttachment(network, nicWithLabel);
    assertTestNotRemovingLabeledNetworksValid(nicWithLabel, removedAttachment, new ParametersBuilder().addRemovedLabels(labelName).build(), network);
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Aggregations

Network (org.ovirt.engine.core.common.businessentities.network.Network)292 Test (org.junit.Test)105 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)63 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)47 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)46 ArrayList (java.util.ArrayList)44 Guid (org.ovirt.engine.core.compat.Guid)44 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)39 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)23 List (java.util.List)21 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)21 HashMap (java.util.HashMap)19 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)19 Map (java.util.Map)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)13 HashSet (java.util.HashSet)9 Set (java.util.Set)9 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9