Search in sources :

Example 16 with Bond

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

the class NicLabelValidatorTest method labelBeingAttachedToValidBondAttachedBondBecomingNotValid.

@Test
public void labelBeingAttachedToValidBondAttachedBondBecomingNotValid() {
    Bond existingBond = new Bond("bond");
    existingBond.setSlaves(Arrays.asList("slave1", "slave2"));
    HostSetupNetworksParameters params = createHostSetupNetworksParams();
    CreateOrUpdateBond updatedBond = new CreateOrUpdateBond();
    updatedBond.setName(existingBond.getName());
    updatedBond.setSlaves(new HashSet<>());
    params.getCreateOrUpdateBonds().add(updatedBond);
    assertLabelBeingAttachedToValidBondFailed(params, existingBond);
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) Test(org.junit.Test)

Example 17 with Bond

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

the class HostSetupNetworksValidatorTest method validateBondModeForLabeledVmNetwork.

private void validateBondModeForLabeledVmNetwork(BondMode bondMode) {
    String bondName = "bondName";
    String networkName = "vmNetwork";
    String label = "label";
    Bond bond = createBond(bondName, networkName, null);
    bond.setLabels(new HashSet<>(Collections.singletonList(label)));
    bond.setBondOptions(bondMode.getConfigurationValue());
    Network vmNetwork = createNetworkWithName(networkName);
    vmNetwork.setVmNetwork(true);
    vmNetwork.setLabel(label);
    NetworkAttachment vmNetworkNetworkAttachment = createNetworkAttachment(vmNetwork, bond);
    HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addBonds(CreateOrUpdateBond.fromBond(bond))).addNetworks(vmNetwork).addExistingInterfaces(bond).build();
    List<NetworkAttachment> attachmentsToConfigure = Collections.singletonList(vmNetworkNetworkAttachment);
    ValidationResult result = validator.validateBondModeVsNetworksAttachedToIt(attachmentsToConfigure);
    if (bondMode.isBondModeValidForVmNetwork()) {
        collector.checkThat(result, isValid());
    } else {
        collector.checkThat(result, failsWith(EngineMessage.INVALID_BOND_MODE_FOR_BOND_WITH_LABELED_VM_NETWORK, ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_BOND_NAME, bondName), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, networkName), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_LABEL, label)));
    }
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 18 with Bond

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

the class CreateOrUpdateBond method toBond.

public Bond toBond() {
    Bond bond = new Bond();
    bond.setId(getId());
    bond.setName(getName());
    bond.setSlaves(new ArrayList<>(getSlaves()));
    bond.setBondOptions(getBondOptions());
    return bond;
}
Also used : Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 19 with Bond

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

the class HostNicMapperTest method testBondMapping.

@Test
public void testBondMapping() {
    HostNic model = new HostNic();
    model.setId(Guid.newGuid().toString());
    model.setName(RandomUtils.instance().nextString(10));
    model.setBonding(new Bonding());
    model.getBonding().setSlaves(new HostNics());
    HostNic slaveA = new HostNic();
    slaveA.setName(RandomUtils.instance().nextString(10));
    model.getBonding().getSlaves().getHostNics().add(slaveA);
    Bond entity = HostNicMapper.map(model, null);
    assertNotNull(entity);
    assertEquals(model.getId(), entity.getId().toString());
    assertEquals(model.getName(), entity.getName());
    assertEquals(model.getBonding().getSlaves().getHostNics().size(), entity.getSlaves().size());
    for (HostNic slave : model.getBonding().getSlaves().getHostNics()) {
        assertTrue(entity.getSlaves().contains(slave.getName()));
    }
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) Bonding(org.ovirt.engine.api.model.Bonding) HostNics(org.ovirt.engine.api.model.HostNics) Test(org.junit.Test)

Example 20 with Bond

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

the class HostSetupNetworksModel method initCreateOrUpdateBondParameters.

private void initCreateOrUpdateBondParameters() {
    NetworkCommonUtils.fillBondSlaves(allExistingNics);
    for (VdsNetworkInterface nic : allExistingNics) {
        if (nic.isBond()) {
            getHostSetupNetworksParametersData().getBonds().add(CreateOrUpdateBond.fromBond((Bond) nic));
        }
    }
    hostSetupNetworksParametersData.setOriginalBondsByName(Entities.entitiesByName(hostSetupNetworksParametersData.getBonds()));
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Aggregations

Bond (org.ovirt.engine.core.common.businessentities.network.Bond)34 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)24 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)19 Test (org.junit.Test)11 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)8 ArrayList (java.util.ArrayList)7 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)5 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)5 NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)5 List (java.util.List)4 HostNic (org.ovirt.engine.api.model.HostNic)4 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 HashMap (java.util.HashMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)3 Guid (org.ovirt.engine.core.compat.Guid)3 Bonding (org.ovirt.engine.api.model.Bonding)2 Vlan (org.ovirt.engine.core.common.businessentities.network.Vlan)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2