avocado-vt icon indicating copy to clipboard operation
avocado-vt copied to clipboard

Replace WMIC with powershell cmd

Open leidwang opened this issue 1 year ago • 13 comments

From Win11-24H2, WMIC is an optional feature for Windows, And it will be fully removed in the future.So replace the related cmd

ID: 3268

Summary by CodeRabbit

  • Bug Fixes

    • Replaced deprecated Windows wmic commands with modern PowerShell alternatives for disk, memory, network, and file operations, improving compatibility and reliability.
    • Updated logic for retrieving and parsing Windows system information, including disk size, free disk space, memory, and network attributes.
    • Improved file path detection and drive letter matching on Windows guests.
    • Enhanced handling of wildcards when identifying virtio-win drive letters.
  • Documentation

    • Updated docstrings and comments to reflect the use of PowerShell commands instead of wmic.
  • Chores

    • Added "powershell" and "CimInstance" to the list of ignored spell-check terms.

leidwang avatar Nov 29 '24 03:11 leidwang

Hi @xiagao @heywji Would you please help test this MR with our acceptance test, thanks.

leidwang avatar Jan 08 '25 02:01 leidwang

Test 271 acceptance with win2022,win11,win1032 and win2016 guests, this patch worked.

heywji avatar Jan 15 '25 06:01 heywji

Hi @XueqiangWei @nanliu-r @fbq815 Would you please help test this MR, it is mainly for wmic repalcement.Thanks.

leidwang avatar Jan 15 '25 06:01 leidwang

Acceptance test looks good. LGTM.

xiagao avatar Jan 16 '25 01:01 xiagao

balloon_hotplug test cases now passed in Win2025

 (1/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.q35: STARTED
 (1/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.q35: PASS (50028.55 s)
 (2/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_reboot.q35: STARTED
 (2/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_reboot.q35: PASS (939.88 s)
 (3/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_system_reset.q35: STARTED
 (3/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_system_reset.q35: PASS (871.67 s)
 (4/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_unplug.q35: STARTED
 (4/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_unplug.q35: PASS (497.14 s)
 (5/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_plug.q35: STARTED
 (5/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_plug.q35: PASS (473.43 s)
 (6/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_hotplug.q35: STARTED
 (6/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_hotplug.q35: PASS (601.20 s)
 (7/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_unplug.q35: STARTED
 (7/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_unplug.q35: PASS (694.86 s)
RESULTS    : PASS 7 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0

mcasquer avatar Jan 16 '25 06:01 mcasquer

Hi @yanan-fu @YongxueHong Would you please help review this MR?Thanks.

leidwang avatar Jan 22 '25 06:01 leidwang

Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs :confused:

mcasquer avatar Apr 25 '25 06:04 mcasquer

Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs 😕

Hi @mcasquer I will update this MR recently, sorry for the delay.Currently, if you hit the issue that wmic not installed, you can try to run unattended_install test case again, it should be helpful.

Just want to explain more about why we will hit this issue. Win11-24H2 and Win2025 remove wmic, and does not provide installer for wmic, so we have to install it from MSFT, which then requires downloading something from the MSFT server,, so the wmic installation sometimes fails.

leidwang avatar Apr 25 '25 06:04 leidwang

Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs 😕

Hi @mcasquer I will update this MR recently, sorry for the delay.Currently, if you hit the issue that wmic not installed, you can try to run unattended_install test case again, it should be helpful.

Just want to explain more about why we will hit this issue. Win11-24H2 and Win2025 remove wmic, and does not provide installer for wmic, so we have to install it from MSFT, which then requires downloading something from the MSFT server,, so the wmic installation sometimes fails.

@leidwang ok, I get the idea, but if I trigger an automated test loop I cannot run the unattended_install twice, which significantly affects automation purpose...

mcasquer avatar Apr 25 '25 07:04 mcasquer

Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs 😕

Hi @mcasquer I will update this MR recently, sorry for the delay.Currently, if you hit the issue that wmic not installed, you can try to run unattended_install test case again, it should be helpful. Just want to explain more about why we will hit this issue. Win11-24H2 and Win2025 remove wmic, and does not provide installer for wmic, so we have to install it from MSFT, which then requires downloading something from the MSFT server,, so the wmic installation sometimes fails.

@leidwang ok, I get the idea, but if I trigger an automated test loop I cannot run the unattended_install twice, which significantly affects automation purpose...

Yes, we have to replace all wmic related command in our framework and test cases, then this issue can be fully fixed.

leidwang avatar Apr 25 '25 07:04 leidwang

Tested with vTPM test cases. LGTM

qcheng-redhat avatar Apr 29 '25 03:04 qcheng-redhat

📝 Walkthrough

Walkthrough

This change set migrates all Windows system information and management commands in the codebase from the deprecated wmic utility to modern PowerShell commands using Get-CimInstance and related cmdlets. Updates span disk, memory, network, and file system utilities, with corresponding adjustments to output parsing and documentation. No public API signatures are changed.

Changes

Cohort / File(s) Change Summary
Spell Ignore List Update
spell.ignore
Added "powershell" and "CimInstance" to the spell checker ignore list.
Disk Utilities: PowerShell Migration
virttest/utils_disk.py
Replaced Windows disk size retrieval command from wmic to PowerShell Get-CimInstance in get_disk_size_windows.
Misc Utilities: PowerShell Migration
virttest/utils_misc.py
Updated Windows commands in get_free_disk, get_free_mem, and get_win_disk_vol from wmic to PowerShell equivalents. Adjusted docstrings to reflect PowerShell usage and parsing logic for condition strings.
Network Utilities: PowerShell Migration & Helper Addition
virttest/utils_net.py
Converted all Windows network interface and IP configuration commands from wmic to PowerShell. Added subnet_mask_to_prefix_length helper. Updated output parsing and documentation for affected functions.
Netperf Utility: PowerShell Migration
virttest/utils_netperf.py
Changed process check command in Netperf.is_target_running from wmic to PowerShell Get-CimInstance.
Windows File Path Utility: PowerShell Migration
virttest/utils_test/__init__.py
Updated get_windows_file_abs_path to use a PowerShell recursive file search instead of wmic datafile. Adjusted regex parsing for new output format.
QEMU Test Utilities: PowerShell Migration
virttest/utils_test/qemu/__init__.py
Modified Windows memory size retrieval in MemoryBaseTest.get_guest_total_mem from wmic to PowerShell Get-CimInstance.
Windows Drive Utilities: PowerShell Migration & Parsing Refactor
virttest/utils_windows/drive.py
Replaced all wmic usage with PowerShell Get-CimInstance queries. Refactored property and condition parsing logic for disk and drive queries. Removed dependencies on wmic and utils_misc.
Windows System Info Utility: PowerShell Migration & Parsing Refactor
virttest/utils_windows/system.py
Replaced WMIC-based OS info retrieval with PowerShell Get-CimInstance in _osinfo. Refactored output parsing and removed wmic import.
Virtio Win Drive Letter Utility: Wildcard Change
virttest/utils_windows/virtio_win.py
Changed drive letter pattern from "virtio-win%" to "virtio-win*" in drive_letter_iso to align with PowerShell wildcard usage.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Complexity: The migration from wmic to PowerShell affects core logic in multiple modules, requires careful review of command syntax, output parsing, and error handling, and introduces new helper functions and docstring updates.
  • Scope: Changes span disk, memory, network, file, and system utilities, with several refactored parsing routines and removal of legacy dependencies.
  • Estimated review time: Approximately 45 minutes for a thorough review, focusing on correctness of command replacements, output parsing, and backward compatibility.

[!NOTE]

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jul 31 '25 09:07 coderabbitai[bot]

@leidwang I've check the code, seems this is windows only, please double confirm that, if it's true you could ignore me with this patch

fbq815 avatar Oct 17 '25 10:10 fbq815