Visitar URL original
Usage: Fix usage_network_offering row mismatches on nic removal and default-nic swap by Pearl1594 · Pull Request #14341 · apache/cloudstack · GitHub
Skip to content

Usage: Fix usage_network_offering row mismatches on nic removal and default-nic swap - #14341

Open
Pearl1594 wants to merge 1 commit into
4.22from
usage-billing-nic-removal-and-default-swap
Open

Pearl1594 wants to merge 1 commit into
4.22from
usage-billing-nic-removal-and-default-swap

Conversation

@Pearl1594

Copy link
Copy Markdown
Contributor

Description

This PR fixes 2 issues:

  1. Removing a nic can silently close a different nic's still-open usage record : UsageNetworkOfferingDaoImpl.update()'s UPDATE_DELETED SQL matched on (account_id, vm_instance_id, network_offering_id) only - not nic_id. On a VM with two nics on two different networks that happen to share one network offering, removing one nic would also close the other nic's still-active usage row, silently under-billing it from that point on. Fixed by matching on the row's own primary key (id).

  2. updateDefaultNicForVirtualMachine can wipe billing for the nic becoming default : The default-nic swap emits 4 usage events: REMOVE(old-default), ASSIGN(new-default), REMOVE(new-default's stale row), ASSIGN(old-default's new row), in that order. Because a default-nic swap never changes which network a nic is on, the 3rd call's REMOVE always collides with the row the 2nd call's ASSIGN just created (identical nic/offering/network, nothing to disambiguate by). The lookup can't tell the stale row from the brand-new one and closes both, leaving the nic becoming default with zero open billing until the VM's next full stop/start. Fixed by reordering to close-before-open per nic (REMOVE old, REMOVE new's stale row, ASSIGN new, ASSIGN old)

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

Screenshots (if appropriate):

How Has This Been Tested?

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

@Pearl1594
Pearl1594 marked this pull request as ready for review October 7, 2026 13:10
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.02%. Comparing base (2974af8) to head (17a9718).

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 0.00% 2 Missing ⚠️
...m/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14341      +/-   ##
============================================
- Coverage     18.02%   18.02%   -0.01%     
+ Complexity    16250    16248       -2     
============================================
  Files          5936     5936              
  Lines        535823   535821       -2     
  Branches      65612    65612              
============================================
- Hits          96582    96560      -22     
- Misses       428242   428264      +22     
+ Partials      10999    10997       -2     
Flag Coverage Δ
uitests 4.04% <ø> (ø)
unittests 19.09% <0.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.

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

@blueorangutan

Copy link
Copy Markdown

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

@Pearl1594 Pearl1594 mentioned this pull request Oct 7, 2026
2 of 9 tasks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants