Search in sources :

Example 56 with AccountVO

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

the class UserVmManagerTest method testMoveVmToUser2.

// Test Move VM b/w accounts where caller doesn't have access to the old or new account
@Test(expected = PermissionDeniedException.class)
public void testMoveVmToUser2() 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) 1, UUID.randomUUID().toString());
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    Account oldAccount = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    Account newAccount = new AccountVO("testaccount", 1, "networkdomain", (short) 1, UUID.randomUUID().toString());
    UserVmVO vm = new UserVmVO(10L, "test", "test", 1L, HypervisorType.Any, 1L, false, false, 1L, 1L, 1, 5L, "test", "test", 1L);
    vm.setState(VirtualMachine.State.Stopped);
    when(_vmDao.findById(anyLong())).thenReturn(vm);
    when(_accountService.getActiveAccountById(anyLong())).thenReturn(oldAccount);
    when(_accountMgr.finalizeOwner(any(Account.class), anyString(), anyLong(), anyLong())).thenReturn(newAccount);
    doThrow(new PermissionDeniedException("Access check failed")).when(_accountMgr).checkAccess(any(Account.class), any(AccessType.class), any(Boolean.class), any(ControlledEntity.class));
    CallContext.register(user, caller);
    when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true);
    try {
        _userVmMgr.moveVMToUser(cmd);
    } finally {
        CallContext.unregister();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ControlledEntity(org.apache.cloudstack.acl.ControlledEntity) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) AssignVMCmd(org.apache.cloudstack.api.command.admin.vm.AssignVMCmd) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) AccountVO(com.cloud.user.AccountVO) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType) Test(org.junit.Test)

Example 57 with AccountVO

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

the class UserVmManagerTest method testUpdateVmNicIpFailure3.

// vm is stopped in shared network in advanced zone
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure3() 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.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(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 58 with AccountVO

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

the class UserVmManagerTest method testScaleVMF1.

// Test scaleVm on incompatible HV.
@Test(expected = InvalidParameterValueException.class)
public void testScaleVMF1() 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);
    // UserContext.current().setEventDetails("Vm Id: "+getId());
    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);
    //AccountVO(String accountName, long domainId, String networkDomain, short type, int regionId)
    doReturn(VirtualMachine.State.Running).when(_vmInstance).getState();
    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) ScaleVMCmd(org.apache.cloudstack.api.command.user.vm.ScaleVMCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 59 with AccountVO

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

the class CreateNetworkOfferingTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    ConfigurationVO configVO = new ConfigurationVO("200", "200", "200", "200", "200", "200");
    Mockito.when(configDao.findByName(Matchers.anyString())).thenReturn(configVO);
    Mockito.when(offDao.persist(Matchers.any(NetworkOfferingVO.class))).thenReturn(new NetworkOfferingVO());
    Mockito.when(offDao.persist(Matchers.any(NetworkOfferingVO.class), Matchers.anyMap())).thenReturn(new NetworkOfferingVO());
    Mockito.when(mapDao.persist(Matchers.any(NetworkOfferingServiceMapVO.class))).thenReturn(new NetworkOfferingServiceMapVO());
    Mockito.when(accountMgr.getSystemUser()).thenReturn(new UserVO(1));
    Mockito.when(accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
    CallContext.register(accountMgr.getSystemUser(), accountMgr.getSystemAccount());
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) UserVO(com.cloud.user.UserVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 60 with AccountVO

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

the class VpcApiUnitTest method validateNtwkOffForVpcInvalidMissingSourceNat.

//2) invalid offering - source nat is not included
@Test(expected = InvalidParameterValueException.class)
public void validateNtwkOffForVpcInvalidMissingSourceNat() {
    boolean result = false;
    try {
        _vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", _vo, "10.1.1.1", new AccountVO(), null);
        result = true;
    } finally {
        assertFalse("Validate network offering: TEST FAILED, can't use network offering without SourceNat service", result);
    }
}
Also used : AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Aggregations

AccountVO (com.cloud.user.AccountVO)139 Account (com.cloud.user.Account)65 Test (org.junit.Test)52 UserVO (com.cloud.user.UserVO)44 Field (java.lang.reflect.Field)41 ArrayList (java.util.ArrayList)40 DomainVO (com.cloud.domain.DomainVO)32 AccountManager (com.cloud.user.AccountManager)27 Before (org.junit.Before)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)21 Date (java.util.Date)16 QuotaAccountVO (org.apache.cloudstack.quota.vo.QuotaAccountVO)16 DomainDao (com.cloud.domain.dao.DomainDao)14 SslCertDao (com.cloud.network.dao.SslCertDao)14 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)13 NetworkDao (com.cloud.network.dao.NetworkDao)13 NetworkVO (com.cloud.network.dao.NetworkVO)13