Skip to content

Return 534 when a network restart fails on an unavailable resource - #14632

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:restart-network-resource-unavailable
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:restart-network-resource-unavailable

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator

Description

This PR makes restartNetwork report a failed restart the way restartVPC does.

RestartNetworkCmd.execute() let ResourceUnavailableException, ConcurrentOperationException and InsufficientCapacityException reach the async job dispatcher. The dispatcher logs those at ERROR as Unexpected exception while executing ... RestartNetworkCmd and fails the job with 530. RestartVPCCmd catches them and throws a ServerApiException instead.

RestartNetworkCmd.execute() now catches them in the same way, with the same logging:

  • ResourceUnavailableException: error code 534 (RESOURCE_UNAVAILABLE_ERROR), logged at WARN;
  • ConcurrentOperationException: 530 (INTERNAL_ERROR), logged at WARN;
  • InsufficientCapacityException: 533 (INSUFFICIENT_CAPACITY_ERROR).

The error text is the exception message in each case, as before. A restart that returns false still fails with 530 and Failed to restart network.

Fixes: #14631

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

  • New RestartNetworkCmdTest (mvn -pl api -am test -Dtest=RestartNetworkCmdTest), 5 tests, all pass: success response; false from the service gives 530; each of the three exceptions gives the error code listed above with the exception message.
  • Found in a lab test of another change: a refused restartNetwork failed with 530 and an ERROR stack trace, while the matching restartVPC failed with 534 and a WARN line. This change has not been run in that lab; the behaviour is covered by the unit tests.

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

Checked that nothing else calls RestartNetworkCmd.execute() and relies on the checked exceptions it declared; the API dispatcher is the only caller.

RestartNetworkCmd.execute() let ResourceUnavailableException,
ConcurrentOperationException and InsufficientCapacityException reach
the async job dispatcher, which logs them at ERROR as "Unexpected
exception while executing" and fails the job with 530. RestartVPCCmd
catches the same exceptions and maps them to ServerApiException, so a
refused restartVPC fails with 534 and a WARN line.

Catch them in RestartNetworkCmd the same way: 534 for
ResourceUnavailableException, 530 for ConcurrentOperationException and
533 for InsufficientCapacityException, each with the exception message.

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

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 18.32%. Comparing base (d02adcd) to head (f17a177).

Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14632      +/-   ##
============================================
- Coverage     18.32%   18.32%   -0.01%     
- Complexity    16644    16646       +2     
============================================
  Files          5939     5939              
  Lines        537768   537780      +12     
  Branches      65929    65929              
============================================
- Hits          98551    98547       -4     
- Misses       428008   428029      +21     
+ Partials      11209    11204       -5     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.41% <100.00%> (-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

Test report: restartNetwork refused because the router's host is Disconnected

Summary: restartNetwork cleanup=true with the router's host Disconnected now fails with error code 534. It is logged at WARN by RestartNetworkCmd, with no Unexpected exception line. That matches restartVPC.

Environment

  • A CloudStack 24.0 (main) build with this PR, alongside some of my other open PRs. Among them is engine: do not force the destroy stop while the host may reconnect #14233, which refuses a rolling restart while an old router's host is Disconnected. That refusal is the ResourceUnavailableException used here.
  • The PR targets 4.22; it wasn't run on a 4.22 build. 4.22's RestartNetworkCmd.execute() declares the same checked exceptions and doesn't catch them.
  • Three KVM hosts, one management server. A new isolated network with source NAT, with its router on host 2 and one VM.

Steps

  1. Stop the CloudStack agent on host 2. The host was Disconnected 2 s later.
  2. restartNetwork id=<network> cleanup=true.
  3. Start the agent again. Host 2 was Up 17 s later.

Results

  • The job failed with 534:
    errorcode: 534
    errortext: Resource [Host:2] is unreachable: Unable to replace router <router>: its host <host 2> is Disconnected and may still be running it. Retry once the host is Up, or stop the router with forced=true first.
    
  • Management server log: a single WARN, with no stack trace at ERROR:
    21:40:26,001 WARN  RestartNetworkCmd  Exception: com.cloud.exception.ResourceUnavailableException: Resource [Host:2] is unreachable: Unable to replace router ...
    
    Unexpected exception while executing ... RestartNetworkCmd: 0 lines.
  • The network still had its one router, Running on host 2. The refusal happens before anything is deployed.
  • Before this PR, the same refusal failed with 530 and an ERROR Unexpected exception while executing ... RestartNetworkCmd with a stack trace. I saw that in the engine: do not force the destroy stop while the host may reconnect #14233 lab run.

Result: pass.

Not covered: the ConcurrentOperationException (530) and InsufficientCapacityException (533) mappings. I had no cheap way to cause them live; they are covered by the unit tests.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restartNetwork reports a ResourceUnavailableException as an unexpected error (530), unlike restartVPC (534)

2 participants