Search in sources :

Example 1 with AddIpToVmNicCmd

use of com.cloud.api.command.user.vm.AddIpToVmNicCmd in project cosmic by MissionCriticalCloud.

the class AddIpToVmNicTest method testCreateFailure.

@Test
public void testCreateFailure() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    final NetworkService networkService = Mockito.mock(NetworkService.class);
    final AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class);
    Mockito.when(networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.anyString())).thenReturn(null);
    ipTonicCmd._networkService = networkService;
    try {
        ipTonicCmd.execute();
    } catch (final InsufficientAddressCapacityException e) {
        throw new InvalidParameterValueException("Allocating guest ip for nic failed");
    }
}
Also used : AddIpToVmNicCmd(com.cloud.api.command.user.vm.AddIpToVmNicCmd) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NetworkService(com.cloud.network.NetworkService) Test(org.junit.Test)

Example 2 with AddIpToVmNicCmd

use of com.cloud.api.command.user.vm.AddIpToVmNicCmd in project cosmic by MissionCriticalCloud.

the class AddIpToVmNicTest method testCreateSuccess.

@Test
public void testCreateSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    final NetworkService networkService = Mockito.mock(NetworkService.class);
    final AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class);
    final NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class);
    Mockito.when(networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.anyString())).thenReturn(secIp);
    ipTonicCmd._networkService = networkService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    final NicSecondaryIpResponse ipres = Mockito.mock(NicSecondaryIpResponse.class);
    Mockito.when(responseGenerator.createSecondaryIPToNicResponse(secIp)).thenReturn(ipres);
    ipTonicCmd._responseGenerator = responseGenerator;
    ipTonicCmd.execute();
}
Also used : NicSecondaryIpResponse(com.cloud.api.response.NicSecondaryIpResponse) AddIpToVmNicCmd(com.cloud.api.command.user.vm.AddIpToVmNicCmd) ResponseGenerator(com.cloud.api.ResponseGenerator) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) NetworkService(com.cloud.network.NetworkService) Test(org.junit.Test)

Aggregations

AddIpToVmNicCmd (com.cloud.api.command.user.vm.AddIpToVmNicCmd)2 NetworkService (com.cloud.network.NetworkService)2 Test (org.junit.Test)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 NicSecondaryIpResponse (com.cloud.api.response.NicSecondaryIpResponse)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1 NicSecondaryIp (com.cloud.vm.NicSecondaryIp)1