Search in sources :

Example 1 with UpdateVmNicIpCmd

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

the class UserVmManagerTest method testUpdateVmNicIpSuccess1.

@Test
public void testUpdateVmNicIpSuccess1() 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);
    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.Stopped);
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
    when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
    when(_networkMock.getState()).thenReturn(Network.State.Implemented);
    when(_networkMock.getDataCenterId()).thenReturn(3L);
    when(_networkMock.getGuestType()).thenReturn(GuestType.Isolated);
    when(zoneRepository.findOne(anyLong())).thenReturn(zone);
    when(zone.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_ipAddrMgr.allocateGuestIP(Mockito.eq(_networkMock), anyString())).thenReturn("10.10.10.10");
    doNothing().when(_networkMgr).implementNetworkElementsAndResources(Mockito.any(DeployDestination.class), Mockito.any(ReservationContext.class), Mockito.eq(_networkMock), Mockito.eq(_networkOfferingMock));
    when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
    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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) DeployDestination(com.cloud.deploy.DeployDestination) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) ResourceLimitService(com.cloud.user.ResourceLimitService) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 2 with UpdateVmNicIpCmd

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

the class UserVmManagerTest method testUpdateVmNicIpSuccess2.

@Test
public void testUpdateVmNicIpSuccess2() 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);
    doReturn(9L).when(_networkMock).getNetworkOfferingId();
    when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
    doReturn(10L).when(_networkOfferingMock).getId();
    final List<Service> services = new ArrayList<>();
    when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
    when(_vmMock.getState()).thenReturn(State.Running);
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
    when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
    when(_networkMock.getState()).thenReturn(Network.State.Implemented);
    when(_networkMock.getDataCenterId()).thenReturn(3L);
    when(_networkMock.getGuestType()).thenReturn(GuestType.Shared);
    when(zoneRepository.findOne(anyLong())).thenReturn(zone);
    when(zone.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_ipAddrMgr.allocatePublicIpForGuestNic(Mockito.eq(_networkMock), anyLong(), Mockito.eq(_accountMock), anyString())).thenReturn("10.10.10.10");
    when(_ipAddressDao.findByIpAndSourceNetworkId(anyLong(), anyString())).thenReturn(null);
    when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
    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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) ResourceLimitService(com.cloud.user.ResourceLimitService) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 3 with UpdateVmNicIpCmd

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

the class UserVmManagerTest method testUpdateVmNicIpFailure2.

// vm is stopped in isolated network in advanced zone
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure2() 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);
    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.Stopped);
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
    when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
    when(_networkMock.getState()).thenReturn(Network.State.Implemented);
    when(_networkMock.getDataCenterId()).thenReturn(3L);
    when(_networkMock.getGuestType()).thenReturn(GuestType.Isolated);
    when(zoneRepository.findOne(anyLong())).thenReturn(zone);
    when(zone.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_ipAddrMgr.allocateGuestIP(Mockito.eq(_networkMock), anyString())).thenReturn(null);
    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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) ResourceLimitService(com.cloud.user.ResourceLimitService) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 4 with UpdateVmNicIpCmd

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

the class UserVmManagerTest method testUpdateVmNicIpFailure3.

// vm is stopped in shared network in advanced zone
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure3() 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);
    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.Stopped);
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
    when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
    when(_networkMock.getState()).thenReturn(Network.State.Implemented);
    when(_networkMock.getDataCenterId()).thenReturn(3L);
    when(_networkMock.getGuestType()).thenReturn(GuestType.Shared);
    when(zoneRepository.findOne(anyLong())).thenReturn(zone);
    when(zone.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_ipAddrMgr.allocatePublicIpForGuestNic(Mockito.eq(_networkMock), anyLong(), Mockito.eq(_accountMock), anyString())).thenReturn(null);
    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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) ResourceLimitService(com.cloud.user.ResourceLimitService) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 5 with UpdateVmNicIpCmd

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

the class UpdateVmNicIpTest method testSuccess.

@Test
public void testSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    final UserVmService userVmService = Mockito.mock(UserVmService.class);
    updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
    final UserVm userVm = Mockito.mock(UserVm.class);
    Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(userVm);
    updateVmNicIpCmd._userVmService = userVmService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    final List<UserVmResponse> list = new LinkedList<>();
    final UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
    list.add(userVmResponse);
    Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
    updateVmNicIpCmd._responseGenerator = responseGenerator;
    updateVmNicIpCmd.execute();
}
Also used : UserVm(com.cloud.uservm.UserVm) UserVmService(com.cloud.vm.UserVmService) ResponseGenerator(com.cloud.api.ResponseGenerator) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) UserVmResponse(com.cloud.api.response.UserVmResponse) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

UpdateVmNicIpCmd (com.cloud.api.command.user.vm.UpdateVmNicIpCmd)7 Test (org.junit.Test)7 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)5 VolumeOrchestrationService (com.cloud.engine.orchestration.service.VolumeOrchestrationService)5 Service (com.cloud.network.Network.Service)5 Account (com.cloud.user.Account)5 AccountService (com.cloud.user.AccountService)5 AccountVO (com.cloud.user.AccountVO)5 ResourceLimitService (com.cloud.user.ResourceLimitService)5 UserVO (com.cloud.user.UserVO)5 Field (java.lang.reflect.Field)5 ArrayList (java.util.ArrayList)5 UserVmService (com.cloud.vm.UserVmService)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 ServerApiException (com.cloud.api.ServerApiException)1 UserVmResponse (com.cloud.api.response.UserVmResponse)1 DeployDestination (com.cloud.deploy.DeployDestination)1 UserVm (com.cloud.uservm.UserVm)1 LinkedList (java.util.LinkedList)1