Search in sources :

Example 26 with NetworkAttachment

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

the class HostNetworkAttachmentsPersister method removeInvalidNetworkAttachmentsFromDb.

/**
 * Removes all {@link org.ovirt.engine.core.common.businessentities.network.NetworkAttachment NetworkAttachments},
 * which network aren't associated with any of given {@link #nicsByName nics}, both from
 * <code>existingNetworkAttachments</code> and from db.
 *
 * @param existingNetworkAttachments all existing attachments.
 */
private void removeInvalidNetworkAttachmentsFromDb(List<NetworkAttachment> existingNetworkAttachments) {
    for (Iterator<NetworkAttachment> iterator = existingNetworkAttachments.iterator(); iterator.hasNext(); ) {
        NetworkAttachment networkAttachment = iterator.next();
        boolean attachmentRelatesToNetworkNotReportedOnHost = !networkConfiguredOnHost(networkAttachment.getNetworkId());
        if (attachmentRelatesToNetworkNotReportedOnHost) {
            networkAttachmentDao.remove(networkAttachment.getId());
            iterator.remove();
        }
    }
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 27 with NetworkAttachment

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

the class HostNetworkAttachmentsPersisterTest method createNetworkAttachment.

private NetworkAttachment createNetworkAttachment(Network network) {
    NetworkAttachment networkAttachment = new NetworkAttachment();
    networkAttachment.setId(Guid.newGuid());
    networkAttachment.setNetworkId(network == null ? null : network.getId());
    return networkAttachment;
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 28 with NetworkAttachment

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

the class HostNetworkAttachmentsPersisterTest method testPersistNetworkAttachmentsWhenCalledWithNewUserAttachments.

@Test
public void testPersistNetworkAttachmentsWhenCalledWithNewUserAttachments() throws Exception {
    Guid userNetworkAttachmentNicId = interfaceWithAttachedClusterNetworkA.getId();
    NetworkAttachment userNetworkAttachment = createNetworkAttachment(clusterNetworkA);
    userNetworkAttachment.setNicId(userNetworkAttachmentNicId);
    userNetworkAttachment.setProperties(customPropertiesForNics.getCustomPropertiesFor(interfaceWithAttachedClusterNetworkA));
    userNetworkAttachment.setIpConfiguration(NetworkUtils.createIpConfigurationFromVdsNetworkInterface(interfaceWithAttachedClusterNetworkA));
    // when persisting new record user provided will be replaced.
    Guid userProvidedNetworkAttachmentId = userNetworkAttachment.getId();
    // user attachments references network, which is not assigned to NIC.
    createPersister(Collections.singletonList(userNetworkAttachment)).persistNetworkAttachments();
    verify(networkAttachmentDao).getAllForHost(any());
    ArgumentCaptor<NetworkAttachment> networkAttachmentCaptor = ArgumentCaptor.forClass(NetworkAttachment.class);
    verify(networkAttachmentDao).save(networkAttachmentCaptor.capture());
    // nicId won't be updated to calculated value
    assertThat(networkAttachmentCaptor.getValue().getNicId(), is(userNetworkAttachmentNicId));
    // new id will be generated for persisted record
    assertThat(networkAttachmentCaptor.getValue().getId(), not(equalTo(userProvidedNetworkAttachmentId)));
    assertThat(networkAttachmentCaptor.getValue().getIpConfiguration(), is(userNetworkAttachment.getIpConfiguration()));
    assertThat(networkAttachmentCaptor.getValue().getNetworkId(), is(userNetworkAttachment.getNetworkId()));
    // verify that nothing else happens, no removals, no creations.
    verifyNoMoreInteractions(networkAttachmentDao);
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 29 with NetworkAttachment

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

the class HostNetworkAttachmentsPersisterTest method testPersistNetworkAttachmentsDeleteInvalidNetworkAttachments.

@Test
public void testPersistNetworkAttachmentsDeleteInvalidNetworkAttachments() throws Exception {
    // network attachments.
    NetworkAttachment networkAttachmentForClusterNetworkA = createNetworkAttachment(clusterNetworkA);
    networkAttachmentForClusterNetworkA.setNicId(interfaceWithAttachedClusterNetworkA.getId());
    networkAttachmentForClusterNetworkA.setProperties(customPropertiesForNics.getCustomPropertiesFor(interfaceWithAttachedClusterNetworkA));
    networkAttachmentForClusterNetworkA.setIpConfiguration(NetworkUtils.createIpConfigurationFromVdsNetworkInterface(interfaceWithAttachedClusterNetworkA));
    NetworkAttachment networkAttachmentForClusterNetworkB = createNetworkAttachment(clusterNetworkB);
    NetworkAttachment networkAttachmentWithoutNetworkAssigned = createNetworkAttachment(null);
    when(networkAttachmentDao.getAllForHost(eq(hostId))).thenReturn(new ArrayList<>(Arrays.asList(networkAttachmentForClusterNetworkA, networkAttachmentForClusterNetworkB, networkAttachmentWithoutNetworkAssigned)));
    createPersister(Collections.emptyList()).persistNetworkAttachments();
    verify(networkAttachmentDao).getAllForHost(any());
    verify(networkAttachmentDao).remove(eq(networkAttachmentForClusterNetworkB.getId()));
    verify(networkAttachmentDao).remove(eq(networkAttachmentWithoutNetworkAssigned.getId()));
    // verify that nothing else gets removed.
    verifyNoMoreInteractions(networkAttachmentDao);
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 30 with NetworkAttachment

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

the class HostNetworkAttachmentsPersisterTest method testPersistNetworkAttachmentsWhenNothingToUpdate.

@Test
public void testPersistNetworkAttachmentsWhenNothingToUpdate() throws Exception {
    NetworkAttachment upToDateNetworkAttachment = createNetworkAttachment(clusterNetworkA);
    upToDateNetworkAttachment.setNicId(interfaceWithAttachedClusterNetworkA.getId());
    IpConfiguration ipConfiguration = NetworkUtils.createIpConfigurationFromVdsNetworkInterface(interfaceWithAttachedClusterNetworkA);
    upToDateNetworkAttachment.setIpConfiguration(ipConfiguration);
    upToDateNetworkAttachment.setProperties(customPropertiesForNics.getCustomPropertiesFor(interfaceWithAttachedClusterNetworkA));
    when(networkAttachmentDao.getAllForHost(eq(hostId))).thenReturn(Collections.singletonList(upToDateNetworkAttachment));
    createPersister(Collections.emptyList()).persistNetworkAttachments();
    verify(networkAttachmentDao).getAllForHost(any());
    verifyNoMoreInteractions(networkAttachmentDao);
}
Also used : IpConfiguration(org.ovirt.engine.core.common.businessentities.network.IpConfiguration) 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