Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix listing of VMs with removed NICs #10204

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

bernardodemarco
Copy link
Collaborator

Description

Currently, when listing VMs by network (networkid) or VPC (vpcid), CloudStack does not check whether the VMs still belong to the specified network or VPC. Therefore, this PR fixes this issue by only filtering the VMs that have non-removed NICs in the specified network or VPC.

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?

First, I created an isolated network (nw-01) and a VPC (vpc-01) with two tiers (tier-01 and tier-02). Next, I deployed a VM (vm-01) with one NIC in each one of these networks.

image

After that, I checked that the listVirtualMachines API had the same behavior as prior to the PR changes:

List VMs that belong to the nw-01 network
(localcloud) 🌍 > listVirtualMachines networkid="f839708e-a21b-4116-a978-c2b6155fa5db" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}
List VMs that belong to the tier-01 network
(localcloud) 🐛 > listVirtualMachines networkid="58932108-cb7b-4be8-8663-bde09fc98920" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}
List VMs that belong to the tier-02 network
(localcloud) 🐀 > listVirtualMachines networkid="c17a596c-8ac9-483f-84cd-a55dcca0929d" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}
List VMs that belong to the vpc-01 VPC
(localcloud) 🐃 > listVirtualMachines vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}
List VMs that belong to the vpc-01 VPC and tier-01 tier
(localcloud) 🦈 > listVirtualMachines vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" networkid="58932108-cb7b-4be8-8663-bde09fc98920" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}
List VMs that belong to the vpc-01 VPC and tier-02 tier
(localcloud) 🐦 > listVirtualMachines vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" networkid="c17a596c-8ac9-483f-84cd-a55dcca0929d" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}

Next, I removed the NIC associated to the nw-01 network from the VM. When listing the VMs by that network, I verified that no VMs were returned:

List VMs that belong to the nw-01 network
(localcloud) 🐃 > listVirtualMachines networkid="f839708e-a21b-4116-a978-c2b6155fa5db" filter=displayname
(localcloud) 🐰 >

Then, I removed the NIC associated to the tier-02 tier. When listing the VMs by that network, I verified that no VMs were returned:

List VMs that belong to the tier-02 network
(localcloud) 🐰 > listVirtualMachines networkid="c17a596c-8ac9-483f-84cd-a55dcca0929d" filter=displayname
(localcloud) 🦂 >

I also verified that when listing the VMs by the tier-02 tier and the vpc-01 VPC, no VMs were returned:

List VMs that belong to the vpc-01 VPC and tier-02 tier
(localcloud) 🦂 > listVirtualMachines vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" networkid="c17a596c-8ac9-483f-84cd-a55dcca0929d" filter=displayname
(localcloud) 🐋 >

Furthermore, when only listing by VPC, the VM was returned since it still had a NIC associated to the tier-01 network:

List VMs that belong to the vpc-01 VPC
(localcloud) 🐋 > listVirtualMachines vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" filter=displayname
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "vm-01"
    }
  ]
}

Next, in order to be able to remove the tier-01 NIC, I added a NIC corresponding to a Layer 2 network, and set it to be the default VM's NIC. After removing the tier-01 NIC, I verified that no VMs were returned when listing by the tier-01 network:

List VMs that belong to the tier-01 network
(localcloud) 🍄 > listVirtualMachines networkid="58932108-cb7b-4be8-8663-bde09fc98920" filter=displayname
(localcloud) 🌴 >

No VMs were returned when listing by the vpc-01 VPC and tier-01 network:

List VMs that belong to the vpc-01 VPC and tier-01 tier
(localcloud) 🌴 > listVirtualMachines networkid="58932108-cb7b-4be8-8663-bde09fc98920" vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" filter=displayname
(localcloud) 🐐 >

No VMs were returned when listing by the vpc-01 VPC:

List VMs that belong to the vpc-01 VPC
(localcloud) 🐐 > listVirtualMachines  vpcid="16938b3c-955a-475f-b72d-f60ad3814c7b" filter=displayname
(localcloud) 🌍 >

Fixes #10188

@bernardodemarco
Copy link
Collaborator Author

@blueorangutan package

@blueorangutan
Copy link

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

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 15.13%. Comparing base (9967bb3) to head (7693008).
Report is 4 commits behind head on 4.19.

Files with missing lines Patch % Lines
...ain/java/com/cloud/api/query/QueryManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.19   #10204      +/-   ##
============================================
- Coverage     15.13%   15.13%   -0.01%     
  Complexity    11274    11274              
============================================
  Files          5408     5408              
  Lines        473974   473975       +1     
  Branches      57813    57813              
============================================
  Hits          71730    71730              
- Misses       394227   394228       +1     
  Partials       8017     8017              
Flag Coverage Δ
uitests 4.30% <ø> (ø)
unittests 15.85% <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 Sentry.
📢 Have feedback on the report? Share it here.

@blueorangutan
Copy link

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

@DaanHoogland DaanHoogland linked an issue Jan 20, 2025 that may be closed by this pull request
Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm

@DaanHoogland
Copy link
Contributor

@blueorangutan test keepEnv

@DaanHoogland DaanHoogland self-assigned this Jan 20, 2025
@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-12131)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 45009 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10204-t12131-kvm-ol8.zip
Smoke tests completed. 133 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

Copy link
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

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

code lgtm

@DaanHoogland
Copy link
Contributor

monkey tested in a lab env, all good

@DaanHoogland DaanHoogland merged commit 70776b0 into apache:4.19 Jan 21, 2025
24 of 25 checks passed
DaanHoogland added a commit that referenced this pull request Jan 21, 2025
* 4.20:
  linstor: Fix ZFS snapshot backup (#10219)
  fix listing of VMs by network (#10204)
  Configure org.eclipse.jetty.server.Request.maxFormKeys from server.properties and increase the default value (#10214)
  api: fix access for listSystemVmUsageHistory (#10032)
  Fix NPE issues during host rolling maintenance, due to host tags and custom constrained/unconstrained service offering (#9844)
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.

[API] Incorrect listing of VMs with previous NICs on networks
4 participants