Skip to content

Conversation

@weizhouapache
Copy link
Member

Description

This PR fixes #12042

No idea how to reproduce the issue. However, 2 users have faced the same issue which seems to be caused by missing {SHA-512} algorithm of checksum value.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@weizhouapache weizhouapache added this to the 4.22.1 milestone Nov 28, 2025
@weizhouapache weizhouapache linked an issue Nov 28, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.59%. Comparing base (b5fd39f) to head (2b8a847).

Files with missing lines Patch % Lines
...apache/cloudstack/utils/security/DigestHelper.java 0.00% 12 Missing ⚠️
...om/cloud/upgrade/SystemVmTemplateRegistration.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12165      +/-   ##
============================================
- Coverage     17.59%   17.59%   -0.01%     
+ Complexity    15601    15596       -5     
============================================
  Files          5910     5910              
  Lines        529780   529792      +12     
  Branches      64729    64731       +2     
============================================
- Hits          93226    93203      -23     
- Misses       426060   426096      +36     
+ Partials      10494    10493       -1     
Flag Coverage Δ
uitests 3.60% <ø> (ø)
unittests 18.66% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15859

@weizhouapache
Copy link
Member Author

@blueorangutan test keepEnv

@blueorangutan
Copy link

@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-14887)

@weizhouapache
Copy link
Member Author

@blueorangutan test keepEnv

@blueorangutan
Copy link

@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-14889)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 53254 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12165-t14889-kvm-ol8.zip
Smoke tests completed. 149 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@weizhouapache weizhouapache marked this pull request as ready for review December 9, 2025 08:50
@weizhouapache
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15960

@weizhouapache
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 16377

@weizhouapache
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@DaanHoogland DaanHoogland requested a review from Copilot January 15, 2026 16:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a bug (#12042) where systemVM template registration was failing due to missing algorithm prefixes in checksum values. The fix adds a new utility method to prepend the algorithm identifier (e.g., {SHA-512}) to checksums when the algorithm is missing but can be inferred from the checksum length.

Changes:

  • Added DigestHelper.prependAlgorithm() method to automatically detect and prepend the hash algorithm based on checksum length
  • Updated template checksum registration to use the new method, ensuring checksums are stored with algorithm prefixes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java Adds prependAlgorithm() utility method to infer and prepend algorithm prefix based on checksum length
engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java Applies prependAlgorithm() when setting checksums during template creation and updates
Comments suppressed due to low confidence (1)

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

  • The checksum comparison at line 880 compares the output of DigestHelper.calculateChecksum() (which returns a plain SHA-512 hash without prefix) against templateDetails.getChecksum() from metadata (which may or may not have a prefix). With the changes in this PR, template checksums in the database will have prefixes, but metadata checksums may not. This comparison should use DigestHelper.getHashValueFromChecksumValue() to strip any algorithm prefix before comparing, or ensure both values are in the same format.
        if (!templateChecksum.equals(templateDetails.getChecksum())) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +146 to +159
public static String prependAlgorithm(String checksum) {
if (StringUtils.isEmpty(checksum)) {
return checksum;
}
int checksumLength = checksum.length();
Map<String, Integer> paddingLengths = getChecksumLengthsMap();
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
if (entry.getValue().equals(checksumLength)) {
String algorithm = entry.getKey();
return String.format("{%s}%s", algorithm, checksum);
}
}
return checksum;
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prependAlgorithm method doesn't check if the algorithm prefix is already present before prepending, which could result in double-prefixing (e.g., {SHA-512}{SHA-512}checksum). Add a check using the existing isAlgorithmPresent() method at the start of the function to return the checksum unchanged if it already has the prefix.

Copilot uses AI. Check for mistakes.
Comment on lines +152 to +157
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
if (entry.getValue().equals(checksumLength)) {
String algorithm = entry.getKey();
return String.format("{%s}%s", algorithm, checksum);
}
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple hash algorithms have different lengths but one checksum length could theoretically match multiple entries in the map, the iteration order is non-deterministic since getChecksumLengthsMap() returns a HashMap. While the current set of algorithms have unique lengths, this creates ambiguity. Consider using a LinkedHashMap with algorithms ordered by preference (most secure first), or add a comment documenting that all supported algorithms have unique digest lengths.

Suggested change
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
if (entry.getValue().equals(checksumLength)) {
String algorithm = entry.getKey();
return String.format("{%s}%s", algorithm, checksum);
}
}
String selectedAlgorithm = null;
// In case multiple algorithms share the same digest length, choose deterministically
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
if (entry.getValue().equals(checksumLength)) {
String algorithm = entry.getKey();
if (selectedAlgorithm == null || algorithm.compareTo(selectedAlgorithm) < 0) {
selectedAlgorithm = algorithm;
}
}
}
if (selectedAlgorithm != null) {
return String.format("{%s}%s", selectedAlgorithm, checksum);
}

Copilot uses AI. Check for mistakes.
}
}

public static String prependAlgorithm(String checksum) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new prependAlgorithm method lacks test coverage. Add test cases covering: (1) checksum without prefix for each supported algorithm, (2) checksum that already has a prefix, (3) null/empty checksum, (4) checksum with invalid length that doesn't match any algorithm.

Copilot uses AI. Check for mistakes.
@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Cloudstack 4.22 upgrade: SystemVM template update fails

3 participants