Repository navigation
network: handle missing network when releasing public IP - #14133
xujiantop-crypto wants to merge 2 commits into
Conversation
Signed-off-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
Signed-off-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14133 +/- ##
=========================================
Coverage 17.94% 17.94%
- Complexity 16145 16151 +6
=========================================
Files 5928 5928
Lines 535174 535176 +2
Branches 65494 65495 +1
=========================================
+ Hits 96017 96057 +40
+ Misses 428228 428181 -47
- Partials 10929 10938 +9
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:
|
|
Thanks for the fix and the tests. I tried it on a KVM zone with the steps from #14068 (VPC offering with the Firewall service, a tier with a VM, a public IP with a port forwarding and a firewall rule, then remove the VM and the tier). Without the change, deleting the VPC fails with With the change, both work. The VPC is deleted, and the released IP goes back to Free with I was curious where the stale id comes from. On tier removal, One thing I noticed: after releasing the IP with the VPC kept, the IP is still configured on the VPC router's public interface, with an iptables rule for it, since no ipassoc is sent in the new path. As the IP is Free again, it could be given to another network while the old router still holds it. Would it make sense to apply the association through the VPC in that case, since the router is still there, or to clear the association when the tier is removed so the normal release path runs? Either way, keeping the guard as a safety net sounds good to me. |
|
@blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19842 |
|
@blueorangutan test |
There was a problem hiding this comment.
Warning
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.
Copilot review overview
3 open issues
Whenip.getAssociatedWithNetworkId()is non-null but_networksDao.findById(...)returns null,… · New This test mutates an internal field directly, which tightly couples the test to the class’s… · New This assertion hard-codes the entity type string. If the production code uses a constant/enum (or… · New
What changed in this PR
Fixes a VPC teardown failure where releasing a public IP could reference a deleted network record, causing a NullPointerException during disassociation.
Changes:
- Guard
applyIpAssociationsbehind a successful associated-network lookup to avoid dereferencing a missing network. - Add regression + behavioral tests covering missing-network release/quarantine/unassignment behavior and existing-network association success/failure paths.
| File | Description |
|---|---|
| server/src/main/java/com/cloud/network/IpAddressManagerImpl.java | Avoids calling applyIpAssociations when the associated network lookup returns null. |
| server/src/test/java/com/cloud/network/IpAddressManagerTest.java | Adds targeted tests for missing-network release behavior and existing-network association outcomes. |
Review effort: Lite
| Network associatedNetwork = null; | ||
| if (ip.getAssociatedWithNetworkId() != null) { | ||
| Network network = _networksDao.findById(ip.getAssociatedWithNetworkId()); | ||
| associatedNetwork = _networksDao.findById(ip.getAssociatedWithNetworkId()); | ||
| } | ||
|
|
||
| if (associatedNetwork != null) { | ||
| try { | ||
| if (!applyIpAssociations(network, rulesContinueOnErrFlag)) { | ||
| logger.warn("Unable to apply ip address associations for " + network); | ||
| if (!applyIpAssociations(associatedNetwork, rulesContinueOnErrFlag)) { | ||
| logger.warn("Unable to apply ip address associations for " + associatedNetwork); |
| ipAddressManager._networkModel = mock(NetworkModel.class); | ||
| when(ipAddressManager._networkModel.getElementImplementingProvider(Network.Provider.VPCVirtualRouter.getName())).thenReturn(element); | ||
|
|
| verify(ipAddressManager).addPublicIpAddressToQuarantine(ipAddressVoMock, account.getDomainId()); | ||
| verify(ipAddressDao).unassignIpAddress(dummyID); | ||
| verify(element).releaseIp(ipAddressVoMock); | ||
| verify(annotationDao).removeByEntityType("PUBLIC_IP_ADDRESS", UUID); |
|
@blueorangutan test |
|
@RosiKyu a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-17552)
|
|
@xujiantop-crypto thanks for the fix. Could you please rebase it onto main and change the base branch to main? |
@RosiKyu , is there a reason this cannot go into 4.22? |


Fixes #14068
During VPC teardown, a public IP can retain its associated network ID after the tier's network record has been deleted.
disassociatePublicIpAddresspasses the missing network toapplyIpAssociations, which dereferences it and aborts VPC deletion with aNullPointerException.Resolve the associated network before choosing the release path. When the network no longer exists, a releasing IP follows the existing quarantine and unassignment path. The association path continues to be used when the network exists.
The regression test supplies a non-null associated network ID whose DAO lookup returns null while the VPC still exists. It verifies successful release, quarantine, IP unassignment, VPC provider cleanup, annotation cleanup and lock release, without calling
applyIpAssociations. Additional tests cover successful and failed associations when the network exists, and prevent repeated quarantine/unassignment of an already free IP when the network is missing.This targets
4.22in accordance with the contribution guide's release-branch policy for bug fixes; the affected code is also present there.Validation
NullPointerExceptionon the unfixed4.22base.IpAddressManagerTestpasses: 30 tests, 0 failures/errors/skips. All 25 selected reactor modules succeed, with 0 Checkstyle violations (JDK 11).git diff --checkpasses.The Maven download plugin could not retrieve the system VM checksum file in this environment. I downloaded the unmodified official
https://download.cloudstack.org/systemvm/4.22/sha512sum.txttoengine/schema/dist/systemvm-templates/sha512sum.txtand ran:mvn -B -pl server -am -Dtest=IpAddressManagerTest -Dsurefire.failIfNoSpecifiedTests=false -Ddownload.plugin.skip=true testOnly the redundant download was skipped; compilation, Checkstyle and the selected tests ran. No build configuration changes are included.
For an environment-level check, follow the steps in #14068: create a VPC offering with firewall service enabled, deploy a tier and VM, apply a public-IP firewall rule, remove the VM and tier, then destroy the VPC. The VPC should be removed without the missing-network exception and the public IP should be released. This full VPC scenario has not been run locally.