DaanHoogland commented on code in PR #8555: URL: https://github.com/apache/cloudstack/pull/8555#discussion_r1470894257
########## server/src/main/java/com/cloud/vm/UserVmManagerImpl.java: ########## @@ -7765,49 +7766,68 @@ public UserVm restoreVirtualMachine(final Account caller, final long vmId, final List<Volume> newVols = new ArrayList<>(); for (VolumeVO root : rootVols) { - 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(); - } - - /* If new template/ISO is provided allocate a new volume from new template/ISO otherwise allocate new volume from original template/ISO */ - Volume newVol = null; - if (newTemplateId != null) { - if (isISO) { - newVol = volumeMgr.allocateDuplicateVolume(root, null); - vm.setIsoId(newTemplateId); - vm.setGuestOSId(template.getGuestOSId()); - vm.setTemplateId(newTemplateId); - } else { - newVol = volumeMgr.allocateDuplicateVolume(root, newTemplateId); - vm.setGuestOSId(template.getGuestOSId()); - vm.setTemplateId(newTemplateId); - } - // check and update VM if it can be dynamically scalable with the new template - updateVMDynamicallyScalabilityUsingTemplate(vm, newTemplateId); - } else { - newVol = volumeMgr.allocateDuplicateVolume(root, null); - } - newVols.add(newVol); + if ( !Volume.State.Allocated.equals(root.getState()) || newTemplateId != null ) { Review Comment: this if block, the transaction and possibibly even the branches within it should be new methods. A lot of comments in it could be method names. These can than be tested to improve the coverage of this bit of code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org