Search in sources :

Example 66 with NetworkAttachment

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

the class HostSetupNetworksValidatorTest method testValidateCustomProperties.

@Test
public void testValidateCustomProperties() 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 = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(networkAttachment)).addNetworks(networkA).build();
    // we do not test SimpleCustomPropertiesUtil here, we just state what happens if it does not find ValidationError
    SimpleCustomPropertiesUtil simpleCustomPropertiesUtilMock = mock(SimpleCustomPropertiesUtil.class);
    assertThat(validator.validateCustomProperties(simpleCustomPropertiesUtilMock, Collections.emptyMap(), Collections.emptyMap()), isValid());
}
Also used : SimpleCustomPropertiesUtil(org.ovirt.engine.core.common.utils.customprop.SimpleCustomPropertiesUtil) 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) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 67 with NetworkAttachment

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

the class HostSetupNetworksValidatorTest method createNetworkAttachment.

private NetworkAttachment createNetworkAttachment(Network networkA, VdsNetworkInterface nic, Guid guid) {
    NetworkAttachment attachment = createNetworkAttachment(networkA, guid);
    if (nic != null) {
        attachment.setNicId(nic.getId());
        attachment.setNicName(nic.getName());
    }
    return attachment;
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 68 with NetworkAttachment

use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment 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 69 with NetworkAttachment

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

the class HostSetupNetworksValidatorTest method modifiedAttachmentNotRemovedAttachmentModifiedButNotRemovedValid.

@Test
public void modifiedAttachmentNotRemovedAttachmentModifiedButNotRemovedValid() {
    HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().build();
    NetworkAttachment modifiedAttachment = createNetworkAttachment(new Network());
    assertThat(validator.modifiedAttachmentNotRemoved(modifiedAttachment), isValid());
}
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 70 with NetworkAttachment

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

the class IpConfigurationCompleterTest method setUp.

@Before
public void setUp() {
    underTest = new IpConfigurationCompleter();
    ipConfiguration = new IpConfiguration();
    networkAttachment = new NetworkAttachment();
    networkAttachment.setIpConfiguration(ipConfiguration);
    networkAttachments = Collections.singleton(networkAttachment);
}
Also used : IpConfiguration(org.ovirt.engine.core.common.businessentities.network.IpConfiguration) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Before(org.junit.Before)

Aggregations

NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)167 Test (org.junit.Test)79 Network (org.ovirt.engine.core.common.businessentities.network.Network)62 Guid (org.ovirt.engine.core.compat.Guid)37 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)36 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)35 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)20 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)18 HashMap (java.util.HashMap)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)14 ArrayList (java.util.ArrayList)10 IpConfiguration (org.ovirt.engine.core.common.businessentities.network.IpConfiguration)10 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)9 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)8 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)7 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)7 AnonymousHostNetworkQos (org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos)6 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)5 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)5