use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class ExecuteNetworkCommandInNetworkOperationTest method joinBondsTest.
/*
* At the beginning there were two bonds (one with NetworkAttachment), which, after being introduced to each other,
* formed a firm bond adopting NetworkAttachment as their own.
*/
private void joinBondsTest(boolean resusingName) {
addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(bondNetworkInterfaceModelA, logicalNetworkModelOfNetworkA);
// $NON-NLS-1$
Bond bondB = createBond(Guid.newGuid(), "bondB", Arrays.asList(nicC, nicD)).toBond();
addBondToParamsAndModel(bondB, bondNetworkInterfaceModelB, Collections.singletonList(logicalNetworkModelOfNetworkA));
initOrginalBondNameToIdMap(bondNetworkInterfaceModelA.getCreateOrUpdateBond(), bondNetworkInterfaceModelB.getCreateOrUpdateBond());
when(bondNetworkInterfaceModelA.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkA));
when(bondNetworkInterfaceModelA.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB));
when(bondNetworkInterfaceModelB.getItems()).thenReturn(Collections.emptyList());
when(bondNetworkInterfaceModelB.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicC, networkInterfaceModelOfNicD));
if (resusingName) {
newlyCreatedBond.setName(existingBondName);
}
NetworkOperation.JOIN_BONDS.getTarget().executeNetworkCommand(bondNetworkInterfaceModelA, bondNetworkInterfaceModelB, dataFromHostSetupNetworksModel, newlyCreatedBond);
// NetworkOperation.JOIN_BONDS only detaches the attachments, the attachments are being re-attached only in
// HostSetupNetworksModel (after clicking ok in the new bond dialog)
assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(1));
Guid removeNetworkAttachmentId = dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().iterator().next();
// $NON-NLS-1$
assertThat("id mismatch", removeNetworkAttachmentId, is(networkAttachment.getId()));
assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
assertBond(newOrModifiedBond, resusingName ? existingBondId : null, Arrays.asList(nicA, nicB, nicC, nicD));
assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(resusingName ? 1 : 2));
// $NON-NLS-1$
assertThat("id mismatch", dataFromHostSetupNetworksModel.getRemovedBonds().contains(existingBondId), is(!resusingName));
// $NON-NLS-1$
assertThat("id mismatch", dataFromHostSetupNetworksModel.getRemovedBonds().contains(bondB.getId()), is(true));
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond 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.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class BackendHostResource method mapBonds.
public CreateOrUpdateBond mapBonds(BusinessEntityMap<Bond> bonds, HostNic model) {
Mapper<HostNic, Bond> hostNicMapper = getMapper(HostNic.class, Bond.class);
Bond bond;
if (model.isSetId()) {
Guid nicId = asGuid(model.getId());
bond = hostNicMapper.map(model, bonds.get(nicId));
} else {
Bond template = model.isSetName() ? bonds.get(model.getName()) : null;
bond = hostNicMapper.map(model, template);
}
return CreateOrUpdateBond.fromBond(bond);
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class NicLabelValidator method labelBeingAttachedToValidBond.
ValidationResult labelBeingAttachedToValidBond(NicLabel nicLabel) {
String interfaceName = nicLabel.getNicName();
VdsNetworkInterface nic = existingInterfacesMap.get(interfaceName);
if (nic instanceof Bond) {
CreateOrUpdateBond createOrUpdateBond = createOrUpdateBondBusinessEntityMap.containsKey(interfaceName) ? createOrUpdateBondBusinessEntityMap.get(interfaceName) : CreateOrUpdateBond.fromBond((Bond) nic);
if (createOrUpdateBond.getSlaves().size() < 2) {
return new ValidationResult(EngineMessage.IMPROPER_BOND_IS_LABELED, ReplacementUtils.createSetVariableString(HostInterfaceValidator.VAR_BOND_NAME, createOrUpdateBond.getName()));
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class NicLabelValidator method shouldBeConfigureAsBondSlave.
private boolean shouldBeConfigureAsBondSlave(String interfaceName) {
// Check if the interface was updated to be a bond's slave
for (CreateOrUpdateBond createOrUpdateBond : params.getCreateOrUpdateBonds()) {
if (createOrUpdateBond.getSlaves().contains(interfaceName)) {
return true;
}
}
// The interface wasn't updated to be a slave, check if currently it is a slave.
VdsNetworkInterface existingNic = existingInterfacesMap.get(interfaceName);
if (existingNic == null) {
return false;
}
if (existingNic.isPartOfBond()) {
String bondName = existingNic.getBondName();
VdsNetworkInterface bond = existingInterfacesMap.get(bondName);
boolean bondWasRemoved = params.getRemovedBonds().contains(bond.getId());
boolean slaveWasRemovedFromBond = createOrUpdateBondBusinessEntityMap.containsKey(bondName) && !createOrUpdateBondBusinessEntityMap.get(bondName).getSlaves().contains(interfaceName);
return !bondWasRemoved && !slaveWasRemovedFromBond;
}
return false;
}
Aggregations