Skip to content

Commit 2b63e6a

Browse files
authored
Merge pull request apache#527 from shapeblue/template_qcow2_validation
Template QCOW2 validation: added validation whether template file exists before validating template format.
2 parents dc67d5b + 7f324d6 commit 2b63e6a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,8 +2386,16 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd)
23862386

23872387
template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
23882388

2389-
String templatePath = template.getPath();
2390-
if (templatePath != null) {
2389+
String templatePath = null;
2390+
if (template != null) {
2391+
templatePath = template.getPath();
2392+
}
2393+
//Check template path is not empty and points to existing local file to validate
2394+
if (StringUtils.isEmpty(templatePath)) {
2395+
s_logger.warn(String.format("Skipped validation whether downloaded file is QCOW2 due to downloaded template path is empty for template %s", template.getName()));
2396+
} else if (!new File(templatePath).exists()) {
2397+
s_logger.warn(String.format("Skipped validation whether downloaded file for %s is QCOW2 due to downloaded template path is not valid: %s", template.getName(), templatePath));
2398+
} else {
23912399
try {
23922400
Qcow2Inspector.validateQcow2File(templatePath);
23932401
} catch (RuntimeException e) {

0 commit comments

Comments
 (0)