Program: 105455
Project: 105455
Buggy source:
/** 
 * This function copies a physical disk from Secondary Storage to Primary Storage or from Primary to Primary Storage The first time a template is deployed in Primary Storage it will be copied from Secondary to Primary. If it has been created on Primary Storage, it will be copied on the Primary Storage
 */
@Override public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,String name,PhysicalDiskFormat format,Storage.ProvisioningType provisioningType,long size,KVMStoragePool destPool,int timeout){
  s_logger.info("String_Node_Str" + name + "String_Node_Str"+ template.getName()+ "String_Node_Str"+ destPool.getUuid()+ "String_Node_Str"+ destPool.getType().toString()+ "String_Node_Str"+ size);
  KVMPhysicalDisk disk=null;
  if (destPool.getType() == StoragePoolType.RBD) {
    disk=createDiskFromTemplateOnRBD(template,name,format,provisioningType,size,destPool,timeout);
  }
 else {
    try {
      String newUuid=name;
      disk=destPool.createPhysicalDisk(newUuid,format,provisioningType,template.getVirtualSize());
      if (template.getFormat() == PhysicalDiskFormat.TAR) {
        Script.runSimpleBashScript("String_Node_Str" + template.getPath() + "String_Node_Str"+ disk.getPath(),timeout);
      }
 else       if (template.getFormat() == PhysicalDiskFormat.DIR) {
        Script.runSimpleBashScript("String_Node_Str" + disk.getPath());
        Script.runSimpleBashScript("String_Node_Str" + disk.getPath());
        Script.runSimpleBashScript("String_Node_Str" + template.getPath() + "String_Node_Str"+ disk.getPath(),timeout);
      }
 else       if (format == PhysicalDiskFormat.QCOW2) {
        QemuImg qemu=new QemuImg(timeout);
        QemuImgFile destFile=new QemuImgFile(disk.getPath(),format);
        if (size > template.getVirtualSize()) {
          destFile.setSize(size);
        }
 else {
          destFile.setSize(template.getVirtualSize());
        }
        Map<String,String> options=new HashMap<String,String>();
        options.put("String_Node_Str",QemuImg.PreallocationType.getPreallocationType(provisioningType).toString());
switch (provisioningType) {
case THIN:
          QemuImgFile backingFile=new QemuImgFile(template.getPath(),template.getFormat());
        qemu.create(destFile,backingFile,options);
      break;
case SPARSE:
case FAT:
    QemuImgFile srcFile=new QemuImgFile(template.getPath(),template.getFormat());
  qemu.convert(srcFile,destFile,options);
break;
}
}
 else if (format == PhysicalDiskFormat.RAW) {
QemuImgFile sourceFile=new QemuImgFile(template.getPath(),template.getFormat());
QemuImgFile destFile=new QemuImgFile(disk.getPath(),PhysicalDiskFormat.RAW);
if (size > template.getVirtualSize()) {
destFile.setSize(size);
}
 else {
destFile.setSize(template.getVirtualSize());
}
QemuImg qemu=new QemuImg(timeout);
Map<String,String> options=new HashMap<String,String>();
qemu.convert(sourceFile,destFile,options);
}
}
 catch (QemuImgException e) {
s_logger.error("String_Node_Str" + disk.getPath() + "String_Node_Str"+ e.getMessage());
}
}
if (disk == null) {
throw new CloudRuntimeException("String_Node_Str" + template.getName());
}
return disk;
}

Fixed version (ground truth):
/** 
 * This function copies a physical disk from Secondary Storage to Primary Storage or from Primary to Primary Storage The first time a template is deployed in Primary Storage it will be copied from Secondary to Primary. If it has been created on Primary Storage, it will be copied on the Primary Storage
 */
@Override public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,String name,PhysicalDiskFormat format,Storage.ProvisioningType provisioningType,long size,KVMStoragePool destPool,int timeout){
  s_logger.info("String_Node_Str" + name + "String_Node_Str"+ template.getName()+ "String_Node_Str"+ destPool.getUuid()+ "String_Node_Str"+ destPool.getType().toString()+ "String_Node_Str"+ size);
  KVMPhysicalDisk disk=null;
  if (destPool.getType() == StoragePoolType.RBD) {
    disk=createDiskFromTemplateOnRBD(template,name,format,provisioningType,size,destPool,timeout);
  }
 else {
    try {
      String newUuid=name;
      disk=destPool.createPhysicalDisk(newUuid,format,provisioningType,template.getVirtualSize());
      if (disk == null) {
        throw new CloudRuntimeException("String_Node_Str" + template.getName());
      }
      if (template.getFormat() == PhysicalDiskFormat.TAR) {
        Script.runSimpleBashScript("String_Node_Str" + template.getPath() + "String_Node_Str"+ disk.getPath(),timeout);
      }
 else       if (template.getFormat() == PhysicalDiskFormat.DIR) {
        Script.runSimpleBashScript("String_Node_Str" + disk.getPath());
        Script.runSimpleBashScript("String_Node_Str" + disk.getPath());
        Script.runSimpleBashScript("String_Node_Str" + template.getPath() + "String_Node_Str"+ disk.getPath(),timeout);
      }
 else       if (format == PhysicalDiskFormat.QCOW2) {
        QemuImg qemu=new QemuImg(timeout);
        QemuImgFile destFile=new QemuImgFile(disk.getPath(),format);
        if (size > template.getVirtualSize()) {
          destFile.setSize(size);
        }
 else {
          destFile.setSize(template.getVirtualSize());
        }
        Map<String,String> options=new HashMap<String,String>();
        options.put("String_Node_Str",QemuImg.PreallocationType.getPreallocationType(provisioningType).toString());
switch (provisioningType) {
case THIN:
          QemuImgFile backingFile=new QemuImgFile(template.getPath(),template.getFormat());
        qemu.create(destFile,backingFile,options);
      break;
case SPARSE:
case FAT:
    QemuImgFile srcFile=new QemuImgFile(template.getPath(),template.getFormat());
  qemu.convert(srcFile,destFile,options);
break;
}
}
 else if (format == PhysicalDiskFormat.RAW) {
QemuImgFile sourceFile=new QemuImgFile(template.getPath(),template.getFormat());
QemuImgFile destFile=new QemuImgFile(disk.getPath(),PhysicalDiskFormat.RAW);
if (size > template.getVirtualSize()) {
destFile.setSize(size);
}
 else {
destFile.setSize(template.getVirtualSize());
}
QemuImg qemu=new QemuImg(timeout);
Map<String,String> options=new HashMap<String,String>();
qemu.convert(sourceFile,destFile,options);
}
}
 catch (QemuImgException e) {
s_logger.error("String_Node_Str" + disk.getPath() + "String_Node_Str"+ e.getMessage());
}
}
return disk;
}