Skip to content

Conversation

shwstppr
Copy link
Contributor

@shwstppr shwstppr commented Oct 1, 2025

Description

Fixes #9602
Fixes #11517

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

Feature/Enhancement Scale

  • Major
  • Minor

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?

Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.50%. Comparing base (2c1aad4) to head (59069d4).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ain/java/com/cloud/network/NetworkServiceImpl.java 33.33% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #11767   +/-   ##
=========================================
  Coverage     17.50%   17.50%           
- Complexity    15427    15432    +5     
=========================================
  Files          5894     5894           
  Lines        526845   526849    +4     
  Branches      64334    64336    +2     
=========================================
+ Hits          92232    92246   +14     
+ Misses       424236   424226   -10     
  Partials      10377    10377           
Flag Coverage Δ
uitests 3.61% <ø> (ø)
unittests 18.56% <33.33%> (+<0.01%) ⬆️

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.

@shwstppr shwstppr requested a review from Copilot October 1, 2025 07:25
Copy link
Contributor

@Copilot 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

This PR fixes consistent behavior for list APIs when project parameter is set to -1, ensuring that all networks (including project networks) are included in the search results when project=-1 is specified.

Key changes:

  • Modified the addProjectNetworksConditionToSearch method to handle the special case of projectId=-1
  • Updated all callers to pass the projectId parameter consistently
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
NetworkServiceImpl.java Enhanced project network filtering logic to handle project=-1 case and updated method signatures
NetworkServiceImplTest.java Added unit tests to verify the new project network filtering behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

private void addProjectNetworksConditionToSearch(SearchCriteria<NetworkVO> sc, boolean skipProjectNetworks) {
sc.getJoin("account").addAnd("type", skipProjectNetworks ? Op.NEQ : Op.EQ, Account.Type.PROJECT);
protected void addProjectNetworksConditionToSearch(SearchCriteria<NetworkVO> sc, boolean skipProjectNetworks, Long projectId) {
if (!skipProjectNetworks && projectId == -1) {
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The comparison projectId == -1 will fail if projectId is null. Since the method signature accepts Long projectId (which can be null), this should use Long.valueOf(-1L).equals(projectId) or add a null check first.

Suggested change
if (!skipProjectNetworks && projectId == -1) {
if (!skipProjectNetworks && Long.valueOf(-1L).equals(projectId)) {

Copilot uses AI. Check for mistakes.

additionalSC.addOr("id", SearchCriteria.Op.SC, domainSC);
}
}

Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The method signature change from private to protected and adding a Long parameter is a breaking change for subclasses. Consider maintaining backward compatibility by overloading the method instead of changing the existing signature.

Suggested change
/**
* Original method signature for backward compatibility.
*/
private void addProjectNetworksConditionToSearch(SearchCriteria<NetworkVO> sc, boolean skipProjectNetworks) {
sc.getJoin("account").addAnd("type", skipProjectNetworks ? Op.NEQ : Op.EQ, Account.Type.PROJECT);
sc.addAnd("id", Op.SC, sc.getJoin("account"));
}
/**
* Overloaded method with additional projectId parameter.
*/

Copilot uses AI. Check for mistakes.

@bernardodemarco
Copy link
Member

@shwstppr, thanks for the PR! I believe after this one gets merged, we'll be able to move forward with the apache/cloudstack-cloudmonkey#185 PR.

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.

Inconsistent behaviour in handling projectid param for different list APIs Enabling the Project toggle doesn't list the admin created networks
2 participants