use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method modifiedAttachmentNotRemovedAttachmentModifiedAndRemoved.
@Test
public void modifiedAttachmentNotRemovedAttachmentModifiedAndRemoved() {
NetworkAttachment modifiedAttachment = createNetworkAttachment(new Network());
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedNetworkAttachments(modifiedAttachment)).build();
assertThat(validator.modifiedAttachmentNotRemoved(modifiedAttachment), failsWith(EngineMessage.NETWORK_ATTACHMENT_IN_BOTH_LISTS, ReplacementUtils.createSetVariableString("NETWORK_ATTACHMENT_IN_BOTH_LISTS_ENTITY", modifiedAttachment.getId().toString())));
}
use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testAddNetworkToNicAlongWithAddingItIntoBond.
// TODO MM: same test for vlan.
@Test
public void testAddNetworkToNicAlongWithAddingItIntoBond() {
Network networkA = createNetworkWithName("networkA");
VdsNetworkInterface nicA = createNic("nicA");
VdsNetworkInterface nicB = createNic("nicB");
NetworkAttachment networkAttachment = createNetworkAttachment(networkA, (Guid) null);
networkAttachment.setNicId(nicA.getId());
networkAttachment.setNicName(nicA.getName());
networkAttachment.setNetworkId(networkA.getId());
networkAttachment.setNetworkName(networkA.getName());
CreateOrUpdateBond createOrUpdateBond = createNewCreateOrUpdateBond(Guid.newGuid(), "bond1", nicA.getName(), nicB.getName());
addNetworkIdToNetworkDaoMock(networkA);
addNetworkToClusterDaoMock(networkA.getId());
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(networkAttachment).addBonds(createOrUpdateBond).build()).addExistingInterfaces(nicA, nicB).addNetworks(networkA).build();
ValidationResult validate = validator.validate();
assertThat(validate, not(isValid()));
EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ADDED_TO_BOND_AND_NETWORK_IS_ATTACHED_TO_IT_AT_THE_SAME_TIME;
assertThat(validate, failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, nicA.getName()), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, networkA.getName())));
}
use of org.ovirt.engine.core.common.businessentities.network.Network in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidateCustomProperties.
@Test
public void testValidateCustomProperties() throws Exception {
Network networkA = createNetworkWithName("networkA");
NetworkAttachment networkAttachment = createNetworkAttachment(networkA);
Map<String, String> customProperties = new HashMap<>();
customProperties.put("a", "b");
networkAttachment.setProperties(customProperties);
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(networkAttachment)).addNetworks(networkA).build();
// we do not test SimpleCustomPropertiesUtil here, we just state what happens if it does not find ValidationError
SimpleCustomPropertiesUtil simpleCustomPropertiesUtilMock = mock(SimpleCustomPropertiesUtil.class);
assertThat(validator.validateCustomProperties(simpleCustomPropertiesUtilMock, Collections.emptyMap(), Collections.emptyMap()), isValid());
}
use of org.ovirt.engine.core.common.businessentities.network.Network 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.Network in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method modifiedAttachmentNotRemovedAttachmentModifiedButNotRemovedValid.
@Test
public void modifiedAttachmentNotRemovedAttachmentModifiedButNotRemovedValid() {
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().build();
NetworkAttachment modifiedAttachment = createNetworkAttachment(new Network());
assertThat(validator.modifiedAttachmentNotRemoved(modifiedAttachment), isValid());
}
Aggregations