Repository navigation
VPC: associate tier public IPs when a public IP of the tier has firewall rules - #14681
adestis-mf wants to merge 1 commit into
Conversation
…all rules Since apache#12706 the Firewall service for public IPs of a VPC is provided by the VPC offering; the network offerings of the tiers do not list it. applyIpAssociations passes the services of the public IPs of a tier to VpcVirtualRouterElement.applyIps, which associates the IPs only when it can handle every one of these services on the tier. Once any public IP of the tier has a firewall rule, Firewall is in that set, canHandle(tier, Firewall) is false, and applyIps skips the association without an error: - port forwarding and load balancing rules on a new IP are applied, but the IP never reaches the router, also not on a network restart; - an IP whose last rule is removed stays configured on the router. Check the Firewall service on the VPC in that case, as applyFWRulesInVPC does. Other services and canHandle(network, service) are unchanged. Log when the IP association is skipped.
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
2 open issues
What changed in this PR
This PR fixes VPC tier public IP association logic so tiers can still associate IPs on the VPC virtual router when the Firewall service is provided by the VPC offering (not the tier network offering), and adds unit tests to cover the corrected behavior.
Changes:
- Update
applyIpsto use a newcanHandleIpServicecheck that consults VPC capability specifically for the Firewall service. - Add debug logging when IP association is skipped due to service handling constraints.
- Add unit tests validating the new association behavior and ensuring only Firewall consults the VPC.
| File | Description |
|---|---|
| server/src/main/java/com/cloud/network/element/VpcVirtualRouterElement.java | Adds canHandleIpService and updates applyIps to handle Firewall via VPC capability checks, plus debug logging when skipping association. |
| server/src/test/java/com/cloud/network/element/VpcVirtualRouterElementTest.java | Adds focused unit tests for applyIps behavior when Firewall is (or isn’t) provided by the VPC, and tests for canHandleIpService decision boundaries. |
Review effort: Lite
| return true; | ||
| } | ||
| if (Service.Firewall.equals(service) && network.getVpcId() != null) { | ||
| return canHandle(_vpcDao.findById(network.getVpcId()), service); |
There was a problem hiding this comment.
canHandle(Vpc, Service) already returns false for a null VPC (it is the first check in that
method), so there is no NullPointerException here: if the VPC cannot be found, the IP association is
skipped, as it was before this change, and the new debug line logs that. applyFWRulesInVPC goes
through the same method. I would leave it as it is.
| private Network mockVpcTier() { | ||
| final Network network = Mockito.mock(Network.class); | ||
| when(_networkMdl.getPhysicalNetworkId(network)).thenReturn(1L); | ||
| when(network.getId()).thenReturn(200L); | ||
| when(network.getVpcId()).thenReturn(100L); | ||
| when(_networkMdl.isProviderEnabledInPhysicalNetwork(1L, Network.Provider.VPCVirtualRouter.getName())).thenReturn(true); | ||
| return network; | ||
| } | ||
|
|
||
| private VpcVO mockVpc(final boolean vpcProvidesFirewall) { | ||
| final VpcVO vpc = Mockito.mock(VpcVO.class); | ||
| when(vpc.getId()).thenReturn(100L); | ||
| when(vpc.getZoneId()).thenReturn(1L); | ||
| when(_vpcDao.findById(100L)).thenReturn(vpc); | ||
| when(_networkMdl.isProviderEnabledInZone(1L, Network.Provider.VPCVirtualRouter.getName())).thenReturn(true); | ||
| when(_vpcMgr.isProviderSupportServiceInVpc(100L, Network.Service.Firewall, Network.Provider.VPCVirtualRouter)).thenReturn(vpcProvidesFirewall); | ||
| return vpc; | ||
| } |
There was a problem hiding this comment.
The new helpers use the same values as the existing testCanHandleFirewallUsesVpcCapability in this
class, which has 1L, 100L and 200L inline as well. I kept that style so the new tests read like
the existing one and the change stays small. Happy to switch both to named constants if reviewers
prefer.
|
@RosiKyu @nvazquez could this be considered for the 24.0 milestone? It fixes #14146 (moved to 25.0 earlier today) and #14669: in a VPC whose offering includes the Firewall service (#12706, new in 4.23.0.0), once a public IP of a tier has a firewall rule, further public IPs of that tier are no longer added to or removed from the virtual router. The change is limited to one method in |
|
@adestis-mf , sure. Thank you for the clarification. Have mmoved #14146 back to 24.0 |
|
@blueorangutan package |
|
@RosiKyu a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 20004 |


Description
This PR fixes adding and removing public IPs of a VPC tier on the VPC virtual router when the VPC
offering provides the Firewall service for public IPs (#12706).
IpAddressManagerImpl.applyIpAssociationspassesVpcVirtualRouterElement.applyIpsthe union ofthe services of the public IPs of a tier. Once a public IP of the tier has a firewall rule,
Firewallis part of that union.applyIpsassociates the IPs only whencanHandle(tier, service)is true for every service, and the tier's network offering does notlist the Firewall service, because #12706 puts it on the VPC offering.
applyIpsthen skips theassociation and returns
true:router, also not on a network restart;
applyIpsnow checks the Firewall service on the VPC when the tier does not provide it(
canHandle(Vpc, Firewall), the same check as inapplyFWRulesInVPC). Other services andcanHandle(Network, Service)are unchanged, sotestCanHandleFirewallUsesVpcCapabilitystillholds. A debug line is logged when the association is skipped, so the case is no longer silent.
What changes: in a VPC whose offering provides the Firewall service through the VPC virtual
router, public IPs of a tier are added to and removed from the router the same way as in a VPC
without the Firewall service. The IPs passed to the element are the same as before. IPs that have
only firewall rules and the source NAT IP of the VPC are not associated with a tier and are still
not passed. VPC offerings whose Firewall provider is not the VPC virtual router behave as before.
This targets
main: #12706 is not in4.22, and there is no4.23branch. The commit alsoapplies cleanly on top of the 4.23.0.0 tag.
Fixes: #14146
Fixes: #14669
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
New unit tests in
VpcVirtualRouterElementTest:testApplyIpsAssociatesTierIpsWhenTheVpcProvidesFirewall: the tier does not provide Firewall,the VPC does → the IPs are associated.
testApplyIpsSkipsAssociationWhenNeitherTierNorVpcProvidesFirewall: neither provides it → noassociation, no router lookup.
testCanHandleIpServiceUsesTheVpcOnlyForFirewall: other services never consult the VPC.testCanHandleIpServiceKeepsTierFirewall: when the tier provides Firewall, the VPC is notconsulted.
With the previous check (
canHandle(network, service)) put back intoapplyIps,testApplyIpsAssociatesTierIpsWhenTheVpcProvidesFirewallfails.VpcVirtualRouterElementTest: 8 tests, 0 failures. The tests incom.cloud.network.element,com.cloud.network.router,com.cloud.network.vpc,com.cloud.network.lb,com.cloud.network.firewall,IpAddressManager*TestandNetworkModel*Testalso pass (352tests, 0 failures, 4 skipped). Checkstyle reports no violations.
The behaviour without this change was reproduced on 4.23.0.0; steps and results are in #14146.
The patched build has not been run on a live system.
How did you try to break this feature and the system with this change?
I went through the cases in which the changed check decides differently:
so they are not passed to
applyIps, as before;has a firewall rule;
firewall rules;