use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidModifiedBondsFailsWhenSlavesValidationFails.
@Test
public void testValidModifiedBondsFailsWhenSlavesValidationFails() throws Exception {
EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ATTACHED_TO_NETWORK_CANNOT_BE_SLAVE;
ValidationResult slavesValidationResult = new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, "slaveA"), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, "networkName"));
CreateOrUpdateBond createOrUpdateBond = createNewCreateOrUpdateBondWithNameAndId();
createOrUpdateBond.setSlaves(Stream.of("slaveA", "slaveB").collect(toSet()));
doTestValidModifiedBonds(createOrUpdateBond, ValidationResult.VALID, /*this mocks validateModifiedBondSlaves to just verify, that caller method will behave ok, when
validateModifiedBondSlaves return invalid result*/
slavesValidationResult, slavesValidationResult);
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class ExecuteNetworkCommandInNetworkOperationTest method createBond.
private CreateOrUpdateBond createBond(Guid id, String bondName, List<VdsNetworkInterface> slaves) {
CreateOrUpdateBond result = new CreateOrUpdateBond();
result.setId(id);
result.setName(bondName);
for (VdsNetworkInterface slave : slaves) {
result.getSlaves().add(slave.getName());
}
return result;
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class ExecuteNetworkCommandInNetworkOperationTest method testRemoveSlaveFromBond.
/*
* At the beginning there was a bond with three slaves, the one of them left others.
*/
@Test
public void testRemoveSlaveFromBond() throws Exception {
existingBond.getSlaves().add(nicC.getName());
addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
when(bondNetworkInterfaceModelA.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB, networkInterfaceModelOfNicC));
NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(bondNetworkInterfaceModelA, logicalNetworkModelOfNetworkA);
when(networkInterfaceModelOfNicA.getBond()).thenReturn(bondNetworkInterfaceModelA);
NetworkOperation.REMOVE_FROM_BOND.getTarget().executeNetworkCommand(networkInterfaceModelOfNicA, null, dataFromHostSetupNetworksModel);
// related network attachment will be updated, not removed and created new one.
assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
Guid networkAttachmentId = dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next().getId();
// $NON-NLS-1$
assertThat("id mismatch", networkAttachmentId, is(networkAttachment.getId()));
assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
assertBond(newOrModifiedBond, existingBondId, Arrays.asList(nicB, nicC));
assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0));
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class ExecuteNetworkCommandInNetworkOperationTest method testBreakingExistingBond.
/*
* At the beginning there was a bond, which was then broken.
*/
@Test
public void testBreakingExistingBond() throws Exception {
CreateOrUpdateBond createOrUpdateBond = CreateOrUpdateBond.fromBond(existingBond);
dataFromHostSetupNetworksModel.getBonds().add(createOrUpdateBond);
when(bondNetworkInterfaceModelA.getItems()).thenReturn(Collections.emptyList());
when(bondNetworkInterfaceModelA.getCreateOrUpdateBond()).thenReturn(createOrUpdateBond);
NetworkOperation.BREAK_BOND.getTarget().executeNetworkCommand(bondNetworkInterfaceModelA, null, dataFromHostSetupNetworksModel);
assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(0));
assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(1));
Guid removedBondId = dataFromHostSetupNetworksModel.getRemovedBonds().iterator().next();
// $NON-NLS-1$
assertThat("id mismatch", removedBondId, is(existingBond.getId()));
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class HostSetupNetworksCommand method isManagementNetworkChanged.
private boolean isManagementNetworkChanged(List<HostNetwork> networksToConfigure) {
Network managementNetwork = managementNetworkUtil.getManagementNetwork(getClusterNetworks(), getClusterId());
String managementNetworkName = managementNetwork.getName();
for (HostNetwork network : networksToConfigure) {
if (managementNetworkName.equals(network.getNetworkName())) {
return true;
}
}
for (CreateOrUpdateBond createOrUpdateBond : getParameters().getCreateOrUpdateBonds()) {
// We are only interested in existing bonds, whose bonding options/slave have changed, so it
// enough to check existing bonds. New bonds which have the management network
// are covered by network attachments
VdsNetworkInterface bondNic = getExistingNicsBusinessEntityMap().get(createOrUpdateBond.getId());
if (bondNic != null && managementNetworkName.equals(bondNic.getNetworkName())) {
return true;
}
}
return false;
}
Aggregations