Skip to content

Fix VPC restart with multi-CIDR networks: handle comma-separated CIDR…#12622

Open
jeanvetorello wants to merge 3 commits intoapache:4.22from
jeanvetorello:fix/vpc-restart-cidr-minimal
Open

Fix VPC restart with multi-CIDR networks: handle comma-separated CIDR…#12622
jeanvetorello wants to merge 3 commits intoapache:4.22from
jeanvetorello:fix/vpc-restart-cidr-minimal

Conversation

@jeanvetorello
Copy link
Contributor

#12621
… in NetworkVO.equals()

When a network has multiple CIDRs (e.g. '192.168.2.0/24,160.0.0.0/24'), NetworkVO.equals() passes the raw comma-separated string to NetUtils.isNetworkAWithinNetworkB() which expects a single CIDR, causing 'cidr is not formatted correctly' error during VPC restart with cleanup=true.

Extract only the first CIDR value before passing to NetUtils.

Description

This PR...

Types of changes

Bug fix (non-breaking change which fixes an issue)

Bug Severity

  • Major

Screenshots (if appropriate):

How Has This Been Tested?

  • Reproduced the issue on a CloudStack 4.21.0.0 environment with two public IP ranges
    on different VLANs assigned to the same VPC
  • Applied the fix and confirmed VPC restart with cleanup=true completes successfully
  • Verified unit tests pass for NetworkVO.equals() with both single and comma-separated CIDRs

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

@sureshanaparti
Copy link
Contributor

@blueorangutan package

@sureshanaparti
Copy link
Contributor

@blueorangutan package

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.92%. Comparing base (7aa0558) to head (c9e7a8b).

Files with missing lines Patch % Lines
.../cloud/configuration/ConfigurationManagerImpl.java 0.00% 5 Missing ⚠️
...src/main/java/com/cloud/network/dao/NetworkVO.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12622      +/-   ##
============================================
+ Coverage     17.61%   17.92%   +0.31%     
- Complexity    15664    16179     +515     
============================================
  Files          5917     5949      +32     
  Lines        531402   534064    +2662     
  Branches      64971    65303     +332     
============================================
+ Hits          93596    95751    +2155     
- Misses       427252   427555     +303     
- Partials      10554    10758     +204     
Flag Coverage Δ
uitests 3.66% <ø> (-0.04%) ⬇️
unittests 19.03% <0.00%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@sureshanaparti
Copy link
Contributor

@blueorangutan package

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes VPC restart failures for multi-CIDR networks by ensuring NetworkVO.equals() does not pass a raw comma-separated CIDR list into NetUtils.isNetworkAWithinNetworkB(), which expects a single CIDR.

Changes:

  • Normalize cidr values in NetworkVO.equals() by extracting the first CIDR from comma-separated strings before comparing.

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

Comment on lines +603 to +605
return NetUtils.isNetworkAWithinNetworkB(
com.cloud.utils.StringUtils.getFirstValueFromCommaSeparatedString(cidr),
com.cloud.utils.StringUtils.getFirstValueFromCommaSeparatedString(that.cidr));
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equals is using NetUtils.isNetworkAWithinNetworkB(...), which is not symmetric (A within B does not imply B within A). That means NetworkVO.equals can violate the Java equals contract, and it is also inconsistent with hashCode() (which is based only on id). Consider switching equals/hashCode to be id-based like other VOs, or (if CIDR-based equality is truly intended) make the comparison symmetric and update hashCode accordingly (e.g., based on the same normalized CIDR(s) and trafficType).

Copilot uses AI. Check for mistakes.
@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland 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.

@blueorangutan
Copy link

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

@weizhouapache
Copy link
Member

as we discussed in the comments of #12621, we need to work on another solution

can you work on the fix ? cc @jeanvetorello @sureshanaparti

@sureshanaparti
Copy link
Contributor

@jeanvetorello can you rebase this PR with 4.22 branch, and address the outstanding comments.

jean and others added 3 commits March 10, 2026 10:55
… in NetworkVO.equals()

When a network has multiple CIDRs (e.g. '192.168.2.0/24,160.0.0.0/24'),
NetworkVO.equals() passes the raw comma-separated string to
NetUtils.isNetworkAWithinNetworkB() which expects a single CIDR,
causing 'cidr is not formatted correctly' error during VPC restart
with cleanup=true.

Extract only the first CIDR value before passing to NetUtils.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…works

addCidrAndGatewayForIpv4/Ipv6 (introduced by PR apache#11249) was called for all
network types without checking if the network is Public. This caused
comma-separated CIDRs to be stored on Public networks, which then triggered
'cidr is not formatted correctly' errors during VPC restart.

Add TrafficType.Public guard in both the VLAN creation (addCidr) and
VLAN deletion (removeCidr) paths in ConfigurationManagerImpl.
@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@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

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 17078

}

return NetUtils.isNetworkAWithinNetworkB(cidr, that.cidr);
final String normalizedCidr = com.cloud.utils.StringUtils.getFirstValueFromCommaSeparatedString(cidr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes should be reverted, I think ?

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.

VPC restart with cleanup fails when VPC has multiple public IP ranges from different VLANs — "cidr is not formatted correctly"

6 participants