use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method validateBondMode.
private void validateBondMode(boolean isVmNetwork, BondMode bondMode) {
String networkName = "networkName";
String bondName = "bondName";
Bond bond = createBond(bondName, networkName, null);
bond.setBondOptions(bondMode.getConfigurationValue());
Network network = createNetworkWithName(networkName);
network.setVmNetwork(isVmNetwork);
NetworkAttachment vmNetworkNetworkAttachment = createNetworkAttachment(network, bond);
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addBonds(CreateOrUpdateBond.fromBond(bond))).addNetworks(network).addExistingInterfaces(bond).build();
List<NetworkAttachment> attachmentsToConfigure = Collections.singletonList(vmNetworkNetworkAttachment);
ValidationResult result = validator.validateBondModeVsNetworksAttachedToIt(attachmentsToConfigure);
if (!isVmNetwork || bondMode.isBondModeValidForVmNetwork()) {
collector.checkThat(result, isValid());
} else {
collector.checkThat(result, failsWith(EngineMessage.INVALID_BOND_MODE_FOR_BOND_WITH_VM_NETWORK, ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_BOND_NAME, bondName), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, networkName)));
}
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidateModifiedBondSlavesWhenSlaveHasNetworkAssignedWhichIsNotRemovedAsAPartOfRequest.
@Test
public void testValidateModifiedBondSlavesWhenSlaveHasNetworkAssignedWhichIsNotRemovedAsAPartOfRequest() throws Exception {
Bond bond = createBond();
Network networkBeingRemoved = new Network();
networkBeingRemoved.setName("assignedNetwork");
VdsNetworkInterface slaveA = createBondSlave(bond, "slaveA");
slaveA.setNetworkName("assignedNetwork");
NetworkAttachment attachmentOfNetworkToSlaveA = createNetworkAttachment(networkBeingRemoved, slaveA);
VdsNetworkInterface slaveB = createBondSlave(bond, "slaveB");
setBondSlaves(bond, slaveA, slaveB);
EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ATTACHED_TO_NETWORK_CANNOT_BE_SLAVE;
final HostSetupNetworksValidator build = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addBonds(CreateOrUpdateBond.fromBond(bond))).addExistingInterfaces(bond, slaveA, slaveB).addExistingAttachments(attachmentOfNetworkToSlaveA).addNetworks(networkBeingRemoved).build();
doTestValidateModifiedBondSlaves(spy(build), ValidationResult.VALID, ValidationResult.VALID, failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, slaveA.getName()), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, networkBeingRemoved.getName())));
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testNotMovingLabeledNetworkToDifferentNicWhenRemovingLabeledNetworkUnrelatedToRemovedBond.
@Test
public void testNotMovingLabeledNetworkToDifferentNicWhenRemovingLabeledNetworkUnrelatedToRemovedBond() throws Exception {
String label = "label";
Network labeledNetwork = new Network();
labeledNetwork.setId(Guid.newGuid());
labeledNetwork.setLabel(label);
VdsNetworkInterface existingNic = new VdsNetworkInterface();
existingNic.setLabels(Collections.singleton(label));
existingNic.setId(Guid.newGuid());
existingNic.setName("nic1");
VdsNetworkInterface existingNic2 = new VdsNetworkInterface();
existingNic2.setId(Guid.newGuid());
existingNic2.setName("nic2");
Guid attachmentId = Guid.newGuid();
NetworkAttachment existingNetworkAttachment = createNetworkAttachment(labeledNetwork, attachmentId);
existingNetworkAttachment.setNicId(existingNic.getId());
existingNetworkAttachment.setNicName(existingNic.getName());
NetworkAttachment updatedNetworkAttachment = createNetworkAttachment(labeledNetwork, attachmentId);
updatedNetworkAttachment.setNicId(existingNic2.getId());
updatedNetworkAttachment.setNicName(existingNic2.getName());
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(updatedNetworkAttachment)).addExistingInterfaces(Arrays.asList(existingNic, existingNic2)).addExistingAttachments(Collections.singletonList(existingNetworkAttachment)).addNetworks(Collections.singletonList(labeledNetwork)).build();
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_MOVE_LABELED_NETWORK_TO_ANOTHER_NIC;
assertThat(validator.notMovingLabeledNetworkToDifferentNic(updatedNetworkAttachment), failsWith(engineMessage, ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, labeledNetwork.getName()), ReplacementUtils.getVariableAssignmentString(engineMessage, labeledNetwork.getLabel())));
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidateModifiedBondSlavesWhenSlaveHasNetworkAssignedWhichIsRemovedAsAPartOfRequest.
@Test
public void testValidateModifiedBondSlavesWhenSlaveHasNetworkAssignedWhichIsRemovedAsAPartOfRequest() throws Exception {
Bond bond = createBond();
Network networkBeingRemoved = new Network();
networkBeingRemoved.setName("assignedNetwork");
VdsNetworkInterface slaveA = createBondSlave(bond, "slaveA");
slaveA.setNetworkName(networkBeingRemoved.getName());
VdsNetworkInterface slaveB = createBondSlave(bond, "slaveB");
NetworkAttachment removedNetworkAttachment = new NetworkAttachment();
removedNetworkAttachment.setId(Guid.newGuid());
removedNetworkAttachment.setNicName(slaveA.getName());
setBondSlaves(bond, slaveA, slaveB);
final HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedNetworkAttachments(removedNetworkAttachment)).addExistingInterfaces(bond, slaveA, slaveB).addExistingAttachments(removedNetworkAttachment).addNetworks(networkBeingRemoved).build();
doTestValidateModifiedBondSlaves(spy(validator), ValidationResult.VALID, ValidationResult.VALID, isValid());
}
use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testNetworksUniquelyConfiguredOnHostWhenNotUniquelyConfigured.
@Test
public void testNetworksUniquelyConfiguredOnHostWhenNotUniquelyConfigured() throws Exception {
Guid id = Guid.newGuid();
String networkName = "networkName";
Network networkA = new Network();
networkA.setName(networkName);
networkA.setId(id);
NetworkAttachment networkAttachment = createNetworkAttachment(networkA);
NetworkAttachment networkAttachmentReferencingSameNetwork = createNetworkAttachment(networkA);
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().addNetworks(Collections.singletonList(networkA)).build();
assertThat(validator.networksUniquelyConfiguredOnHost(Arrays.asList(networkAttachment, networkAttachmentReferencingSameNetwork)), failsWith(EngineMessage.NETWORKS_ALREADY_ATTACHED_TO_IFACES, ReplacementUtils.getVariableAssignmentStringWithMultipleValues(EngineMessage.NETWORKS_ALREADY_ATTACHED_TO_IFACES, networkName)));
}
Aggregations