Skip to content

Commit 48377a3

Browse files
committed
Fix build regression from 08e5993
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent f412e07 commit 48377a3

3 files changed

Lines changed: 35 additions & 27 deletions

File tree

‎server/src/com/cloud/storage/VolumeApiServiceImpl.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long n
984984
hosts = new long[] {userVm.getLastHostId()};
985985
}
986986

987+
final String errorMsg = "The VM must be stopped or the disk detached in order to resize with the XenServer Hypervisor.";
987988
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
988989

989990
if (storagePool.isManaged() && storagePool.getHypervisor() == HypervisorType.Any && hosts != null && hosts.length > 0) {

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5028,35 +5028,29 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
50285028
throw ex;
50295029
}
50305030

5031-
VolumeVO root = rootVols.get(0);
5032-
if ( !Volume.State.Allocated.equals(root.getState()) || newTemplateId != null ){
5033-
Long templateId = root.getTemplateId();
5034-
boolean isISO = false;
5035-
if (templateId == null) {
5036-
// Assuming that for a vm deployed using ISO, template ID is set to NULL
5037-
isISO = true;
5038-
templateId = vm.getIsoId();
5039-
}
5031+
// If target VM has associated VM snapshots then don't allow restore of VM
5032+
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
5033+
if (vmSnapshots.size() > 0) {
5034+
throw new InvalidParameterValueException("Unable to restore VM, please remove VM snapshots before restoring VM");
5035+
}
50405036

5041-
// If target VM has associated VM snapshots then don't allow restore of VM
5042-
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
5043-
if (vmSnapshots.size() > 0) {
5044-
throw new InvalidParameterValueException("Unable to restore VM, please remove VM snapshots before restoring VM");
5045-
}
5037+
VolumeVO root = rootVols.get(0);
5038+
Long templateId = root.getTemplateId();
5039+
boolean isISO = false;
5040+
if(templateId == null) {
5041+
// Assuming that for a vm deployed using ISO, template ID is set to NULL
5042+
isISO = true;
5043+
templateId = vm.getIsoId();
5044+
}
50465045

5047-
VMTemplateVO template = null;
5048-
//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
5049-
if (newTemplateId != null) {
5050-
template = _templateDao.findById(newTemplateId);
5051-
_accountMgr.checkAccess(caller, null, true, template);
5052-
if (isISO) {
5053-
if (!template.getFormat().equals(ImageFormat.ISO)) {
5054-
throw new InvalidParameterValueException("Invalid ISO id provided to restore the VM ");
5055-
}
5056-
} else {
5057-
if (template.getFormat().equals(ImageFormat.ISO)) {
5058-
throw new InvalidParameterValueException("Invalid template id provided to restore the VM ");
5059-
}
5046+
VMTemplateVO template = null;
5047+
//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
5048+
if(newTemplateId != null) {
5049+
template = _templateDao.findById(newTemplateId);
5050+
_accountMgr.checkAccess(caller, null, true, template);
5051+
if (isISO) {
5052+
if (!template.getFormat().equals(ImageFormat.ISO)) {
5053+
throw new InvalidParameterValueException("Invalid ISO id provided to restore the VM ");
50605054
}
50615055
} else {
50625056
if (template.getFormat().equals(ImageFormat.ISO)) {

‎server/test/com/cloud/vm/UserVmManagerTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232
import static org.mockito.Mockito.when;
3333

3434
import java.lang.reflect.Field;
35+
import java.util.ArrayList;
3536
import java.util.List;
3637
import java.util.UUID;
3738

39+
import com.cloud.vm.snapshot.VMSnapshotVO;
40+
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
3841
import org.junit.Before;
3942
import org.junit.Test;
4043
import org.mockito.Mock;
@@ -99,6 +102,7 @@ public class UserVmManagerTest {
99102
@Mock UserDao _userDao;
100103
@Mock UserVmDao _vmDao;
101104
@Mock VMInstanceDao _vmInstanceDao;
105+
@Mock VMSnapshotDao _vmSnapshotDao;
102106
@Mock VMTemplateDao _templateDao;
103107
@Mock VolumeDao _volsDao;
104108
@Mock RestoreVMCmd _restoreVMCmd;
@@ -123,6 +127,7 @@ public void setup(){
123127

124128
_userVmMgr._vmDao = _vmDao;
125129
_userVmMgr._vmInstanceDao = _vmInstanceDao;
130+
_userVmMgr._vmSnapshotDao = _vmSnapshotDao;
126131
_userVmMgr._templateDao = _templateDao;
127132
_userVmMgr._volsDao = _volsDao;
128133
_userVmMgr._itMgr = _itMgr;
@@ -323,6 +328,10 @@ public void testScaleVMF1() throws Exception {
323328

324329
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
325330

331+
List<VMSnapshotVO> vmSnapshots = new ArrayList<VMSnapshotVO>();
332+
vmSnapshots.add(new VMSnapshotVO());
333+
when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(vmSnapshots);
334+
326335
// UserContext.current().setEventDetails("Vm Id: "+getId());
327336
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
328337
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
@@ -356,6 +365,10 @@ public void testScaleVMF2() throws Exception {
356365

357366

358367
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
368+
List<VMSnapshotVO> vmSnapshots = new ArrayList<VMSnapshotVO>();
369+
vmSnapshots.add(new VMSnapshotVO());
370+
when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(vmSnapshots);
371+
359372
doReturn(Hypervisor.HypervisorType.XenServer).when(_vmInstance).getHypervisorType();
360373

361374
doReturn(VirtualMachine.State.Running).when(_vmInstance).getState();

0 commit comments

Comments
 (0)