Skip to content

kvm: get ip address of Windows vms via virsh domifaddr#12651

Draft
weizhouapache wants to merge 1 commit intoapache:4.22from
weizhouapache:4.22-fix-ip-addr-of-windows-vm
Draft

kvm: get ip address of Windows vms via virsh domifaddr#12651
weizhouapache wants to merge 1 commit intoapache:4.22from
weizhouapache:4.22-fix-ip-addr-of-windows-vm

Conversation

@weizhouapache
Copy link
Member

Description

This PR fixes #12649

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?

@weizhouapache weizhouapache added this to the 4.22.1 milestone Feb 16, 2026
@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 17.62%. Comparing base (7324ef4) to head (27f25a6).

Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12651      +/-   ##
============================================
- Coverage     17.62%   17.62%   -0.01%     
  Complexity    15668    15668              
============================================
  Files          5917     5917              
  Lines        531255   531255              
  Branches      64951    64951              
============================================
- Hits          93639    93637       -2     
- Misses       427077   427078       +1     
- Partials      10539    10540       +1     
Flag Coverage Δ
uitests 3.70% <ø> (ø)
unittests 18.69% <100.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.

🚀 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.

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

This PR fixes issue #12649 where KVM IP autodiscovery failed for Windows VMs due to multi-word interface names like "Ethernet Instance 0". The fix changes the parsing logic in getIpAddresses to parse virsh domifaddr output from the end of each line rather than from fixed positions, making it compatible with both single-word Linux interface names and multi-word Windows interface names.

Changes:

  • Modified parsing logic to use relative positions from end of line (parts.length - 3, parts.length - 2, parts.length - 1) instead of fixed positions
  • Added test data constant VIRSH_DOMIF_OUTPUT_WINDOWS with realistic Windows virsh output
  • Updated testExecuteWithWindowsVm to test parsing of Windows interface names with spaces

Reviewed changes

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

File Description
LibvirtGetVmIpAddressCommandWrapper.java Changed parsing to use relative positions from end of line to handle multi-word interface names
LibvirtGetVmIpAddressCommandWrapperTest.java Added Windows-specific test data and updated/added tests for Windows VM IP discovery

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

private static String VIRSH_DOMIF_OUTPUT_WINDOWS = " Name MAC address Protocol Address\n" + //
"-------------------------------------------------------------------------------\n" + //
" Ethernet Instance 0 02:0c:02:f9:00:80 ipv4 192.168.0.10/24\n" + //
" Loopback Pseudo-Interface 1 ipv6 ::1/128\n" + //
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The test data for line 58 appears to be missing the MAC address column. Based on the virsh domifaddr output format, each line should have 4 columns: Name, MAC address, Protocol, and Address. Line 58 "Loopback Pseudo-Interface 1" only has 3 columns (Name, Protocol, Address), which will cause the parsing logic to incorrectly treat "1" (part of the interface name) as the MAC address when using parts[parts.length - 3]. This should either include a MAC address or use "-" as a placeholder to maintain the expected column structure, similar to line 59.

Suggested change
" Loopback Pseudo-Interface 1 ipv6 ::1/128\n" + //
" Loopback Pseudo-Interface 1 - ipv6 ::1/128\n" + //

Copilot uses AI. Check for mistakes.


@Test
public void testExecuteWithWindowsVm2() {
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The test name "testExecuteWithWindowsVm2" is not descriptive. Consider renaming it to something more meaningful like "testExecuteWithWindowsVmFallbackToRegistry" to clarify that this test verifies the fallback behavior when virsh domifaddr returns empty output and the system falls back to reading from the Windows registry.

Suggested change
public void testExecuteWithWindowsVm2() {
public void testExecuteWithWindowsVmFallbackToRegistry() {

Copilot uses AI. Check for mistakes.
@weizhouapache
Copy link
Member Author

for anyone who use 4.22.0.0, please rename the .jar.zip file to .jar, and replace /usr/share/cloudstack-agent/lib/cloud-plugin-hypervisor-kvm-4.22.0.0.jar with it on kvm hosts.

cloud-plugin-hypervisor-kvm-4.22.0.0.jar.zip

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.

KVM IP autodiscovery not working with Windows interface names

1 participant