Skip to content

Commit

Permalink
upgrade: consider multiple hypervisors and secondary storages
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
weizhouapache committed Nov 8, 2024
1 parent 03bdf11 commit 172a249
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,14 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
Long templateId = getRegisteredTemplateId(hypervisorAndTemplateName);
if (templateId != null) {
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image);
String installPath = templateDataStoreVO.getInstallPath();
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
continue;
} else if (templateVO != null) {
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
if (templateDataStoreVO != null) {
String installPath = templateDataStoreVO.getInstallPath();
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
continue;
}
}
if (templateVO != null) {
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3441,7 +3441,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
TemplateDataStoreVO templateVO = null;
if (templateId != null) {
vmTemplateVO = _templateDao.findById(templateId);
templateVO = _templateStoreDao.findByTemplate(templateId, DataStoreRole.Image);
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
if (templateVO != null) {
try {
if (SystemVmTemplateRegistration.validateIfSeeded(
Expand Down

0 comments on commit 172a249

Please sign in to comment.