Search in sources :

Example 1 with NetworkAttachment

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

the class PersistentHostSetupNetworksParametersFactory method create.

/**
 * @param hostId host on which networks to be updated reside
 * @param networks networks to be updated; it is assumed, that all those networks belongs to given host.
 *
 * @return PersistentHostSetupNetworksParameters to refresh all given networks.
 */
public PersistentHostSetupNetworksParameters create(Guid hostId, List<Network> networks) {
    Map<Network, NetworkAttachment> networksToSync = getNetworksToSync(hostId, networks);
    PersistentHostSetupNetworksParameters parameters = new PersistentHostSetupNetworksParameters(hostId);
    parameters.setRollbackOnFailure(true);
    parameters.setShouldBeLogged(false);
    parameters.setNetworkNames(getNetworkNames(networksToSync.keySet()));
    parameters.setNetworkAttachments(new ArrayList<>(networksToSync.values()));
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 2 with NetworkAttachment

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

the class NetworkAttachmentValidatorTest method testNetworkNotAttachedToHostWhenAttached.

@Test
public void testNetworkNotAttachedToHostWhenAttached() {
    Network network = createNetwork();
    when(networkDaoMock.get(network.getId())).thenReturn(network);
    when(vdsDaoMock.getAllForNetwork(eq(network.getId()))).thenReturn(Collections.singletonList(host));
    String networkName = NETWORK_NAME;
    NetworkAttachment attachment = new NetworkAttachment();
    attachment.setNetworkId(network.getId());
    attachment.setNetworkName(networkName);
    assertThat(createNetworkAttachmentValidator(attachment).networkNotAttachedToHost(), failsWith(EngineMessage.NETWORK_ALREADY_ATTACHED_TO_HOST, ReplacementUtils.createSetVariableString(NETWORK_NAME, networkName), ReplacementUtils.createSetVariableString(HOST_NAME, host.getName())));
}
Also used : ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 3 with NetworkAttachment

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

the class NetworkAttachmentValidatorTest method testNetworkNotAttachedToHost.

@Test
public void testNetworkNotAttachedToHost() {
    Network network = createNetwork();
    when(networkDaoMock.get(network.getId())).thenReturn(network);
    NetworkAttachment attachment = new NetworkAttachment();
    attachment.setNetworkId(network.getId());
    assertThat(createNetworkAttachmentValidator(attachment).networkNotAttachedToHost(), isValid());
}
Also used : ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 4 with NetworkAttachment

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

the class NetworkAttachmentValidatorTest method testNetworkExistWhenOnlyNetworkNameIsSet.

@Test
public void testNetworkExistWhenOnlyNetworkNameIsSet() {
    NetworkAttachment networkAttachment = new NetworkAttachment();
    networkAttachment.setNetworkName(NETWORK_NAME);
    NetworkAttachmentValidator validator = createNetworkAttachmentValidator(networkAttachment);
    EngineMessage engineMessage = EngineMessage.NETWORK_HAVING_NAME_NOT_EXISTS;
    assertThat(validator.networkExists(), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, NETWORK_NAME)));
}
Also used : EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 5 with NetworkAttachment

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

the class NetworkAttachmentValidatorTest method testNotExternalNetwork.

@Test
public void testNotExternalNetwork() {
    Network notExternalNetwork = new Network();
    notExternalNetwork.setId(Guid.newGuid());
    notExternalNetwork.setProvidedBy(null);
    when(networkDaoMock.get(eq(notExternalNetwork.getId()))).thenReturn(notExternalNetwork);
    NetworkAttachment attachment = new NetworkAttachment();
    attachment.setNetworkId(notExternalNetwork.getId());
    NetworkAttachmentValidator validator = createNetworkAttachmentValidator(attachment);
    assertThat(validator.notExternalNetwork(), isValid());
}
Also used : ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

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