Repository navigation
Conversation
A network with its own IP ranges (shared, or isolated with SpecifyIpRanges) allocates guest IPs only from those ranges. When they are all in use the allocation failed with a bare "Insufficient address capacity" scoped to the zone, which reads as the zone running out of public IPs. Say which network ran out, or that the requested IP is not available in it. The scope stays on the zone so the deployment retry logic is unchanged.
The resource reservation wrapper in deployVirtualMachine caught every exception other than ResourceAllocationException and CloudRuntimeException, logged it at ERROR with a stack trace and rethrew it as a CloudRuntimeException. An InsufficientCapacityException from NIC allocation therefore reached the API as an internal error with the raw exception text. Let it through so DeployVMCmd returns INSUFFICIENT_CAPACITY_ERROR with the exception message.
…ranges Cover GuestNetworkGuru.allocate() for isolated and shared networks with SpecifyIpRanges: both take the address from the network's IP ranges through allocateDirectIp, not from the whole CIDR.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #14958 +/- ##
============================================
+ Coverage 3.87% 21.17% +17.30%
- Complexity 0 21577 +21577
============================================
Files 499 6080 +5581
Lines 43120 551780 +508660
Branches 8198 73936 +65738
============================================
+ Hits 1670 116847 +115177
- Misses 41215 421140 +379925
- Partials 235 13793 +13558
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jmsperu
left a comment
There was a problem hiding this comment.
What I tested
Lab: KVM advanced zone, one management server, two KVM hosts, ACS 4.22.1.1.
Port to 4.22.1.1:
- The IpAddressManagerImpl hunk applies cleanly to 4.22.1.1.
- The two UserVmManagerImpl hunks do not apply as is. The method signatures on main have an extra
Long rootDiskKmsKeyIdparameter, which 4.22.1.1 does not have. Apart from that parameter, the change is the same: InsufficientCapacityException is added to thethrowsclause and to the multi-catch in getCheckedUserVmResource and getUncheckedUserVmResource. I ported it by hand with no other changes. - I compiled only the changed classes against the 4.22.1.1 jar and updated them into a copy of the jar. Nothing else in the jar changed (200,880 entries, 14 class files differ: IpAddressManagerImpl plus its 12 inner classes, and UserVmManagerImpl).
- The new GuestNetworkGuruAllocateTest is test-only. GuestNetworkGuru main code is not changed by this PR.
Setup:
- A test domain and account.
- A shared network with SpecifyIpRanges and a 2 address range (10.58.1.10 to .11).
- An isolated network with SpecifyIpRanges and a 3 address range (10.59.1.10 to .12).
- Each range filled with VMs (startvm=false).
Cases on each build, all as admin with deployVirtualMachine:
- Shared network, range full, deploy one more.
- Isolated network, range full, deploy one more.
- Isolated network, deploy asking for 10.59.1.11, which is already in use.
- Shared network, deploy asking for 10.58.1.10, which is already in use.
Before and after
| Case | Before (4.22.1.1) | After (PR) |
|---|---|---|
| Shared, range full | HTTP 530, errorcode 530, "Insufficient address capacity" | HTTP 533, errorcode 533, "Insufficient address capacity: no free IP address left in the IP ranges of network pr14958-shared" |
| Isolated, range full | 530, "Insufficient address capacity" | 533, "Insufficient address capacity: no free IP address left in the IP ranges of network pr14958-iso" |
| Isolated, requested IP in use | 530, "Insufficient address capacity" | 533, "Insufficient address capacity: the requested IP address 10.59.1.11 is not available in the IP ranges of network pr14958-iso" |
| Shared, requested IP in use | 530, "Insufficient address capacity" | 533, "Insufficient address capacity: the requested IP address 10.58.1.10 is not available in the IP ranges of network pr14958-shared" |
| Log, per failed deploy | WARN "Unable to get ip address in zone id=1, network id=...", ERROR [UserVmManagerImpl] "error during resource reservation and allocation ... InsufficientAddressCapacityException", ERROR [ApiServer] "unhandled exception executing api command ... CloudRuntimeException: Insufficient address capacity" | Same WARN line, then INFO [DeployVMCmdByAdmin] and INFO [ApiServer] with the new message. No ERROR lines. |
| Async job / alert | None (synchronous error), no alert | Same |
| Failed VM row | Error row, removed about a minute later | Same |
In both builds, VMs only got addresses from the network's own IP ranges.
Does it match the PR description
Yes. The codes, messages and log behaviour match the author's before and after table, including the requested-IP case. I also tested the shared requested-IP case, which the table does not list, and it gives the same kind of message.
One small difference I saw: the 533 response carries cserrorcode 9999, where the old 530 response had 0. That comes from the ServerApiException path in DeployVMCmd, not from this PR's code, and I do not think it matters.
CPU resource count check and the CI failure
The failing CI job is the Simulator CI group with test_cpu_project_limits. The failure is in test_01_project_counts_start_stop_instance, at line 190, which is the first assertion. It runs right after the VM is deployed in setUp, before any stop or start: AssertionError: 8 != 4. The project cputotal was double right after one 4-core deploy.
I ran the same sequence on both builds:
- a project with a CPU limit of 4;
- a 2-core offering;
- deploy a running VM;
- stop, start;
- updateResourceCount for the project and the account;
- destroy.
| Step | 4.22.1.1 | PR build |
|---|---|---|
| Before deploy | project 0 | project 0 |
| After deploy | project 2, domain +2 | project 2, domain +2 |
| After stop | 2 | 2 |
| After start | 2 | 2 |
| After updateResourceCount | 2 | 2 |
| After destroy | 0 | 0 |
The account count did not change in either build, as expected for project VMs. The project count was correct at every step on both builds.
What this suggests:
- The PR only changes behaviour when an InsufficientCapacityException is raised during deploy. In the CI test, the deploy succeeds, so the changed path is not taken.
- That job group passed on every other Simulator CI run I checked from 2 December onwards (about 20 runs on other PRs and main). This was the only failure, on attempt 1.
- My lab run did not reproduce the double count with or without the PR.
To me this looks like an intermittent failure rather than something this PR causes. One caveat: my run was not identical to the CI test. The CI test deploys as a domain admin with no network given, so the project gets a new default isolated network, on the simulator with a 4-core offering. I used admin with an L2 network. Re-running the failed job is the cheapest way to confirm.
Code comments
-
Scope of the new message. Only the last zone-scoped throw in listAvailablePublicIps uses getInsufficientAddressCapacityMessage. The pod-scoped throw (podId != null) and the earlier VirtualNetwork throw keep the plain "Insufficient address capacity". Advanced zone shared and isolated networks go through allocateDirectIp with a null podId, so they get the new message, and that is the case in #12772. A basic zone or pod-based direct network that runs out of addresses will still show the old text. That is fine for this fix, but a short note in the description would help, or a follow-up to name the network there too.
-
Requested-IP wording. "is not available in the IP ranges of network X" also covers a requested IP that is outside the range, not only one that is taken. The wording works for both, which I think is right.
-
The exception scope stays DataCenter, so the planner and retry logic see the same exception type and scope as before. Good.
-
Rethrowing InsufficientCapacityException from the reservation wrapper: the CheckedReservation resources are still closed by try-with-resources. In my runs, no reservation leaked after the failed deploys (the counts above were taken after the capacity tests on the same domain and stayed correct). The author checked the other callers (autoscale, CKS, Veeam restore), and they already handle InsufficientCapacityException.
-
Exposing the network name in the error is fine. The caller passed that network in the request and already has access to it.
-
Minor, not from this PR: the WARN line still says "network id=467" with the internal id. The INFO line from DeployVMCmd prints the exception with no separator before "Scope=" ("...pr14958-sharedScope=interface com.cloud.dc.DataCenter"). That comes from the exception's toString and is pre-existing.
-
Codecov reports patch coverage of 58% (5 lines). The UserVmManagerImpl catch changes are the uncovered part. A unit test that makes getUncheckedUserVmResource throw InsufficientAddressCapacityException and checks it comes out unwrapped would cover it, if the maintainers want that.
-
Backport note: the UserVmManagerImpl hunks need the trivial signature adjustment for 4.22, because of rootDiskKmsKeyId.
Summary
Tested on a live KVM zone: the change works as described, and I found no regression in the CPU resource count. Comment 1 is a non-blocking note. Could you re-run the failed Simulator CI job? The failing test does not touch the changed path, so I expect it to pass on a re-run.
Description
A network with its own IP ranges (shared, or isolated with SpecifyIpRanges) gives guest VMs IPs only from those ranges. When the ranges were full, deploying a VM failed as an internal error (530) with just "Insufficient address capacity", scoped to the zone, and the management server logged a stack trace at ERROR. That reads like the zone ran out of public IPs, which is what #12772 ran into.
This names the network in that error, or the requested IP when a specific one was asked for and is already taken. It also lets the capacity exception through the resource reservation wrapper in deploy, so the API returns INSUFFICIENT_CAPACITY_ERROR (533) with that message instead of an internal error. The exception scope stays on the zone, so the deployment retry logic is unchanged.
#14087 tried to fix this by making isolated networks with SpecifyIpRanges allocate from the whole CIDR. As @Damans227 pointed out there, that ignores the start and end IP set on the network. This keeps allocation on the network's IP ranges, with a test for it, and fixes the error instead.
Fixes: #12772
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
N/A
How Has This Been Tested?
Unit tests for the new messages and for GuestNetworkGuru.allocate() on isolated and shared networks with SpecifyIpRanges. The isolated allocate test fails with the change from #14087 (allocateDirectIp is never called) and passes here.
Live on a KVM advanced zone with a management server and 2 hosts: an isolated network with SpecifyIpRanges and a 3 address range, and a shared network with a 2 address range. Filled each range with VMs, then deployed one more, and deployed one asking for an IP that was already taken. In both runs the VMs only got IPs from the network ranges.
Before:
After:
How did you try to break this feature and the system with this change?
Checked the other callers that create VMs through the same path (autoscale, Kubernetes clusters, Veeam restore). They already catch InsufficientCapacityException next to CloudRuntimeException, so their handling does not change. Public IP and system VM allocation keep the old message.