use of com.cloud.api.command.user.vm.UpdateVmNicIpCmd in project cosmic by MissionCriticalCloud.
the class UpdateVmNicIpTest method testFailure.
@Test
public void testFailure() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
final UserVmService userVmService = Mockito.mock(UserVmService.class);
updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(null);
updateVmNicIpCmd._userVmService = userVmService;
updateVmNicIpCmd._responseGenerator = responseGenerator;
try {
updateVmNicIpCmd.execute();
} catch (final ServerApiException exception) {
Assert.assertEquals("Failed to update ip address on vm NIC. Refer to server logs for details.", exception.getDescription());
}
}
use of com.cloud.api.command.user.vm.UpdateVmNicIpCmd in project cosmic by MissionCriticalCloud.
the class UserVmManagerTest method testUpdateVmNicIpFailure1.
// vm is running in network with dhcp support
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure1() throws Exception {
final UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
final Class<?> _class = cmd.getClass();
final Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
final Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
final NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
final List<Service> services = new ArrayList<>();
services.add(Service.Dhcp);
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Running);
final Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
Aggregations