Skip to content

add a maintenance prepare error event - #13669

Open
DaanHoogland wants to merge 1 commit into
4.20from
ghi13324-eventEmit
Open

add a maintenance prepare error event#13669
DaanHoogland wants to merge 1 commit into
4.20from
ghi13324-eventEmit

Conversation

@DaanHoogland

Copy link
Copy Markdown
Contributor

Description

This PR...

Fixes: #13324

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?

@DaanHoogland DaanHoogland added this to the 4.20.4 milestone Jul 22, 2026

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

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a new CloudStack event type to record failures while preparing a host for maintenance, and extends unit tests to validate event emission and entity mapping.

Changes:

  • Introduce MAINT.PREPARE.ERROR event type and map it to Host entity.
  • Emit an error ActionEvent when a host enters PrepareForMaintenanceWithErrors.
  • Add/extend unit tests validating the emitted event and entity mapping.

Reviewed changes

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

File Description
server/src/main/java/com/cloud/resource/ResourceManagerImpl.java Emits a new error event when host preparation for maintenance fails due to VM/migration issues.
api/src/main/java/com/cloud/event/EventTypes.java Adds the new maintenance prepare error event constant and maps it to Host.
server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java Verifies the new event is emitted and mapped to the correct entity class.

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

Comment thread server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
Comment thread server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
Comment thread api/src/main/java/com/cloud/event/EventTypes.java
@sonarqubecloud

Copy link
Copy Markdown

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

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

@DaanHoogland DaanHoogland changed the title add an maintenance prepare error event add a maintenance prepare error event Jul 30, 2026
@DaanHoogland DaanHoogland linked an issue Jul 30, 2026 that may be closed by this pull request
@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@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-16660)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 51042 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr13669-t16660-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

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 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (4)

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java:1731

  • The event description uses %s with host, which relies on HostVO.toString() and can produce unstable/log-noisy output if toString() changes. Prefer a stable identifier (e.g., host id/uuid/name) in the message so logs and external consumers get consistent descriptions.
        ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(),
                EventVO.LEVEL_ERROR, EventTypes.EVENT_MAINTENANCE_PREPARE_ERROR,
                String.format("failed to prepare host %s for maintenance due to migration or VM state errors", host), host.getId(), null, 0);

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java:1729

  • CallContext is retrieved twice on the same line. Store CallContext.current() in a local variable and reuse it to avoid duplicate thread-local lookups and make the code easier to read (and safer if the implementation ever changes).
        ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(),

server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java:459

  • This assertion hard-codes the full formatted description using the host object's toString(), which makes the test brittle if toString() is modified (or if the mock's string representation changes). Consider asserting on stable substrings/fields (e.g., includes host id/uuid) or matching the description with a less fragile matcher aligned with the intended message contract.
        String expectedDescription = String.format("failed to prepare host %s for maintenance due to migration or VM state errors", host);
        actionEventUtilsMocked.verify(() -> ActionEventUtils.onCompletedActionEvent(
                anyLong(), anyLong(), eq(EventVO.LEVEL_ERROR), eq(EventTypes.EVENT_MAINTENANCE_PREPARE_ERROR),
                eq(expectedDescription), eq(hostId), isNull(), eq(0L)));

api/src/main/java/com/cloud/event/EventTypes.java:461

  • The PR description template is largely unfilled (type of change, severity/scale, and testing notes), but this change introduces a new externally visible event type. Please update the PR description with concrete behavior change details and how it was tested so automation/maintainers can correctly label and document it.
    public static final String EVENT_MAINTENANCE_PREPARE_ERROR = "MAINT.PREPARE.ERROR";

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.

Missing event - ErrorinPrepareForMaintenance

4 participants