use of org.apache.cloudstack.api.command.user.vm.ScaleVMCmd 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 org.apache.cloudstack.api.command.user.vm.ScaleVMCmd 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();
}
}
use of org.apache.cloudstack.api.command.user.vm.ScaleVMCmd 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();
}
}
use of org.apache.cloudstack.api.command.user.vm.ScaleVMCmd in project cloudstack by apache.
the class UserVmManagerTest method testScaleVMF2.
// Test scaleVm on equal service offerings.
@Test(expected = InvalidParameterValueException.class)
public void testScaleVMF2() 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();
doReturn(VirtualMachine.State.Running).when(_vmInstance).getState();
doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
doNothing().when(_itMgr).checkIfCanUpgrade(_vmMock, _offeringVo);
ServiceOffering so1 = getSvcoffering(512);
ServiceOffering so2 = getSvcoffering(256);
when(_offeringDao.findById(anyLong())).thenReturn((ServiceOfferingVO) so1);
when(_offeringDao.findByIdIncludingRemoved(anyLong(), anyLong())).thenReturn((ServiceOfferingVO) so1);
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();
}
}
Aggregations