Search in sources :

Example 56 with UserVO

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

the class UserVmManagerTest method testScaleVMF4.

// Test scaleVm for Running vm. Full positive test.
public void testScaleVMF4() 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);
    //UserContext.current().setEventDetails("Vm Id: "+getId());
    //Account account = (Account) new AccountVO("testaccount", 1L, "networkdomain", (short) 0, 1);
    //AccountVO(String accountName, long domainId, String networkDomain, short type, int regionId)
    //UserContext.registerContext(1, account, null, true);
    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.Running).when(_vmInstance).getState();
    //when(ApiDBUtils.getCpuOverprovisioningFactor()).thenReturn(3f);
    when(_capacityMgr.checkIfHostHasCapacity(anyLong(), anyInt(), anyLong(), anyBoolean(), anyFloat(), anyFloat(), anyBoolean())).thenReturn(false);
    when(_itMgr.reConfigureVm(_vmInstance.getUuid(), so1, false)).thenReturn(_vmInstance);
    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)

Example 57 with UserVO

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

the class UserVmManagerTest method testUpdateVmNicIpSuccess2.

@Test
public void testUpdateVmNicIpSuccess2() 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>();
    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(_dcDao.findById(anyLong())).thenReturn(_dcMock);
    when(_dcMock.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);
    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 58 with UserVO

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

the class NetworkACLManagerTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    final Account account = new AccountVO("testaccount", 1, "testdomain", (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, account);
    acl = Mockito.mock(NetworkACLVO.class);
    aclItem = Mockito.mock(NetworkACLItemVO.class);
}
Also used : Account(com.cloud.user.Account) NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) Before(org.junit.Before)

Example 59 with UserVO

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

the class NetworkACLServiceTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    Account account = new AccountVO("testaccount", 1, "testdomain", (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);
    createACLItemCmd = new CreateNetworkACLCmd() {

        @Override
        public Long getACLId() {
            return 3L;
        }

        @Override
        public Integer getNumber() {
            return 1;
        }

        @Override
        public String getProtocol() {
            return "TCP";
        }
    };
    acl = new NetworkACLVO() {

        @Override
        public Long getVpcId() {
            return 1L;
        }

        @Override
        public long getId() {
            return 1L;
        }
    };
    aclItem = new NetworkACLItemVO() {

        @Override
        public long getAclId() {
            return 4L;
        }
    };
}
Also used : Account(com.cloud.user.Account) NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) UserVO(com.cloud.user.UserVO) CreateNetworkACLCmd(org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd) AccountVO(com.cloud.user.AccountVO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) Before(org.junit.Before)

Example 60 with UserVO

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

the class UserVmManagerTest method testRestoreVMF5.

// Test restoreVM on providing new ISO Id, when VM(deployed using ISO) is in running state
@Test
public void testRestoreVMF5() 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(null).when(_volumeMock).getTemplateId();
    doReturn(3L).when(_vmMock).getIsoId();
    doReturn(ImageFormat.ISO).when(_templateMock).getFormat();
    when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
    when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
    doNothing().when(_vmMock).setIsoId(14L);
    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();
    }
    verify(_vmMock, times(1)).setIsoId(14L);
}
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)

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