Search in sources :

Example 1 with FindActiveVmsUsingNetwork

use of org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork in project ovirt-engine by oVirt.

the class HostSetupNetworksValidatorTest method testValidateNotRemovingUsedNetworkByVmsWhenUsedByVms.

@Test
public void testValidateNotRemovingUsedNetworkByVmsWhenUsedByVms() {
    String nameOfNetworkA = "networkA";
    Network networkA = createNetworkWithName(nameOfNetworkA);
    NetworkAttachment networkAttachmentA = createNetworkAttachment(networkA);
    VdsNetworkInterface nicA = createNic("nicA");
    networkAttachmentA.setNicId(nicA.getId());
    final HostSetupNetworksValidator underTest = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedNetworkAttachments(networkAttachmentA).build()).addExistingInterfaces(Collections.singletonList(nicA)).addExistingAttachments(Collections.singletonList(networkAttachmentA)).addNetworks(Collections.singletonList(networkA)).build();
    List<String> vmNames = Arrays.asList("vmName1", "vmName2");
    when(findActiveVmsUsingNetwork.findNamesOfActiveVmsUsingNetworks(any(), anyCollection())).thenReturn(vmNames);
    final List<String> removedNetworkNames = Collections.singletonList(nameOfNetworkA);
    assertThat(underTest.validateNotRemovingUsedNetworkByVms(nameOfNetworkA), failsWith(EngineMessage.NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS, Stream.concat(ReplacementUtils.replaceWith(VAR_NETWORK_NAME, removedNetworkNames, SEPARATOR).stream(), ReplacementUtils.replaceWith(VAR_VM_NAMES, vmNames, SEPARATOR).stream()).collect(Collectors.toList())));
    verify(findActiveVmsUsingNetwork).findNamesOfActiveVmsUsingNetworks(eq(host.getId()), collectionArgumentCaptor.capture());
    assertThat(collectionArgumentCaptor.getValue(), contains(nameOfNetworkA));
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)1 Network (org.ovirt.engine.core.common.businessentities.network.Network)1 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)1 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)1