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();
}
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations