use of org.ovirt.engine.core.common.businessentities.network.NicLabel in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method validateSlaveHasNoLabelsOldLabelWasMovedToAnotherNicValid.
@Test
public void validateSlaveHasNoLabelsOldLabelWasMovedToAnotherNicValid() {
VdsNetworkInterface slave = createNic("slave");
slave.setLabels(Collections.singleton("lbl1"));
NicLabel nicLabel = new NicLabel(Guid.newGuid(), slave.getName() + "not", "lbl1");
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addLabels(nicLabel)).addExistingInterfaces(slave).build();
assertThat(validator.validateSlaveHasNoLabels(slave.getName()), isValid());
}
use of org.ovirt.engine.core.common.businessentities.network.NicLabel in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method notMovingLabeledNetworkToDifferentNicCommonTest.
private void notMovingLabeledNetworkToDifferentNicCommonTest(boolean nicContainslabel, boolean labelShouldBeRemovedFromNic, boolean labelShouldBeAddedToNic, boolean valid) {
VdsNetworkInterface nic = createNic("nicWithLabel");
if (nicContainslabel) {
nic.setLabels(Collections.singleton("lbl1"));
}
Network movedNetwork = createNetworkWithNameAndLabel("net", "lbl1");
NetworkAttachment existingAttachment = createNetworkAttachment(movedNetwork, nic);
NetworkAttachment updatedAttachment = new NetworkAttachment(existingAttachment);
updatedAttachment.setNicId(Guid.newGuid());
updatedAttachment.setNicName(nic.getName() + "not");
HostSetupNetworksParameters params = new HostSetupNetworksParameters(host.getId());
if (labelShouldBeRemovedFromNic) {
params.getRemovedLabels().add("lbl1");
}
if (labelShouldBeAddedToNic) {
NicLabel nicLabel = new NicLabel(nic.getId(), nic.getName(), "lbl1");
params.getLabels().add(nicLabel);
}
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(params).addExistingInterfaces(nic).addExistingAttachments(existingAttachment).addNetworks(movedNetwork).build();
if (valid) {
assertThat(validator.notMovingLabeledNetworkToDifferentNic(updatedAttachment), isValid());
} else {
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_MOVE_LABELED_NETWORK_TO_ANOTHER_NIC;
assertThat(validator.notMovingLabeledNetworkToDifferentNic(updatedAttachment), failsWith(engineMessage, ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, movedNetwork.getName()), ReplacementUtils.getVariableAssignmentString(engineMessage, movedNetwork.getLabel())));
}
}
use of org.ovirt.engine.core.common.businessentities.network.NicLabel in project ovirt-engine by oVirt.
the class HostSetupNetworksModel method createNicToLabelModels.
private Map<String, List<NetworkLabelModel>> createNicToLabelModels(Map<String, Set<LogicalNetworkModel>> nicNameToNetworkModels, List<LogicalNetworkModel> errorLabelNetworks, Map<String, String> labelToDesiredNicName) {
Map<String, List<NetworkLabelModel>> nicToLabelModels = new HashMap<>();
for (NicLabel nicLabel : hostSetupNetworksParametersData.getLabels()) {
String label = nicLabel.getLabel();
String nicName = nicLabel.getNicName();
labelToDesiredNicName.put(label, nicName);
Collection<LogicalNetworkModel> nicNetworks = nicNameToNetworkModels.get(nicName);
NetworkLabelModel labelModel = networkLabelModelByLabel.get(label);
// $NON-NLS-1$
assert labelModel != null : "NicLabel should have a NetworkLabelModel";
markNetworkModelsAsAttachedViaLabel(errorLabelNetworks, nicNetworks, labelModel);
if (nicToLabelModels.get(nicName) == null) {
nicToLabelModels.put(nicName, new ArrayList<NetworkLabelModel>());
}
nicToLabelModels.get(nicName).add(labelModel);
}
return nicToLabelModels;
}
use of org.ovirt.engine.core.common.businessentities.network.NicLabel in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method attachmentAndNicLabelReferenceSameLabelCommonTest.
private void attachmentAndNicLabelReferenceSameLabelCommonTest(boolean referenceSameNic, boolean valid) {
VdsNetworkInterface nic = createNic("nic");
final String labelName = "lbl1";
Network network = createNetworkWithNameAndLabel("net", labelName);
NetworkAttachment attachment = createNetworkAttachment(network, nic);
NicLabel nicLabel = referenceSameNic ? new NicLabel(nic.getId(), nic.getName(), labelName) : new NicLabel(Guid.newGuid(), nic.getName() + "not", labelName);
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addLabels(nicLabel)).addNetworks(network).addExistingInterfaces(nic).build();
if (valid) {
assertThat(validator.validateAttachmentAndNicReferenceSameLabelNotConflict(attachment), isValid());
} else {
EngineMessage engineMessage = EngineMessage.NETWORK_SHOULD_BE_ATTACHED_VIA_LABEL_TO_ANOTHER_NIC;
assertThat(validator.validateAttachmentAndNicReferenceSameLabelNotConflict(attachment), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, network.getName()), ReplacementUtils.createSetVariableString("nicName", attachment.getNicName()), ReplacementUtils.createSetVariableString("labeledNicName", nicLabel.getNicName())));
}
}
use of org.ovirt.engine.core.common.businessentities.network.NicLabel in project ovirt-engine by oVirt.
the class NicLabelValidatorTest method assertLabelBeingAttachedToValidBondFailed.
private void assertLabelBeingAttachedToValidBondFailed(HostSetupNetworksParameters params, VdsNetworkInterface nic) {
List<VdsNetworkInterface> nics = Collections.singletonList(nic);
NicLabel nicLabel = new NicLabel(nic.getId(), nic.getName(), "lbl1");
assertThat(createNicLabelValidator(params, nics).labelBeingAttachedToValidBond(nicLabel), failsWith(EngineMessage.IMPROPER_BOND_IS_LABELED, ReplacementUtils.createSetVariableString(HostInterfaceValidator.VAR_BOND_NAME, nic.getName())));
}
Aggregations