Skip to content

Commit 5af5f64

Browse files
Validate the direct downloaded template file format (QCOW2) if the template file exists
1 parent c5afee2 commit 5af5f64

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
@@ -2455,8 +2455,15 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd)
24552455

24562456
template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
24572457

2458-
String templatePath = template.getPath();
2459-
if (templatePath != null) {
2458+
String templatePath = null;
2459+
if (template != null) {
2460+
templatePath = template.getPath();
2461+
}
2462+
if (StringUtils.isEmpty(templatePath)) {
2463+
logger.warn(String.format("Skipped validation whether downloaded file is QCOW2 for template {}, due to downloaded template path is empty", template.getName()));
2464+
} else if (!new File(templatePath).exists()) {
2465+
logger.warn(String.format("Skipped validation whether downloaded file is QCOW2 for template {}, due to downloaded template path is not valid: {}", template.getName(), templatePath));
2466+
} else {
24602467
try {
24612468
Qcow2Inspector.validateQcow2File(templatePath);
24622469
} catch (RuntimeException e) {

0 commit comments

Comments
 (0)