Skip to content

Add NULL check during restoreVM operation when host is removed - #13779

Open
nvazquez wants to merge 3 commits into
apache:4.22from
shapeblue:422-nullcheck-restorevm
Open

Add NULL check during restoreVM operation when host is removed#13779
nvazquez wants to merge 3 commits into
apache:4.22from
shapeblue:422-nullcheck-restorevm

Conversation

@nvazquez

@nvazquez nvazquez commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR addresses a fix for the following use case:

  • Create VM
  • Start VM
  • Stop VM
  • Delete Host where VM was started
  • Restore VM -> Restore VM command failed, VM ended up with two ROOT volumes, one of them is in Allocated state
  • Expected result: VM restored (with new template)

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?

sachindoddaguni and others added 2 commits August 3, 2026 15:37
…e#571)

* Add NULL check during restore VM operation when host is not available/removed

* fix line ending pre commit failure

* update logging with details of removed host and vm

---------

Co-authored-by: Sachin R Doddaguni <s_rudrappadoddagu@apple.com>
(cherry picked from commit 1dbda12ccdca1aaf86ef8f9b185986c9d22b567e)
@nvazquez nvazquez added this to the 4.22.2 milestone Aug 3, 2026
// host row may have been hard-deleted from DB, treat like removed
if (host == null) {
logger.warn("Host {} not found", hostId);
s_logger.warn(String.format("Host with id %s not found in DB for VM %s (%s)",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s_logger doesn't exist in this class. It only has logger (see the line right below this one). This won't compile.

// host row may have been hard-deleted from DB, treat like removed
if (host == null) {
logger.warn("Host {} not found", hostId);
s_logger.warn(String.format("Host with id %s not found in DB for VM %s (%s)",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use {} placeholders here to match the branch below, instead of String.format.

import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.host.Status;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

com.cloud.host.Status is out of place here, mixed into the org.apache.cloudstack.* block.

}

@Test
public void testRestoreVirtualMachineWhenHostRemoved() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we also add a test for the host-row-missing case, not just Removed?

@vladimirpetrov

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@vladimirpetrov 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 18790

@vladimirpetrov

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@vladimirpetrov 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 18791

@nvazquez

nvazquez commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez 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.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.69%. Comparing base (5328528) to head (d7cd7ef).

❗ There is a different number of reports uploaded between BASE (5328528) and HEAD (d7cd7ef). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (5328528) HEAD (d7cd7ef)
unittests 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               4.22   #13779       +/-   ##
=============================================
- Coverage     17.69%    3.69%   -14.01%     
=============================================
  Files          5925      449     -5476     
  Lines        533539    38176   -495363     
  Branches      65274     7072    -58202     
=============================================
- Hits          94427     1409    -93018     
+ Misses       428435    36580   -391855     
+ Partials      10677      187    -10490     
Flag Coverage Δ
uitests 3.69% <ø> (ø)
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.

@blueorangutan

Copy link
Copy Markdown

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

@nvazquez

nvazquez commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez 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 18794

@vladimirpetrov

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@vladimirpetrov 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 18795

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants