Skip to content

Commit bc5f734

Browse files
committed
fix
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 48c9d29 commit bc5f734

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,10 @@ public boolean validateIfSeeded(TemplateDataStoreVO templDataStoreVO, String url
376376

377377
private static String getHypervisorArchKey(String hypervisorType, String arch) {
378378
if (Hypervisor.HypervisorType.KVM.name().equals(hypervisorType)) {
379-
return String.format("%s-%s", hypervisorType, StringUtils.isBlank(arch) ? CPU.archX86_64Identifier : arch);
379+
return String.format("%s-%s", hypervisorType.toLowerCase(),
380+
StringUtils.isBlank(arch) ? CPU.archX86_64Identifier : arch);
380381
}
381-
return hypervisorType;
382+
return hypervisorType.toLowerCase();
382383
}
383384

384385
private static MetadataTemplateDetails getMetadataTemplateDetails(Hypervisor.HypervisorType hypervisorType, String arch) {
@@ -744,25 +745,39 @@ public void registerTemplate(Hypervisor.HypervisorType hypervisor, String name,
744745
* exist a template corresponding to the current code version.
745746
*/
746747
public static String parseMetadataFile() {
747-
try {
748-
Ini ini = new Ini();
749-
ini.load(new FileReader(METADATA_FILE));
750-
for (Pair<Hypervisor.HypervisorType, String> hypervisorType : hypervisorList) {
751-
String key = getHypervisorArchKey(hypervisorType.first().name(), hypervisorType.second());
752-
Ini.Section section = ini.get(key);
753-
NewTemplateMap.put(key, new MetadataTemplateDetails(hypervisorType.first(), section.get("templatename"),
754-
section.get("filename"), section.get("downloadurl"), section.get("checksum"),
755-
hypervisorType.second()));
756-
}
757-
Ini.Section section = ini.get("default");
758-
return section.get("version");
759-
} catch (Exception e) {
760-
String errMsg = String.format("Failed to parse systemVM template metadata file: %s", METADATA_FILE);
748+
String errMsg = String.format("Failed to parse systemVM template metadata file: %s", METADATA_FILE);
749+
final Ini ini = new Ini();
750+
try (FileReader reader = new FileReader(METADATA_FILE)) {
751+
ini.load(reader);
752+
} catch (IOException e) {
761753
LOGGER.error(errMsg, e);
762754
throw new CloudRuntimeException(errMsg, e);
763755
}
756+
if (!ini.containsKey("default")) {
757+
errMsg = String.format("%s as unable to default section", errMsg);
758+
LOGGER.error(errMsg);
759+
throw new CloudRuntimeException(errMsg);
760+
}
761+
for (Pair<Hypervisor.HypervisorType, String> hypervisorType : hypervisorList) {
762+
String key = getHypervisorArchKey(hypervisorType.first().name(), hypervisorType.second());
763+
Ini.Section section = ini.get(key);
764+
if (section == null) {
765+
LOGGER.error("Failed to find details for {} in template metadata file: {}", key, METADATA_FILE);
766+
continue;
767+
}
768+
NewTemplateMap.put(key, new MetadataTemplateDetails(
769+
hypervisorType.first(),
770+
section.get("templatename"),
771+
section.get("filename"),
772+
section.get("downloadurl"),
773+
section.get("checksum"),
774+
hypervisorType.second()));
775+
}
776+
Ini.Section defaultSection = ini.get("default");
777+
return defaultSection.get("version");
764778
}
765779

780+
766781
private static void cleanupStore(Long templateId, String filePath) {
767782
String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + String.valueOf(templateId);
768783
try {

engine/schema/templateConfig.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ declare -a templates
7373
getTemplateVersion $1
7474
templates=( "kvm-x86_64:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-x86_64-kvm.qcow2.bz2"
7575
"kvm-aarch64:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-aarch64-kvm.qcow2.bz2"
76-
"vmware-x86_64:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-x86_64-vmware.ova"
77-
"xenserver-x86_64:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-xen.vhd.bz2"
78-
"hyperv-x86_64:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-hyperv.vhd.zip"
79-
"lxc-x86_64:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-kvm.qcow2.bz2"
80-
"ovm3-x86_64:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-ovm.raw.bz2" )
76+
"vmware:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-x86_64-vmware.ova"
77+
"xenserver:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-xen.vhd.bz2"
78+
"hyperv:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-hyperv.vhd.zip"
79+
"lxc:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-kvm.qcow2.bz2"
80+
"ovm3:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-ovm.raw.bz2" )
8181

8282
PARENTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/dist/systemvm-templates/"
8383
mkdir -p $PARENTPATH

0 commit comments

Comments
 (0)