Skip to content

Prevent downloading templates to secondary storages that are in read-only - #13023

Open
GaOrtiga wants to merge 7 commits into
apache:4.20from
scclouds:dont-download-template-to-sec-storage-readonly
Open

Prevent downloading templates to secondary storages that are in read-only#13023
GaOrtiga wants to merge 7 commits into
apache:4.20from
scclouds:dont-download-template-to-sec-storage-readonly

Conversation

@GaOrtiga

Copy link
Copy Markdown
Collaborator

Description

When a Secondary Storage is marked as read-only, download of new templates is still performed in it. This behavior has been fixed, making it so that read-only storages are ignored during the template download process.

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?

I put a secondary in the zone in the read-only state and verified that it no longer would be selected for the download.

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

@winterhazel winterhazel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CLGTM

@winterhazel

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@winterhazel 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
Copy Markdown

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

@codecov

codecov Bot commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 4.14%. Comparing base (8eb162c) to head (40e82c2).
⚠️ Report is 24 commits behind head on 4.20.

❗ There is a different number of reports uploaded between BASE (8eb162c) and HEAD (40e82c2). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (8eb162c) HEAD (40e82c2)
unittests 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               4.20   #13023       +/-   ##
=============================================
- Coverage     16.26%    4.14%   -12.12%     
=============================================
  Files          5665      405     -5260     
  Lines        500530    33025   -467505     
  Branches      60787     5898    -54889     
=============================================
- Hits          81411     1370    -80041     
+ Misses       410027    31479   -378548     
+ Partials       9092      176     -8916     
Flag Coverage Δ
uitests 4.14% <ø> (-0.01%) ⬇️
unittests ?

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

☔ View full report in Codecov by Harness.
📢 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.

@sureshanaparti

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti 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
Copy Markdown

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

@winterhazel

Copy link
Copy Markdown
Member

@GaOrtiga could you have a look at the test failures?

@GaOrtiga

Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@GaOrtiga 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
Copy Markdown

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes template download/allocation behavior so Secondary Storage marked read-only is skipped during template download and sync flows.

Changes:

  • Add read-only image store checks when selecting/validating secondary storage for template creation/allocation.
  • Prevent template sync/download decisions from targeting read-only image stores.
  • Extend unit tests to account for the new read-only filtering behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java Skips template allocation/download to image stores flagged as read-only.
server/src/test/java/com/cloud/template/HypervisorTemplateAdapterTest.java Updates tests/mocks to support new ImageStoreDao read-only checks.
engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java Skips downloads during template sync when the target image store is read-only; fixes a log message typo.
engine/storage/image/src/test/java/org/apache/cloudstack/storage/image/TemplateServiceImplTest.java Adds coverage for read-only store behavior and adjusts setup for new DAO usage.
engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java Avoids downloading templates to read-only image stores at the driver level.

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

Comment thread server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java Outdated
Comment thread server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java Outdated
@weizhouapache weizhouapache added this to the 4.20.4 milestone May 7, 2026
@GaOrtiga

GaOrtiga commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

@sureshanaparti thanks for the review, I applied yours and copilot's suggestions.

@GaOrtiga

GaOrtiga commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@GaOrtiga 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
Copy Markdown

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

@DaanHoogland

Copy link
Copy Markdown
Contributor

@GaOrtiga a failing unit test:

16:01:25 [ERROR] Failures: 
16:01:25 [ERROR]   TemplateServiceImplTest.shouldDownloadTemplateToStoreTestSkipsWhenStorageIsReadOnly:179

can you have a look?

@DaanHoogland

Copy link
Copy Markdown
Contributor

@GaOrtiga , should you be re-added to the collaborators list?

@GaOrtiga

Copy link
Copy Markdown
Collaborator Author

@DaanHoogland Yes. I have created the PR.

@GaOrtiga

GaOrtiga commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@GaOrtiga 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
Copy Markdown

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

@winterhazel
winterhazel self-requested a review June 1, 2026 18:51
@GaOrtiga

GaOrtiga commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@GaOrtiga 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
Copy Markdown

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

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

@blueorangutan

Copy link
Copy Markdown

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

Test Result Time (s) Test File

@DaanHoogland
DaanHoogland requested a lite review from Copilot August 5, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Suppressed comments (4)

server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java:277

  • The exception message says the store is 'marked as read-only', but isRemovedOrReadonly(...) also returns true when the store doesn't exist/was removed (per DataStoreManagerImpl). Update the message to reflect both cases (e.g., removed/not found or read-only) so operators get an accurate reason for the rejection.
            if (dataStoreManager.isRemovedOrReadonly(dataStore)) {
                throw new CloudRuntimeException(String.format("DataStore [{}] returned by heuristic rule is marked as read-only.", dataStore));
            }

engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java:44

  • This logger can be private static final to avoid per-instance allocation and match common logging best practices in the codebase. Changing to a constant logger also discourages accidental reassignment.
    protected Logger logger = LogManager.getLogger(DataStoreManagerImpl.class);

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java:64

  • Method name casing is inconsistent with common Java camelCase for 'read-only' (typically ReadOnly). Consider renaming to isRemovedOrReadOnly for clarity and consistency.
    boolean isRemovedOrReadonly(DataStore store);

server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java:344

  • This newly added read-only filtering path in HypervisorTemplateAdapter.isZoneAndImageStoreAvailable(...) doesn't appear to have a direct unit test asserting false when the store is read-only. Add a test that stubs the returned ImageStoreVO to isReadonly() == true and verifies the method returns false.
        if (_imgStoreDao.findById(imageStore.getId()).isReadonly()) {
            logger.info("Image store [{}] is marked as read-only. Skip downloading template to this image store.", imageStore);
            return false;
        }

Comment thread server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants