Skip to content

Commit fde46aa

Browse files
sureshanapartidhslove
authored andcommitted
Validate the direct downloaded template file format (QCOW2) if the template file exists (apache#10332)
* Validate the direct downloaded template file format (QCOW2) if the template file exists * string format not required
1 parent 73a1fea commit fde46aa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,8 +2674,15 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd)
26742674

26752675
template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
26762676

2677-
String templatePath = template.getPath();
2678-
if (templatePath != null) {
2677+
String templatePath = null;
2678+
if (template != null) {
2679+
templatePath = template.getPath();
2680+
}
2681+
if (StringUtils.isEmpty(templatePath)) {
2682+
logger.warn("Skipped validation whether downloaded file is QCOW2 for template {}, due to downloaded template path is empty", template.getName());
2683+
} else if (!new File(templatePath).exists()) {
2684+
logger.warn("Skipped validation whether downloaded file is QCOW2 for template {}, due to downloaded template path is not valid: {}", template.getName(), templatePath);
2685+
} else {
26792686
try {
26802687
Qcow2Inspector.validateQcow2File(templatePath);
26812688
} catch (RuntimeException e) {

0 commit comments

Comments
 (0)