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();
}
}
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();
}
}
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();
}
}
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());
}
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);
}
}
Aggregations