mirror of https://github.com/apache/cloudstack.git
Fix build regression from 08e5993a45
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
f412e07d71
commit
48377a3f12
|
|
@ -984,6 +984,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
hosts = new long[] {userVm.getLastHostId()};
|
||||
}
|
||||
|
||||
final String errorMsg = "The VM must be stopped or the disk detached in order to resize with the XenServer Hypervisor.";
|
||||
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
|
||||
|
||||
if (storagePool.isManaged() && storagePool.getHypervisor() == HypervisorType.Any && hosts != null && hosts.length > 0) {
|
||||
|
|
|
|||
|
|
@ -5028,35 +5028,29 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
throw ex;
|
||||
}
|
||||
|
||||
// If target VM has associated VM snapshots then don't allow restore of VM
|
||||
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
|
||||
if (vmSnapshots.size() > 0) {
|
||||
throw new InvalidParameterValueException("Unable to restore VM, please remove VM snapshots before restoring VM");
|
||||
}
|
||||
|
||||
VolumeVO root = rootVols.get(0);
|
||||
if ( !Volume.State.Allocated.equals(root.getState()) || newTemplateId != null ){
|
||||
Long templateId = root.getTemplateId();
|
||||
boolean isISO = false;
|
||||
if (templateId == null) {
|
||||
// Assuming that for a vm deployed using ISO, template ID is set to NULL
|
||||
isISO = true;
|
||||
templateId = vm.getIsoId();
|
||||
}
|
||||
Long templateId = root.getTemplateId();
|
||||
boolean isISO = false;
|
||||
if(templateId == null) {
|
||||
// Assuming that for a vm deployed using ISO, template ID is set to NULL
|
||||
isISO = true;
|
||||
templateId = vm.getIsoId();
|
||||
}
|
||||
|
||||
// If target VM has associated VM snapshots then don't allow restore of VM
|
||||
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
|
||||
if (vmSnapshots.size() > 0) {
|
||||
throw new InvalidParameterValueException("Unable to restore VM, please remove VM snapshots before restoring VM");
|
||||
}
|
||||
|
||||
VMTemplateVO template = null;
|
||||
//newTemplateId can be either template or ISO id. In the following snippet based on the vm deployment (from template or ISO) it is handled accordingly
|
||||
if (newTemplateId != null) {
|
||||
template = _templateDao.findById(newTemplateId);
|
||||
_accountMgr.checkAccess(caller, null, true, template);
|
||||
if (isISO) {
|
||||
if (!template.getFormat().equals(ImageFormat.ISO)) {
|
||||
throw new InvalidParameterValueException("Invalid ISO id provided to restore the VM ");
|
||||
}
|
||||
} else {
|
||||
if (template.getFormat().equals(ImageFormat.ISO)) {
|
||||
throw new InvalidParameterValueException("Invalid template id provided to restore the VM ");
|
||||
}
|
||||
VMTemplateVO template = null;
|
||||
//newTemplateId can be either template or ISO id. In the following snippet based on the vm deployment (from template or ISO) it is handled accordingly
|
||||
if(newTemplateId != null) {
|
||||
template = _templateDao.findById(newTemplateId);
|
||||
_accountMgr.checkAccess(caller, null, true, template);
|
||||
if (isISO) {
|
||||
if (!template.getFormat().equals(ImageFormat.ISO)) {
|
||||
throw new InvalidParameterValueException("Invalid ISO id provided to restore the VM ");
|
||||
}
|
||||
} else {
|
||||
if (template.getFormat().equals(ImageFormat.ISO)) {
|
||||
|
|
|
|||
|
|
@ -32,9 +32,12 @@ import static org.mockito.Mockito.verify;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.cloud.vm.snapshot.VMSnapshotVO;
|
||||
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
|
@ -99,6 +102,7 @@ public class UserVmManagerTest {
|
|||
@Mock UserDao _userDao;
|
||||
@Mock UserVmDao _vmDao;
|
||||
@Mock VMInstanceDao _vmInstanceDao;
|
||||
@Mock VMSnapshotDao _vmSnapshotDao;
|
||||
@Mock VMTemplateDao _templateDao;
|
||||
@Mock VolumeDao _volsDao;
|
||||
@Mock RestoreVMCmd _restoreVMCmd;
|
||||
|
|
@ -123,6 +127,7 @@ public class UserVmManagerTest {
|
|||
|
||||
_userVmMgr._vmDao = _vmDao;
|
||||
_userVmMgr._vmInstanceDao = _vmInstanceDao;
|
||||
_userVmMgr._vmSnapshotDao = _vmSnapshotDao;
|
||||
_userVmMgr._templateDao = _templateDao;
|
||||
_userVmMgr._volsDao = _volsDao;
|
||||
_userVmMgr._itMgr = _itMgr;
|
||||
|
|
@ -323,6 +328,10 @@ public class UserVmManagerTest {
|
|||
|
||||
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
|
||||
|
||||
List<VMSnapshotVO> vmSnapshots = new ArrayList<VMSnapshotVO>();
|
||||
vmSnapshots.add(new VMSnapshotVO());
|
||||
when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(vmSnapshots);
|
||||
|
||||
// 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());
|
||||
|
|
@ -356,6 +365,10 @@ public class UserVmManagerTest {
|
|||
|
||||
|
||||
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
|
||||
List<VMSnapshotVO> vmSnapshots = new ArrayList<VMSnapshotVO>();
|
||||
vmSnapshots.add(new VMSnapshotVO());
|
||||
when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(vmSnapshots);
|
||||
|
||||
doReturn(Hypervisor.HypervisorType.XenServer).when(_vmInstance).getHypervisorType();
|
||||
|
||||
doReturn(VirtualMachine.State.Running).when(_vmInstance).getState();
|
||||
|
|
|
|||
Loading…
Reference in New Issue