Search in sources :

Example 51 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class TemplateManagerImplTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    AccountVO account = new AccountVO("admin", 1L, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
}
Also used : UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 52 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class UserVmManagerTest method testMoveVmToUser1.

// Test Move VM b/w accounts where caller is not ROOT/Domain admin
@Test(expected = InvalidParameterValueException.class)
public void testMoveVmToUser1() throws Exception {
    AssignVMCmd cmd = new AssignVMCmd();
    Class<?> _class = cmd.getClass();
    Field virtualmachineIdField = _class.getDeclaredField("virtualMachineId");
    virtualmachineIdField.setAccessible(true);
    virtualmachineIdField.set(cmd, 1L);
    Field accountNameField = _class.getDeclaredField("accountName");
    accountNameField.setAccessible(true);
    accountNameField.set(cmd, "account");
    Field domainIdField = _class.getDeclaredField("domainId");
    domainIdField.setAccessible(true);
    domainIdField.set(cmd, 1L);
    // caller is of type 0
    Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, caller);
    try {
        _userVmMgr.moveVMToUser(cmd);
    } finally {
        CallContext.unregister();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) AssignVMCmd(org.apache.cloudstack.api.command.admin.vm.AssignVMCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 53 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class UserVmManagerTest method testUpdateVmNicIpFailure2.

// vm is stopped in isolated network in advanced zone
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure2() throws Exception {
    UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
    Class<?> _class = cmd.getClass();
    Field virtualmachineIdField = _class.getDeclaredField("nicId");
    virtualmachineIdField.setAccessible(true);
    virtualmachineIdField.set(cmd, 1L);
    Field accountNameField = _class.getDeclaredField("ipAddr");
    accountNameField.setAccessible(true);
    accountNameField.set(cmd, "10.10.10.10");
    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();
    List<Service> services = new ArrayList<Service>();
    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(_dcDao.findById(anyLong())).thenReturn(_dcMock);
    when(_dcMock.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_ipAddrMgr.allocateGuestIP(Mockito.eq(_networkMock), anyString())).thenReturn(null);
    Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    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) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) ResourceLimitService(com.cloud.user.ResourceLimitService) UpdateVmNicIpCmd(org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 54 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class UserVmManagerTest method testRestoreVMF4.

// Test restoreVM on providing new template Id, when VM is in running state
@Test
public void testRestoreVMF4() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    doReturn(VirtualMachine.State.Running).when(_vmMock).getState();
    when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
    when(_volsDao.findByInstanceAndType(314L, Volume.Type.ROOT)).thenReturn(_rootVols);
    doReturn(false).when(_rootVols).isEmpty();
    when(_rootVols.get(eq(0))).thenReturn(_volumeMock);
    doReturn(3L).when(_volumeMock).getTemplateId();
    doReturn(ImageFormat.VHD).when(_templateMock).getFormat();
    when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
    when(_storageMgr.allocateDuplicateVolume(_volumeMock, 14L)).thenReturn(_volumeMock);
    when(_templateMock.getGuestOSId()).thenReturn(5L);
    doNothing().when(_vmMock).setGuestOSId(anyLong());
    doNothing().when(_vmMock).setTemplateId(3L);
    when(_vmDao.update(314L, _vmMock)).thenReturn(true);
    when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
    doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
    when(_volumeMock.getId()).thenReturn(3L);
    doNothing().when(_volsDao).detachVolume(anyLong());
    List<VMSnapshotVO> mockList = mock(List.class);
    when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(mockList);
    when(mockList.size()).thenReturn(0);
    when(_templateMock.getUuid()).thenReturn("b1a3626e-72e0-4697-8c7c-a110940cc55d");
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    StoragePoolVO storagePool = new StoragePoolVO();
    storagePool.setManaged(false);
    when(_storagePoolDao.findById(anyLong())).thenReturn(storagePool);
    CallContext.register(user, account);
    try {
        _userVmMgr.restoreVMInternal(_account, _vmMock, 14L);
    } finally {
        CallContext.unregister();
    }
}
Also used : VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 55 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class UserVmManagerTest method testScaleVMF3.

// Test scaleVm for Stopped vm.
//@Test(expected=InvalidParameterValueException.class)
public void testScaleVMF3() throws Exception {
    ScaleVMCmd cmd = new ScaleVMCmd();
    Class<?> _class = cmd.getClass();
    Field idField = _class.getDeclaredField("id");
    idField.setAccessible(true);
    idField.set(cmd, 1L);
    Field serviceOfferingIdField = _class.getDeclaredField("serviceOfferingId");
    serviceOfferingIdField.setAccessible(true);
    serviceOfferingIdField.set(cmd, 1L);
    when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
    doReturn(Hypervisor.HypervisorType.XenServer).when(_vmInstance).getHypervisorType();
    ServiceOffering so1 = getSvcoffering(512);
    ServiceOffering so2 = getSvcoffering(256);
    when(_entityMgr.findById(eq(ServiceOffering.class), anyLong())).thenReturn(so2);
    when(_entityMgr.findById(ServiceOffering.class, 1L)).thenReturn(so1);
    doReturn(VirtualMachine.State.Stopped).when(_vmInstance).getState();
    when(_vmDao.findById(anyLong())).thenReturn(null);
    doReturn(true).when(_itMgr).upgradeVmDb(anyLong(), anyLong());
    //when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, UUID.randomUUID().toString());
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    try {
        _userVmMgr.upgradeVirtualMachine(cmd);
    } finally {
        CallContext.unregister();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ServiceOffering(com.cloud.offering.ServiceOffering) ScaleVMCmd(org.apache.cloudstack.api.command.user.vm.ScaleVMCmd) AccountVO(com.cloud.user.AccountVO)

Aggregations

UserVO (com.cloud.user.UserVO)72 AccountVO (com.cloud.user.AccountVO)44 Account (com.cloud.user.Account)42 Test (org.junit.Test)23 Before (org.junit.Before)21 ArrayList (java.util.ArrayList)19 Field (java.lang.reflect.Field)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 HashMap (java.util.HashMap)11 DomainVO (com.cloud.domain.DomainVO)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 Service (com.cloud.network.Network.Service)7 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 LinkedHashMap (java.util.LinkedHashMap)5 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)5