Skip to content

Commit 8a8934d

Browse files
author
Yongxue Hong
committed
qemu_utils: Prepare module for autils migration
- Fix docstring formatting by removing empty first lines - Add missing type documentation for qemu_path parameter - Convert % string formatting to f-strings for better readability - Improve module docstring to provide clearer functionality overview - Remove from .pylintrc_utils ignore list to enable pylint checking Signed-off-by: Yongxue Hong <yhong@redhat.com>
1 parent 933524f commit 8a8934d

2 files changed

Lines changed: 33 additions & 26 deletions

File tree

.pylintrc_utils

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension-pkg-whitelist=netifaces
7070
# TO BE REMOVED:
7171
# utils_scheduling.py (will be deleted from codebase)
7272
#
73-
ignore=CVS,accessors.py,address.py,aexpect.py,ah_ipv6.py,ah.py,all_ipv6.py,all.py,arch.py,arp.py,asset.py,audio.py,backup_xml.py,base_installer.py,base.py,block.py,block_volume.py,bootstrap.py,boottool.py,bridge.py,build_helper.py,capability_xml.py,cartesian_config.py,cb.py,ceph.py,channel.py,character.py,check_cpu_flag.py,checkpoint_xml.py,cmd_runner.py,compat.py,console.py,controller.py,core.py,cpu.py,curl.py,data_dir.py,dd.py,defaults.py,dir_pool.py,dir_volume.py,disk.py,domcapability_xml.py,drive.py,duplicate_pages.py,emulator.py,env_process.py,error_context.py,error_event.py,esp_ipv6.py,esp.py,filesystem.py,file_volume.py,filterref.py,funcatexit.py,gcov.py,gluster.py,graphical_console.py,graphics.py,guest_agent.py,hostdev.py,http_server.py,hub.py,icmp.py,icmpv6.py,idmap_xml.py,igmp.py,__init__.py,input.py,installer.py,interface.py,interrupted_thread.py,iommu.py,ip.py,ip_sniffing.py,ipv6.py,iscsi.py,kernelinstall.py,kernel_interface.py,kernel.py,key_event_form.py,ksm_overcommit_guest.py,lease.py,libguestfs.py,librarian.py,libvirt_bios.py,libvirt_ceph_utils.py,libvirt_cgroup.py,libvirt_config.py,libvirt_cpu.py,libvirtd_decorator.py,libvirt_device_utils.py,libvirt_disk.py,libvirt_domjobinfo.py,libvirt_embedded_qemu.py,libvirt_filesystem.py,libvirt_installer.py,libvirt_keywrap.py,libvirt_memory.py,libvirt_misc.py,libvirt_monitor.py,libvirt_nested.py,libvirt_network.py,libvirt_numa.py,libvirt_nwfilter.py,libvirt_pcicontr.py,libvirt.py,libvirt_remote.py,libvirt_secret.py,libvirt_service.py,libvirt_setup.py,libvirt_storage.py,libvirt_unprivileged.py,libvirt_usb.py,libvirt_version.py,libvirt_vfio.py,libvirt_virtio.py,libvirt_vm.py,libvirt_vmxml.py,logger.py,logging_manager.py,lvm.py,lvsb_base.py,lvsb.py,lvsbs.py,lv_utils.py,mac.py,macvtap.py,memballoon.py,memory.py,messenger.py,migration.py,migration_template.py,mock.py,multicast_guest.py,nbd.py,netperf_agent.py,net_volume.py,networking.py,network_xml.py,nfs_pool.py,nfs.py,nfs_volume.py,nodedev_xml.py,node_properties.py,node.py,nvme.py,nvram.py,nwfilter_binding.py,nwfilter_xml.py,openvswitch.py,os_posix.py,ovirt.py,ovs.py,ovs_utils.py,panic.py,parallel.py,pci_utils.py,pmsocat36.py,png_utils.py,pool.py,pool_selector.py,pool_xml.py,port_resource.py,postprocess_iozone.py,ppc.py,ppm_utils.py,propcan.py,proxy.py,pstore.py,qcontainer.py,qdevice_format.py,qdevices.py,qemu_capabilities.py,qemu_installer.py,qemu_io.py,qemu_migration.py,qemu_monitor.py,qemu_qtree.py,qemu_storage.py,qemu_utils.py,qemu_virtio_port.py,qemu_vm.py,rarp.py,redirdev.py,redirfilter.py,remote_build.py,remote_interface.py,remote_master.py,remote.py,remote_runner.py,requirement_checks.py,resource_manager.py,resource.py,RFBDes.py,rng_egd.py,rng.py,scan_autotest_results.py,scheduler.py,sctp_ipv6.py,sctp.py,seclabel.py,secret_xml.py,selector.py,serial_host_send_receive.py,serial.py,service.py,set_win_promisc.py,sev.py,shmem.py,smartcard.py,snapshot_xml.py,sound.py,ssh_key.py,standalone_test.py,step_editor.py,storage.py,storage_ssh.py,stp.py,syslog_server.py,system.py,sys_time.py,tap_network.py,tap_port.py,tap.py,tcp_ipv6.py,tcp.py,telnet.py,test_controller_xml.py,test_interface_xml.py,test_memory_xml.py,test_network_xml.py,test_utils_kernel_module.py,test_utils_misc.py,test_utils_test__init__.py,test_utils_zchannels.py,test_utils_zcrypt.py,test_vm_xml.py,tool.py,tpm.py,udp_ipv6.py,udplite_ipv6.py,udplite.py,udp.py,unattended_install.py,utils_backup.py,utils_cgroup.py,utils_config.py,utils_conn.py,utils_cpi.py,utils_disk.py,utils_env.py,utils_gdb.py,utils_hotplug.py,utils_ids.py,utils_iptables.py,utils_kernel_module.py,utils_koji.py,utils_libguestfs.py,utils_libvirtd.py,utils_linux_modules.py,utils_logfile.py,utils_memory.py,utils_misc.py,utils_nbd.py,utils_netperf.py,utils_net.py,utils_npiv.py,utils_numeric.py,utils_package.py,utils_params.py,utils.py,utils_pyvmomi.py,utils_qemu.py,utils_sasl.py,utils_scheduling.py,utils_selinux.py,utils_spice.py,utils_split_daemons.py,utils_sriov.py,utils_stress.py,utils_switchdev.py,utils_sys.py,utils_time.py,utils_v2v.py,utils_vdpa.py,utils_version.py,utils_virtio_port.py,utils_vsock.py,utils_zchannels.py,utils_zcrypt.py,vdpa_blk.py,verify.py,versionable_class.py,version.py,vhost_user_blk.py,video_maker.py,video.py,virsh.py,virt_admin.py,VirtIoChannel_guest_send_receive.py,virtio_console_guest.py,virtio_win.py,virt_vm.py,vlan.py,vms.py,vm_xml.py,volume.py,vol_xml.py,vsock.py,vt_console.py,vt_iothread.py,wait_for_quit.py,watchdog.py,windows_support.py,wmic.py,_wrappers.py,xcepts.py,xml_utils.py,yumrepo.py
73+
ignore=CVS,accessors.py,address.py,aexpect.py,ah_ipv6.py,ah.py,all_ipv6.py,all.py,arch.py,arp.py,asset.py,audio.py,backup_xml.py,base_installer.py,base.py,block.py,block_volume.py,bootstrap.py,boottool.py,bridge.py,build_helper.py,capability_xml.py,cartesian_config.py,cb.py,ceph.py,channel.py,character.py,check_cpu_flag.py,checkpoint_xml.py,cmd_runner.py,compat.py,console.py,controller.py,core.py,cpu.py,curl.py,data_dir.py,dd.py,defaults.py,dir_pool.py,dir_volume.py,disk.py,domcapability_xml.py,drive.py,duplicate_pages.py,emulator.py,env_process.py,error_context.py,error_event.py,esp_ipv6.py,esp.py,filesystem.py,file_volume.py,filterref.py,funcatexit.py,gcov.py,gluster.py,graphical_console.py,graphics.py,guest_agent.py,hostdev.py,http_server.py,hub.py,icmp.py,icmpv6.py,idmap_xml.py,igmp.py,__init__.py,input.py,installer.py,interface.py,interrupted_thread.py,iommu.py,ip.py,ip_sniffing.py,ipv6.py,iscsi.py,kernelinstall.py,kernel_interface.py,kernel.py,key_event_form.py,ksm_overcommit_guest.py,lease.py,libguestfs.py,librarian.py,libvirt_bios.py,libvirt_ceph_utils.py,libvirt_cgroup.py,libvirt_config.py,libvirt_cpu.py,libvirtd_decorator.py,libvirt_device_utils.py,libvirt_disk.py,libvirt_domjobinfo.py,libvirt_embedded_qemu.py,libvirt_filesystem.py,libvirt_installer.py,libvirt_keywrap.py,libvirt_memory.py,libvirt_misc.py,libvirt_monitor.py,libvirt_nested.py,libvirt_network.py,libvirt_numa.py,libvirt_nwfilter.py,libvirt_pcicontr.py,libvirt.py,libvirt_remote.py,libvirt_secret.py,libvirt_service.py,libvirt_setup.py,libvirt_storage.py,libvirt_unprivileged.py,libvirt_usb.py,libvirt_version.py,libvirt_vfio.py,libvirt_virtio.py,libvirt_vm.py,libvirt_vmxml.py,logger.py,logging_manager.py,lvm.py,lvsb_base.py,lvsb.py,lvsbs.py,lv_utils.py,mac.py,macvtap.py,memballoon.py,memory.py,messenger.py,migration.py,migration_template.py,mock.py,multicast_guest.py,nbd.py,netperf_agent.py,net_volume.py,networking.py,network_xml.py,nfs_pool.py,nfs.py,nfs_volume.py,nodedev_xml.py,node_properties.py,node.py,nvme.py,nvram.py,nwfilter_binding.py,nwfilter_xml.py,openvswitch.py,os_posix.py,ovirt.py,ovs.py,ovs_utils.py,panic.py,parallel.py,pci_utils.py,pmsocat36.py,png_utils.py,pool.py,pool_selector.py,pool_xml.py,port_resource.py,postprocess_iozone.py,ppc.py,ppm_utils.py,propcan.py,proxy.py,pstore.py,qcontainer.py,qdevice_format.py,qdevices.py,qemu_capabilities.py,qemu_installer.py,qemu_io.py,qemu_migration.py,qemu_monitor.py,qemu_qtree.py,qemu_storage.py,qemu_virtio_port.py,qemu_vm.py,rarp.py,redirdev.py,redirfilter.py,remote_build.py,remote_interface.py,remote_master.py,remote.py,remote_runner.py,requirement_checks.py,resource_manager.py,resource.py,RFBDes.py,rng_egd.py,rng.py,scan_autotest_results.py,scheduler.py,sctp_ipv6.py,sctp.py,seclabel.py,secret_xml.py,selector.py,serial_host_send_receive.py,serial.py,service.py,set_win_promisc.py,sev.py,shmem.py,smartcard.py,snapshot_xml.py,sound.py,ssh_key.py,standalone_test.py,step_editor.py,storage.py,storage_ssh.py,stp.py,syslog_server.py,system.py,sys_time.py,tap_network.py,tap_port.py,tap.py,tcp_ipv6.py,tcp.py,telnet.py,test_controller_xml.py,test_interface_xml.py,test_memory_xml.py,test_network_xml.py,test_utils_kernel_module.py,test_utils_misc.py,test_utils_test__init__.py,test_utils_zchannels.py,test_utils_zcrypt.py,test_vm_xml.py,tool.py,tpm.py,udp_ipv6.py,udplite_ipv6.py,udplite.py,udp.py,unattended_install.py,utils_backup.py,utils_cgroup.py,utils_config.py,utils_conn.py,utils_cpi.py,utils_disk.py,utils_env.py,utils_gdb.py,utils_hotplug.py,utils_ids.py,utils_iptables.py,utils_kernel_module.py,utils_koji.py,utils_libguestfs.py,utils_libvirtd.py,utils_linux_modules.py,utils_logfile.py,utils_memory.py,utils_misc.py,utils_nbd.py,utils_netperf.py,utils_net.py,utils_npiv.py,utils_numeric.py,utils_package.py,utils_params.py,utils.py,utils_pyvmomi.py,utils_qemu.py,utils_sasl.py,utils_scheduling.py,utils_selinux.py,utils_spice.py,utils_split_daemons.py,utils_sriov.py,utils_stress.py,utils_switchdev.py,utils_sys.py,utils_time.py,utils_v2v.py,utils_vdpa.py,utils_version.py,utils_virtio_port.py,utils_vsock.py,utils_zchannels.py,utils_zcrypt.py,vdpa_blk.py,verify.py,versionable_class.py,version.py,vhost_user_blk.py,video_maker.py,video.py,virsh.py,virt_admin.py,VirtIoChannel_guest_send_receive.py,virtio_console_guest.py,virtio_win.py,virt_vm.py,vlan.py,vms.py,vm_xml.py,volume.py,vol_xml.py,vsock.py,vt_console.py,vt_iothread.py,wait_for_quit.py,watchdog.py,windows_support.py,wmic.py,_wrappers.py,xcepts.py,xml_utils.py,yumrepo.py
7474

7575
# regex matches against base names, not paths.
7676
ignore-patterns=.git

virttest/vt_utils/qemu_utils.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,63 @@
1-
#
2-
# Library for qemu option related helper functions
3-
#
4-
# This program is free software; you can redistribute it and/or modify
5-
# it under the terms of the GNU General Public License as published by
6-
# the Free Software Foundation; specifically version 2 of the License.
7-
#
8-
# This program is distributed in the hope that it will be useful,
9-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11-
#
12-
# See LICENSE for more details.
13-
#
14-
# Copyright: Red Hat (c) 2024 and Avocado contributors
15-
# Author: Houqi Zuo <hzuo@redhat.com>
1+
"""QEMU Utility Functions for Avocado-VT Testing Framework.
2+
3+
This module provides utility functions for interacting with QEMU/KVM binaries
4+
and extracting configuration information. It includes functions for checking
5+
command-line option support and retrieving available machine types.
6+
7+
Functions:
8+
has_option: Check if a specific command-line option is supported by QEMU.
9+
get_support_machine_type: Retrieve all machine types supported by QEMU.
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation; specifically version 2 of the License.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18+
19+
See LICENSE for more details.
20+
21+
Copyright: Red Hat (c) 2024 and Avocado contributors
22+
Author: Houqi Zuo <hzuo@redhat.com>
23+
"""
24+
1625
import re
1726

1827
from avocado.utils import process
1928

2029

2130
def has_option(option, qemu_path="/usr/bin/qemu-kvm"):
22-
"""
23-
Helper function for command line option wrappers.
31+
"""Helper function for command line option wrappers.
2432
2533
:param option: Option need check.
26-
:type option: String
34+
:type option: str
2735
:param qemu_path: Path for qemu-kvm.
28-
:type option: String
36+
:type qemu_path: str
2937
3038
:return: Return true if the qemu has the given option. Otherwise, return
3139
false.
3240
:rtype: Boolean
3341
"""
3442
hlp = process.run(
35-
"%s -help" % qemu_path, shell=True, ignore_status=True, verbose=False
43+
f"{qemu_path} -help", shell=True, ignore_status=True, verbose=False
3644
).stdout_text
37-
return bool(re.search(r"^-%s(\s|$)" % option, hlp, re.MULTILINE))
45+
return bool(re.search(rf"^-{option}(\s|$)", hlp, re.MULTILINE))
3846

3947

4048
def get_support_machine_type(qemu_binary="/usr/libexec/qemu-kvm", remove_alias=False):
41-
"""
42-
Get each machine types supported by host.
49+
"""Get each machine types supported by host.
4350
4451
:param qemu_binary: qemu-kvm binary file path.
45-
:type qemu_binary: String
52+
:type qemu_binary: str
4653
:param remove_alias: If it's True, remove alias or not. Otherwise, do NOT
4754
remove alias.
4855
:type remove_alias: Boolean
4956
5057
:return: A tuple(machine_name, machine_type, machine_alias).
5158
:rtype: Tuple[List, List, List]
5259
"""
53-
o = process.run("%s -M ?" % qemu_binary).stdout_text.splitlines()
60+
o = process.run(f"{qemu_binary} -M ?").stdout_text.splitlines()
5461
machine_name = []
5562
machine_type = []
5663
machine_alias = []

0 commit comments

Comments
 (0)