Skip to content

Commit 92abb94

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-6007. Restore VM command fails with NPE.
If a VM instance is deployed with startVm=false, then calling restoreVm on the instance fails with NPE because CS tries to expunge a volume that has not been created in primary store.
1 parent b811bc0 commit 92abb94

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
7272
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
7373
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
74+
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
7475
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
7576
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
7677
import org.apache.cloudstack.framework.async.AsyncCallFuture;
@@ -5113,14 +5114,17 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
51135114
_volsDao.detachVolume(root.getId());
51145115
volumeMgr.destroyVolume(root);
51155116

5116-
// For VMware hypervisor since the old root volume is replaced by the new root volume in storage, force expunge old root volume
5117+
// For VMware hypervisor since the old root volume is replaced by the new root volume, force expunge old root volume if it has been created in storage
51175118
if (vm.getHypervisorType() == HypervisorType.VMware) {
5118-
s_logger.info("Expunging volume " + root.getId() + " from primary data store");
5119-
AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId()));
5120-
try {
5121-
future.get();
5122-
} catch (Exception e) {
5123-
s_logger.debug("Failed to expunge volume:" + root.getId(), e);
5119+
VolumeInfo volumeInStorage = volFactory.getVolume(root.getId());
5120+
if (volumeInStorage != null) {
5121+
s_logger.info("Expunging volume " + root.getId() + " from primary data store");
5122+
AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId()));
5123+
try {
5124+
future.get();
5125+
} catch (Exception e) {
5126+
s_logger.debug("Failed to expunge volume:" + root.getId(), e);
5127+
}
51245128
}
51255129
}
51265130

0 commit comments

Comments
 (0)