Skip to content

Commit 208f410

Browse files
committed
upgrade: consider multiple hypervisors and secondary storages
This fixes an issue during upgrade in edge case. Steps to reproduce the issue - deploy an env with ACS 4.18 - the env has multiple hypervisors: KVM and VMware - the env has multiple secondary storages: sec1 and sec2 - register the new 4.19.1 systemvm template for VMware (systemvm-vmware-4.19.1), but mistakely as a private template. - the systemvm template is downloaded to sec2 (not sec1). If it is downloaded to sec1, remove it and re-register the template. - backup the cloudstack databases by `mysqldump -R cloud` and `mysqldump -R cloud_usage` - install ACS 4.19.1.2 and start mgmt server Without this PR, got an NPE during mgmt server start ``` 2024-10-29 12:46:53,904 ERROR [c.c.u.SystemVmTemplateRegistration] (main:null) (logid:) Failed to register template for hypervisor: VMware java.lang.NullPointerException at com.cloud.upgrade.SystemVmTemplateRegistration.updateTemplateDetails(SystemVmTemplateRegistration.java:519) at com.cloud.upgrade.SystemVmTemplateRegistration.performTemplateRegistrationOperations(SystemVmTemplateRegistration.java:640) at com.cloud.upgrade.SystemVmTemplateRegistration.registerTemplate(SystemVmTemplateRegistration.java:650) at com.cloud.upgrade.SystemVmTemplateRegistration$4.doInTransactionWithoutResult(SystemVmTemplateRegistration.java:789) at com.cloud.utils.db.TransactionCallbackNoReturn.doInTransaction(TransactionCallbackNoReturn.java:25) ```
1 parent 03bdf11 commit 208f410

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,14 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
794794
Long templateId = getRegisteredTemplateId(hypervisorAndTemplateName);
795795
if (templateId != null) {
796796
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
797-
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image);
798-
String installPath = templateDataStoreVO.getInstallPath();
799-
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
800-
continue;
801-
} else if (templateVO != null) {
797+
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
798+
if (templateDataStoreVO != null) {
799+
String installPath = templateDataStoreVO.getInstallPath();
800+
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
801+
continue;
802+
}
803+
}
804+
if (templateVO != null) {
802805
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
803806
continue;
804807
}

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3441,7 +3441,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
34413441
TemplateDataStoreVO templateVO = null;
34423442
if (templateId != null) {
34433443
vmTemplateVO = _templateDao.findById(templateId);
3444-
templateVO = _templateStoreDao.findByTemplate(templateId, DataStoreRole.Image);
3444+
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
34453445
if (templateVO != null) {
34463446
try {
34473447
if (SystemVmTemplateRegistration.validateIfSeeded(

0 commit comments

Comments
 (0)