-
Notifications
You must be signed in to change notification settings - Fork 243
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
Replace WMIC with powershell cmd #4034
base: master
Are you sure you want to change the base?
Conversation
97073f0
to
194ab37
Compare
1c9d9ea
to
7c4813a
Compare
ae6028c
to
9f86791
Compare
From Win11-24H2, WMIC is an optional feature for Windows, And it will be fully removed in the future.So replace the related cmd Signed-off-by: Leidong Wang <[email protected]>
9f86791
to
d1bcda5
Compare
Test 271 acceptance with win2022,win11,win1032 and win2016 guests, this patch worked. |
Hi @XueqiangWei @nanliu-r @fbq815 Would you please help test this MR, it is mainly for wmic repalcement.Thanks. |
Acceptance test looks good. |
balloon_hotplug test cases now passed in Win2025
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @yanan-fu @YongxueHong Would you please help review this MR?Thanks. |
return out if out else [] | ||
c_name, c_value = cond.split("=") | ||
cmd = ( | ||
'powershell -command "Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object {$_.%s -like %s}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The disk needs to be under single quotes, same you've done in utils_netperf.py and replace the existing ones by double quotes
'powershell -command "Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object {$_.%s -like %s}' | |
"powershell -command \"Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object {$_.%s -like '%s'}" |
return mapping | ||
return {} | ||
cmd = ( | ||
'powershell -command "Get-CimInstance -ClassName Win32_Diskdrive | Where-Object {$_.SerialNumber -eq %s}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
'powershell -command "Get-CimInstance -ClassName Win32_Diskdrive | Where-Object {$_.SerialNumber -eq %s}' | |
"powershell -command \"Get-CimInstance -ClassName Win32_Diskdrive | Where-Object {$_.SerialNumber -eq '%s'}" |
results.append(vals[0]) | ||
else: | ||
results.append(dict(zip(keys, vals))) | ||
return results if results else [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leidwang
Another comment here, this implementation seems to no longer return a map, so this will probably break all the calls to this function.
octets = subnet_mask.split(".") | ||
|
||
prefix_length = 0 | ||
for octet in octets: | ||
prefix_length += bin(int(octet)).count("1") | ||
|
||
return prefix_length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
octets = subnet_mask.split(".") | |
prefix_length = 0 | |
for octet in octets: | |
prefix_length += bin(int(octet)).count("1") | |
return prefix_length | |
return sum(bin(int(octet)).count("1") for octet in subnet_mask.split(".")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that the netmask in set_guest_ip_addr
can be CIDR AND dot-decimal notation, only when users give a dot-decimal notation, we have to convert it to a bitmask.
However, the new function is a duplicate of convert_netmask
in utils_net
module, and set_guest_ip_addr
also used it.
avocado-vt/virttest/utils_net.py
Lines 1641 to 1647 in 731ecab
nic_ifname = get_linux_ifname(session, mac) | |
if session.cmd_status("which ip") != 0: | |
info_cmd = "ifconfig -a; ethtool -S %s" % nic_ifname | |
cmd = "ifconfig %s %s netmask %s" % (nic_ifname, ip_addr, netmask) | |
else: | |
if "." in netmask: | |
netmask = convert_netmask(netmask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, the current convert_netmask
can only handle dot-decimal notation, as we already import ipaddress
, an enhancement here is to use it to handle all types of netmask.
>>> import ipaddress
>>> ip_addr = "192.168.1.1"
>>> netmask = "24" # or "255.255.255.0"
>>> ipaddr = ipaddress.IPv4Network(f"{ip_addr}/{netmask}", strict=False)
>>> ipaddr.netmask
IPv4Address('255.255.255.0')
>>> ipaddr.prefixlen
24
And then you can use it for linux/windows
@@ -3941,19 +3968,22 @@ def update_mac_ip_address(vm, timeout=240): | |||
|
|||
|
|||
def get_windows_nic_attribute( | |||
session, key, value, target, timeout=240, global_switch="nic" | |||
session, key, value, target, timeout=240, global_switch="NetworkAdapter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @xiagao
Could you help to review if it will affect the test case: https://github.com/autotest/tp-qemu/blob/6f0573097c77bb5d43b1c52574e12f5735714995/qemu/tests/win_virtio_driver_update_by_installer.py#L108-L109
Thanks.
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