Skip to content

Record a VM.STOP event and alert when host maintenance stops a VM - #14895

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:maint-stop-alert
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:maint-stop-alert

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator

Description

When host maintenance stops a VM instead of migrating it, nothing records the stop. The owner gets no VM.STOP event and admins get no alert, so people find out because their workload went down.

This PR adds both. When an HA ForceStop or a failed migration for maintenance leaves a VM Stopped that was Running (or Migrating) before:

  • a WARN VM.STOP event goes to the VM's owner: VM <name> (<uuid>) was stopped by host maintenance
  • the HA alert for the VM type goes out (ALERT.USERVM, router, CPVM or SSVM), with the host name added. It follows vm.ha.alerts.enabled like the other HA alerts.
Maintenance case Before After
No host available, migration not allowed, or vGPU: ForceStop nothing VM.STOP event + alert
Local storage with host.maintenance.local.storage.strategy=ForceStop nothing VM.STOP event + alert
Migration fails and orchestrateMigrateAway force-stops the VM generic VM.MIGRATE error only also VM.STOP event + alert
Migration fails but the VM keeps running VM.MIGRATE error unchanged

HA work counts as maintenance if it has the HostMaintenance reason or its host is in a maintenance state. I left the no-host ForceStop untagged on purpose: tagging it HostMaintenance would make it cancellable after a management server restart, which would change behavior.

The event and alert are best effort. A failure to record them is logged and doesn't affect the stop or the HA work.

No schema change. The only file changed is HighAvailabilityManagerImpl.

Relation to #13189: that PR stops orchestrateMigrateAway from force-stopping a VM after a failed migration and retries instead. This PR doesn't touch VirtualMachineManagerImpl, so the two don't conflict. With #13189 merged, the failed-migration hook simply never fires, and the two ForceStop cases still need this fix.

Fixes: #14894

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?

Unit tests in HighAvailabilityManagerImplTest:

  • ForceStop and a failed migration both check for a maintenance stop. A ForceStop that fails records nothing.
  • A stop tagged HostMaintenance writes the event against the owner account and sends the alert.
  • A stop with no tag on a host in PrepareForMaintenance is recorded. On an Enabled host it isn't.
  • Nothing is recorded if the VM is still running, or wasn't running before the attempt.
  • A DB error while recording doesn't escape.

The full server module test suite passes.

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

  • VMs already Stopping or Starting when maintenance began are not reported as stopped by maintenance.
  • The event text leaves out the hypervisor host name, because the VM owner can see it. Only the admin alert names the host.
  • Hidden VMs (displayvm=false) get a hidden event.

Not done here:

  • SSVM/CPVM destroyed by maintenance (they're recreated automatically).
  • The LXC restart path, which already alerts when the restart fails.

Host maintenance can stop a VM instead of moving it: a ForceStop when
no host can take it (or by the local storage strategy), or a force stop
after a failed migration. Neither left a VM.STOP event or an alert, so
the owner had no record of why the VM went down.

Record a WARN VM.STOP event against the VM's owner and send the VM HA
alert in both cases. HA work counts as maintenance when it carries the
HostMaintenance reason or its host is in a maintenance state.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.35%. Comparing base (a8735b2) to head (fd8576b).

Files with missing lines Patch % Lines
...java/com/cloud/ha/HighAvailabilityManagerImpl.java 83.33% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14895      +/-   ##
============================================
+ Coverage     18.34%   18.35%   +0.01%     
- Complexity    16671    16682      +11     
============================================
  Files          5939     5939              
  Lines        537817   537841      +24     
  Branches      65938    65942       +4     
============================================
+ Hits          98640    98701      +61     
+ Misses       427954   427900      -54     
- Partials      11223    11240      +17     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.44% <83.33%> (+0.01%) ⬆️

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.

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator Author

Tested on a KVM lab with 4.22 plus this change.

Setup: host.maintenance.local.storage.strategy=ForceStop, vm.ha.alerts.enabled=true. On one host, a VM with a local root disk and a control VM on RBD, then prepare that host for maintenance.

Without the change With the change
Host reaches Maintenance yes yes
Local-disk VM Stopped Stopped
VM.STOP events for it 0 1, WARN, "was stopped by host maintenance"
Alerts 0 1, ALERT.USERVM
RBD control VM migrated, no event, no alert migrated, no event, no alert

Not covered in the lab, unit tests only: the force stop after a failed migration, and the last-host ForceStop with no reason set.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant