use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class ExecuteNetworkCommandInNetworkOperationTest method testBondingTwoNicsWithReattachingNetworkAttachmentOnNewlyCreatedBond.
/*
* At the beginning there were two nics (one with NetworkAttachment), which, after being introduced to each other,
* formed a firm bond adopting NetworkAttachment as their own.
*/
@Test
public void testBondingTwoNicsWithReattachingNetworkAttachmentOnNewlyCreatedBond() throws Exception {
NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA);
initNetworkIdToExistingAttachmentIdMap(attachment);
initOrginalBondNameToIdMap();
when(networkInterfaceModelOfNicA.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkA));
NetworkOperation.BOND_WITH.getTarget().executeNetworkCommand(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB, dataFromHostSetupNetworksModel, newlyCreatedBond);
when(logicalNetworkModelOfNetworkA.isAttached()).thenReturn(false);
when(bondNetworkInterfaceModelA.getOriginalIface()).thenReturn(newlyCreatedBond.toBond());
// this is not part of BOND_WITH command, it's simply called after it. BOND_WITH is actually: "detach networks
// and create bond".
// in production code, probably due to some problems with listeners, this is actually called three times,
// luckily each time overwriting previous call.
NetworkOperation.attachNetworks(bondNetworkInterfaceModelA, Collections.singletonList(logicalNetworkModelOfNetworkA), dataFromHostSetupNetworksModel);
// related network attachment will be updated, not removed and created new one.
assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
assertNetworkAttachment(dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(), attachment.getId(), networkA.getId(), newlyCreatedBond.getId());
assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
assertBond(newOrModifiedBond, null, Arrays.asList(nicA, nicB));
assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0));
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class ReportedConfigurationsFiller method fillReportedConfigurations.
public void fillReportedConfigurations(List<VdsNetworkInterface> allInterfacesForHost, BusinessEntityMap<Network> networkMap, List<NetworkAttachment> networkAttachments, DnsResolverConfiguration reportedDnsResolverConfiguration, Guid clusterId) {
Cluster cluster = clusterDao.get(clusterId);
Map<String, VdsNetworkInterface> networkNameToNicMap = nicsByNetworkId(allInterfacesForHost);
for (NetworkAttachment networkAttachment : networkAttachments) {
fillReportedConfigurations(networkNameToNicMap, networkMap, networkAttachment, reportedDnsResolverConfiguration, cluster);
}
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class NetworkAttachmentsValidator method createNicNameToNetworkTypesMap.
private Map<String, List<NetworkType>> createNicNameToNetworkTypesMap() {
Map<String, List<NetworkType>> nicNameToNetworkTypes = new HashMap<>();
for (NetworkAttachment attachment : attachmentsToConfigure) {
String nicName = attachment.getNicName();
// have to check since if null, multiple results would be merged producing invalid results.
if (nicName == null) {
throw new IllegalArgumentException("nic name cannot be null");
}
Network networkToConfigure = networkBusinessEntityMap.get(attachment.getNetworkId());
NetworkType networkTypeToAdd = determineNetworkType(networkToConfigure);
nicNameToNetworkTypes.computeIfAbsent(nicName, k -> new ArrayList<>()).add(networkTypeToAdd);
}
return nicNameToNetworkTypes;
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class BackendHostNicsResource method list.
@Override
public HostNics list() {
HostNics ret = new HostNics();
List<VdsNetworkInterface> ifaces = getCollection();
Map<String, Guid> networkNameToNetworkIdMap = mapNetworkNamesToNetworkIds();
Map<Guid, NetworkAttachment> attachmentsByNetworkId = getAttachmentsByNetworkId();
for (VdsNetworkInterface iface : ifaces) {
HostNic hostNic = populate(map(iface, ifaces), iface);
setCustomProperties(attachmentsByNetworkId, networkNameToNetworkIdMap, hostNic);
String networkName = iface.getNetworkName();
if (networkNameToNetworkIdMap.containsKey(networkName)) {
Guid networkId = networkNameToNetworkIdMap.get(networkName);
hostNic.getNetwork().setId(networkId.toString());
hostNic.getNetwork().setName(null);
}
ret.getHostNics().add(addLinks(hostNic));
}
return addActions(ret);
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class PersistentHostSetupNetworksParametersFactoryTest method testCreate.
@Test
public void testCreate() {
when(networkAttachmentDao.getAllForHost(hostId)).thenReturn(Arrays.asList(networkAttachmentA, networkAttachmentB));
PersistentHostSetupNetworksParameters parameters = underTest.create(hostId, Arrays.asList(networkA, networkB));
assertThat(parameters.getShouldBeLogged(), is(false));
assertThat(parameters.rollbackOnFailure(), is(true));
String expectedSubstitutedNetworkNames = networkB.getName();
assertThat(parameters.getNetworkNames(), is(expectedSubstitutedNetworkNames));
assertThat(parameters.getNetworkAttachments(), hasSize(1));
NetworkAttachment soleAttachment = parameters.getNetworkAttachments().iterator().next();
assertThat(soleAttachment.getId(), is(networkAttachmentB.getId()));
assertThat(soleAttachment.isOverrideConfiguration(), is(true));
}
Aggregations