Search in sources :

Example 36 with NetworkAttachment

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));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 37 with NetworkAttachment

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);
    }
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkInSyncWithVdsNetworkInterface(org.ovirt.engine.core.utils.NetworkInSyncWithVdsNetworkInterface) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 38 with NetworkAttachment

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;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkExclusivenessValidator(org.ovirt.engine.core.bll.validator.network.NetworkExclusivenessValidator) NetworkType(org.ovirt.engine.core.bll.validator.network.NetworkType) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) HashMap(java.util.HashMap) BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) Collectors(java.util.stream.Collectors) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Map(java.util.Map) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Entry(java.util.Map.Entry) Network(org.ovirt.engine.core.common.businessentities.network.Network) HashMap(java.util.HashMap) NetworkType(org.ovirt.engine.core.bll.validator.network.NetworkType) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 39 with NetworkAttachment

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);
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) HostNics(org.ovirt.engine.api.model.HostNics) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 40 with NetworkAttachment

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));
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) 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