virttest.utils_test package¶
Submodules¶
virttest.utils_test.libguestfs module¶
-
class
virttest.utils_test.libguestfs.
GuestfishTools
(params)[source]¶ Bases:
virttest.utils_libguestfs.GuestfishPersistent
Useful Tools for Guestfish class.
-
create_msdos_part
(device, start='1', end='-1')[source]¶ Create a msdos partition in given device. Default partition section is whole disk(1~-1). And return its part name if part add succeed.
-
create_whole_disk_msdos_part
(device)[source]¶ Create only one msdos partition in given device. And return its part name if part add succeed.
-
params
¶
-
-
exception
virttest.utils_test.libguestfs.
VTError
[source]¶ Bases:
exceptions.Exception
-
class
virttest.utils_test.libguestfs.
VirtTools
(vm, params)[source]¶ Bases:
object
Useful functions for virt-commands.
Some virt-tools need an input disk and output disk. Main for virt-clone, virt-sparsify, virt-resize.
-
clone_vm_filesystem
(newname=None)[source]¶ Clone a new vm with only its filesystem disk.
- :param newname:if newname is None,
- create a new name with clone added.
-
define_vm_with_newdisk
()[source]¶ Define the new vm with old vm’s configuration
Changes: 1.replace name 2.delete uuid 3.replace disk
-
expand_vm_filesystem
(resize_part_num=2, resized_size='+1G', new_disk=None)[source]¶ Expand vm’s filesystem with virt-resize.
-
format_disk
(disk_path=None, filesystem=None, partition=None, lvm=None)[source]¶ Parameters: disk_path – None for additional disk by update_vm_disk() only
-
-
virttest.utils_test.libguestfs.
attach_additional_disk
(vm, disksize, targetdev)[source]¶ Create a disk with disksize, then attach it to given vm.
Parameters: - vm – Libvirt VM object.
- disksize – size of attached disk
- targetdev – target of disk device
-
virttest.utils_test.libguestfs.
cleanup_vm
(vm_name=None, disk=None)[source]¶ Cleanup the vm with its disk deleted.
-
virttest.utils_test.libguestfs.
define_new_vm
(vm_name, new_name)[source]¶ Just define a new vm from given name
-
virttest.utils_test.libguestfs.
get_primary_disk
(vm)[source]¶ Get primary disk source.
Parameters: vm – Libvirt VM object.
virttest.utils_test.libvirt module¶
High-level libvirt test utility functions.
This module is meant to reduce code size by performing common test procedures. Generally, code here should look like test code.
- More specifically:
- Functions in this module should raise exceptions if things go wrong
- Functions in this module typically use functions and classes from lower-level modules (e.g. utils_misc, qemu_vm, aexpect).
- Functions in this module should not be used by lower-level modules.
- Functions in this module should be used in the right context. For example, a function should not be used where it may display misleading or inaccurate info or debug messages.
copyright: | 2014 Red Hat Inc. |
---|
-
class
virttest.utils_test.libvirt.
LibvirtNetwork
(net_type, address=None, iface=None, net_name=None, persistent=False)[source]¶ Bases:
object
Class to create a temporary network for testing.
-
class
virttest.utils_test.libvirt.
MigrationTest
[source]¶ Bases:
object
Class for migration tests
-
do_migration
(vms, srcuri, desturi, migration_type, options=None, thread_timeout=60)[source]¶ Migrate vms.
Parameters: - vms – migrated vms.
- srcuri – local uri, used when migrate vm from remote to local
- descuri – remote uri, used when migrate vm from local to remote
- migration_type – do orderly for simultaneous migration
-
-
class
virttest.utils_test.libvirt.
PoolVolumeTest
(test, params)[source]¶ Bases:
object
Test class for storage pool or volume
-
cleanup_pool
(pool_name, pool_type, pool_target, emulated_image, **kwargs)[source]¶ Delete vols, destroy the created pool and restore the env
-
pre_pool
(pool_name, pool_type, pool_target, emulated_image, **kwargs)[source]¶ Prepare(define or create) the specific type pool
Parameters: - pool_name – created pool name
- pool_type – dir, disk, logical, fs, netfs or else
- pool_target – target of storage pool
- emulated_image – use an image file to simulate a scsi disk it could be used for disk, logical pool, etc
- kwargs – key words for specific pool
-
-
virttest.utils_test.libvirt.
alter_boot_order
(vm_name, pci_id, boot_order=0)[source]¶ Alter the startup sequence of VM to PCI-device firstly
OS boot element and per-device boot elements are mutually exclusive, It’s necessary that remove all OS boots before setting PCI-device order
Parameters: - vm_name – VM name
- pci_id – such as “0000:06:00.1”
- boot_order – order priority, such as 1, 2, ...
-
virttest.utils_test.libvirt.
attach_additional_device
(vm_name, targetdev, disk_path, params, config=True)[source]¶ Create a disk with disksize, then attach it to given vm.
Parameters: - vm_name – Libvirt VM name.
- disk_path – path of attached disk
- targetdev – target of disk device
- params – dict include necessary configurations of device
-
virttest.utils_test.libvirt.
attach_disks
(vm, path, vgname, params)[source]¶ Attach multiple disks.According parameter disk_type in params, it will create lvm or file type disks.
Parameters: - path – file type disk’s path
- vgname – lvm type disk’s volume group name
-
virttest.utils_test.libvirt.
check_actived_pool
(pool_name)[source]¶ Check if pool_name exist in active pool list
-
virttest.utils_test.libvirt.
check_blockjob
(vm_name, target, check_point='none', value='0')[source]¶ Run blookjob command to check block job progress, bandwidth, ect.
Parameters: - vm_name – Domain name
- target – Domian disk target dev
- check_point – Job progrss, bandwidth or none(no job)
- value – Value of progress, bandwidth or 0(no job)
Returns: Boolean value, true for pass, false for fail
-
virttest.utils_test.libvirt.
check_exit_status
(result, expect_error=False)[source]¶ Check the exit status of virsh commands.
Parameters: - result – Virsh command result object
- expect_error – Boolean value, expect command success or fail
-
virttest.utils_test.libvirt.
check_iface
(iface_name, checkpoint, extra='', **dargs)[source]¶ Check interface with specified checkpoint.
Parameters: - iface_name – Interface name
- checkpoint – Check if interface exists, and It’s MAC address, IP address and State, also connectivity by ping. valid checkpoint: [exists, mac, ip, ping, state]
- extra – Extra string for checking
Returns: Boolean value, true for pass, false for fail
-
virttest.utils_test.libvirt.
check_result
(result, expected_fails=[], skip_if=[], any_error=False)[source]¶ Check the result of a command and check command error message against expectation.
Parameters: - result – Command result instance.
- expected_fails – list of regex of expected stderr patterns. The check will pass if any of these patterns matches.
- skip_if – list of regex of expected patterns. The check will raise a TestNAError if any of these patterns matches.
- any_error – Whether expect on any error message. Setting to True will will override expected_fails
-
virttest.utils_test.libvirt.
clean_up_snapshots
(vm_name, snapshot_list=[])[source]¶ Do recovery after snapshot
Parameters: - vm_name – Name of domain
- snapshot_list – The list of snapshot name you want to remove
-
virttest.utils_test.libvirt.
connect_libvirtd
(uri, read_only='', virsh_cmd='list', auth_user=None, auth_pwd=None, vm_name='', status_error='no', extra='', log_level='LIBVIRT_DEBUG=3', su_user='', patterns_virsh_cmd='.*Id\\s*Name\\s*State\\s*.*')[source]¶ Connect libvirt daemon
-
virttest.utils_test.libvirt.
cpu_allowed_list_by_task
(pid, tid)[source]¶ Get the Cpus_allowed_list in status of task.
-
virttest.utils_test.libvirt.
cpus_parser
(cpulist)[source]¶ Parse a list of cpu list, its syntax is a comma separated list, with ‘-‘ for ranges and ‘^’ denotes exclusive. :param cpulist: a list of physical CPU numbers
-
virttest.utils_test.libvirt.
cpus_string_to_affinity_list
(cpus_string, num_cpus)[source]¶ Parse the cpus_string string to a affinity list.
e.g host_cpu_count = 4 0 –> [y,-,-,-] 0,1 –> [y,y,-,-] 0-2 –> [y,y,y,-] 0-2,^2 –> [y,y,-,-] r –> [y,y,y,y]
-
virttest.utils_test.libvirt.
create_channel_xml
(params, alias=False, address=False)[source]¶ Create a XML contains channel information.
Parameters: - params – the params for Channel slot
- alias – allow to add ‘alias’ slot
- address – allow to add ‘address’ slot
-
virttest.utils_test.libvirt.
create_hostdev_xml
(pci_id, boot_order=0)[source]¶ Create a hostdev configuration file.
Parameters: pci_id – such as “0000:03:04.0”
-
virttest.utils_test.libvirt.
create_local_disk
(disk_type, path=None, size='10', disk_format='raw', vgname=None, lvname=None)[source]¶
-
virttest.utils_test.libvirt.
create_net_xml
(net_name, params)[source]¶ Create a new network or update an existed network xml
-
virttest.utils_test.libvirt.
create_nwfilter_xml
(params)[source]¶ Create a new network filter or update an existed network filter xml
-
virttest.utils_test.libvirt.
create_scsi_disk
(scsi_option, scsi_size='2048')[source]¶ Get the scsi device created by scsi_debug kernel module
:param scsi_option. The scsi_debug kernel module options. :return: scsi device if it is created successfully.
-
virttest.utils_test.libvirt.
define_new_vm
(vm_name, new_name)[source]¶ Just define a new vm from given name
-
virttest.utils_test.libvirt.
define_pool
(pool_name, pool_type, pool_target, cleanup_flag, **kwargs)[source]¶ To define a given type pool(Support types: ‘dir’, ‘netfs’, logical’, iscsi’, ‘gluster’, ‘disk’ and ‘fs’).
Parameters: - pool_name – Name of the pool
- pool_type – Type of the pool
- pool_target – Target for underlying storage
- cleanup_flag – A list contains 3 booleans and 1 string stands for need_cleanup_nfs, need_cleanup_iscsi, need_cleanup_logical, selinux_bak and need_cleanup_gluster
- kwargs – key words for special pool define. eg, glusterfs pool source path and source name, etc
-
virttest.utils_test.libvirt.
delete_local_disk
(disk_type, path=None, vgname=None, lvname=None)[source]¶
-
virttest.utils_test.libvirt.
delete_scsi_disk
()[source]¶ Delete scsi device by removing scsi_debug kernel module.
-
virttest.utils_test.libvirt.
device_exists
(vm, target_dev)[source]¶ Check if given target device exists on vm.
-
virttest.utils_test.libvirt.
do_migration
(vm_name, uri, extra, auth_pwd, auth_user='root', options='--verbose', virsh_patterns='.*100\\s%.*', su_user='', timeout=30)[source]¶ Migrate VM to target host.
-
virttest.utils_test.libvirt.
exec_virsh_edit
(source, edit_cmd, connect_uri='qemu:///system')[source]¶ Execute edit command.
:param source : virsh edit’s option. :param edit_cmd: Edit command list to execute. :return: True if edit is successful, False if edit is failure.
-
virttest.utils_test.libvirt.
get_all_cells
()[source]¶ Use virsh freecell –all to get all cells on host
# virsh freecell --all 0: 124200 KiB 1: 1059868 KiB -------------------- Total: 1184068 KiB
That would return a dict like:
cell_dict = {"0":"124200 KiB", "1":"1059868 KiB", "Total":"1184068 KiB"}
Returns: cell_dict
-
virttest.utils_test.libvirt.
get_ifname_host
(vm_name, mac)[source]¶ Get the vm interface name on host
Returns: interface name, None if not exist
-
virttest.utils_test.libvirt.
get_interface_details
(vm_name)[source]¶ Get the interface details from virsh domiflist command output
Returns: list of all interfaces details
-
virttest.utils_test.libvirt.
hotplug_domain_vcpu
(domain, count, by_virsh=True, hotplug=True)[source]¶ Hot-plug/Hot-unplug vcpu for domian
Parameters: - domain – Domain name, id, uuid
- count – to setvcpus it’s the current vcpus number, but to qemu-monitor-command, we need to designate a specific CPU ID. The default will be got by (count - 1)
- by_virsh – True means hotplug/unplug by command setvcpus, otherwise, using qemu_monitor
- hotplug – True means hot-plug, False means hot-unplug
-
virttest.utils_test.libvirt.
mk_label
(disk, label='msdos', session=None)[source]¶ Set label for disk.
-
virttest.utils_test.libvirt.
mk_part
(disk, size='100M', session=None)[source]¶ Create a partition for disk
-
virttest.utils_test.libvirt.
mkfs
(partition, fs_type, options='', session=None)[source]¶ Make a file system on the partition
-
virttest.utils_test.libvirt.
new_disk_vol_name
(pool_name)[source]¶ According to BZ#1138523, the new volume name must be the next created partition(sdb1, etc.), so we need to inspect the original partitions of the disk then count the new partition number.
Parameters: pool_name – Disk pool name Returns: New volume name or none
-
virttest.utils_test.libvirt.
pci_label_from_address
(address_dict, radix=10)[source]¶ Generate a pci label from a dict of address.
Parameters: - address_dict – A dict contains domain, bus, slot and function.
- radix – The radix of your data in address_dict.
Example:
address_dict = {'domain': '0x0000', 'bus': '0x08', 'slot': '0x10', 'function': '0x0'} radix = 16 return = pci_0000_08_10_0
-
virttest.utils_test.libvirt.
remotely_control_libvirtd
(server_ip, server_user, server_pwd, action='restart', status_error='no')[source]¶ Remotely restart libvirt service
-
virttest.utils_test.libvirt.
set_controller_multifunction
(vm_name, controller_type='scsi')[source]¶ Set multifunction on for controller device and expand to all function.
-
virttest.utils_test.libvirt.
set_domain_state
(vm, vm_state)[source]¶ Set domain state.
Parameters: - vm – the vm object
- vm_state – the given vm state string “shut off”, “running” “paused”, “halt” or “pm_suspend”
-
virttest.utils_test.libvirt.
set_guest_agent
(vm)[source]¶ Set domain xml with guest agent channel and install guest agent rpm in domain.
Parameters: vm – the vm object
-
virttest.utils_test.libvirt.
set_vm_disk
(vm, params, tmp_dir=None, test=None)[source]¶ Replace vm first disk with given type in domain xml, including file type (local, nfs), network type(gluster, iscsi), block type(use connected iscsi block disk).
For all types, all following params are common and need be specified:
disk_device: default to ‘disk’ disk_type: ‘block’ or ‘network’ disk_target: default to ‘vda’ disk_target_bus: default to ‘virtio’ disk_format: default to ‘qcow2’ disk_src_protocol: ‘iscsi’, ‘gluster’ or ‘netfs’For ‘gluster’ network type, following params are gluster only and need be specified:
vol_name: string pool_name: default to ‘gluster-pool’ transport: ‘tcp’, ‘rdma’ or ‘’, default to ‘’For ‘iscsi’ network type, following params need be specified:
image_size: default to “10G”, 10G is raw size of jeos disk disk_src_host: default to “127.0.0.1” disk_src_port: default to “3260”For ‘netfs’ network type, following params need be specified:
mnt_path_name: the mount dir name, default to “nfs-mount” export_options: nfs mount options, default to “rw,no_root_squash,fsid=0”For ‘block’ type, using connected iscsi block disk, following params need be specified:
image_size: default to “10G”, 10G is raw size of jeos diskParameters: - vm – the vm object
- tmp_dir – string, dir path
- params – dict, dict include setup vm disk xml configurations
-
virttest.utils_test.libvirt.
setup_or_cleanup_gluster
(is_setup, vol_name, brick_path='', pool_name='', file_path='/etc/glusterfs/glusterd.vol')[source]¶ Set up or clean up glusterfs environment on localhost :param is_setup: Boolean value, true for setup, false for cleanup :param vol_name: gluster created volume name :param brick_path: Dir for create glusterfs :return: ip_addr or nothing
-
virttest.utils_test.libvirt.
setup_or_cleanup_iscsi
(is_setup, is_login=True, emulated_image='emulated-iscsi', image_size='1G', chap_user='', chap_passwd='', restart_tgtd='no', portal_ip='127.0.0.1')[source]¶ Set up(and login iscsi target) or clean up iscsi service on localhost.
Parameters: - is_setup – Boolean value, true for setup, false for cleanup
- is_login – Boolean value, true for login, false for not login
- emulated_image – name of iscsi device
- image_size – emulated image’s size
- chap_user – CHAP authentication username
- chap_passwd – CHAP authentication password
Returns: iscsi device name or iscsi target
-
virttest.utils_test.libvirt.
setup_or_cleanup_nfs
(is_setup, mount_dir='nfs-mount', is_mount=False, export_options='rw, no_root_squash', mount_options='rw', export_dir='nfs-export', restore_selinux='')[source]¶ Set SElinux to “permissive” and Set up nfs service on localhost. Or clean up nfs service on localhost and restore SElinux.
Note: SElinux status must be backed up and restored after use. Example:
# Setup NFS. res = setup_or_cleanup_nfs(is_setup=True) # Backup SELinux status. selinux_bak = res[“selinux_status_bak”]
# Do something. ...
# Cleanup NFS and restore NFS. res = setup_or_cleanup_nfs(is_setup=False, restore_selinux=selinux_bak)
Parameters: - is_setup – Boolean value, true for setup, false for cleanup
- mount_dir – NFS mount dir. This can be an absolute path on the host or a relative path origin from libvirt tmp dir. Default to “nfs-mount”.
- is_mount – Boolean value, Whether the target NFS should be mounted.
- export_options – Options for nfs dir. Default to “nfs-export”.
- mount_options – Options for mounting nfs dir. Default to “rw”.
- export_dir – NFS export dir. This can be an absolute path on the host or a relative path origin from libvirt tmp dir. Default to “nfs-export”.
Returns: A dict contains export and mount result parameters: export_dir: Absolute directory of exported local NFS file system. mount_dir: Absolute directory NFS file system mounted on. selinux_status_bak: SELinux status before set
-
virttest.utils_test.libvirt.
update_polkit_rule
(params, pattern, new_value)[source]¶ This function help to update the rule during testing.
Parameters: - params – Test run params
- pattern – Regex pattern for updating
- new_value – New value for updating
-
virttest.utils_test.libvirt.
update_vm_disk_source
(vm_name, disk_source_path, source_type='file')[source]¶ Update disk source path of the VM
Parameters: source_type – it may be ‘dev’ or ‘file’ type, which is default
virttest.utils_test.qemu module¶
High-level QEMU test utility functions.
This module is meant to reduce code size by performing common test procedures. Generally, code here should look like test code.
- More specifically:
- Functions in this module should raise exceptions if things go wrong
- Functions in this module typically use functions and classes from lower-level modules (e.g. utils_misc, qemu_vm, aexpect).
- Functions in this module should not be used by lower-level modules.
- Functions in this module should be used in the right context. For example, a function should not be used where it may display misleading or inaccurate info or debug messages.
copyright: | 2008-2013 Red Hat Inc. |
---|
-
class
virttest.utils_test.qemu.
GuestSuspend
(params, vm)[source]¶ Bases:
object
Suspend guest, supports both Linux and Windows.
-
SUSPEND_TYPE_DISK
= 'disk'¶
-
SUSPEND_TYPE_MEM
= 'mem'¶
-
action_after_suspend
(*args, **kwargs)¶
-
action_before_suspend
(*args, **kwargs)¶
-
action_during_suspend
(*args, **kwargs)¶
-
check_bg_program
(*args, **kwargs)¶ Make sure the background program is running as expected
-
kill_bg_program
(*args, **kwargs)¶
-
resume_guest_disk
(*args, **kwargs)¶
-
resume_guest_mem
(*args, **kwargs)¶
-
setup_bg_program
(*args, **kwargs)¶ Start up a program as a flag in guest.
-
start_suspend
(*args, **kwargs)¶
-
verify_guest_down
(*args, **kwargs)¶
-
verify_guest_up
(*args, **kwargs)¶
-
-
class
virttest.utils_test.qemu.
MigrationData
(params, srchost, dsthost, vms_name, params_append)[source]¶ Bases:
object
-
class
virttest.utils_test.qemu.
MultihostMigration
(test, params, env, preprocess_env=True)[source]¶ Bases:
object
Class that provides a framework for multi-host migration.
Migration can be run both synchronously and asynchronously. To specify what is going to happen during the multi-host migration, it is necessary to reimplement the method migration_scenario. It is possible to start multiple migrations in separate threads, since self.migrate is thread safe.
Only one test using multihost migration framework should be started on one machine otherwise it is necessary to solve the problem with listen server port.
Multihost migration starts SyncListenServer through which all messages are transferred, since the multiple hosts can be in different states.
Class SyncData is used to transfer data over network or synchronize the migration process. Synchronization sessions are recognized by session_id.
It is important to note that, in order to have multi-host migration, one needs shared guest image storage. The simplest case is when the guest images are on an NFS server.
Example:
class TestMultihostMigration(utils_misc.MultihostMigration): def __init__(self, test, params, env): super(testMultihostMigration, self).__init__(test, params, env) def migration_scenario(self): srchost = self.params.get("hosts")[0] dsthost = self.params.get("hosts")[1] def worker(mig_data): vm = env.get_vm("vm1") session = vm.wait_for_login(timeout=self.login_timeout) session.sendline("nohup dd if=/dev/zero of=/dev/null &") session.cmd("killall -0 dd") def check_worker(mig_data): vm = env.get_vm("vm1") session = vm.wait_for_login(timeout=self.login_timeout) session.cmd("killall -9 dd") # Almost synchronized migration, waiting to end it. # Work is started only on first VM. self.migrate_wait(["vm1", "vm2"], srchost, dsthost, worker, check_worker) # Migration started in different threads. # It allows to start multiple migrations simultaneously. mig1 = self.migrate(["vm1"], srchost, dsthost, worker, check_worker) mig2 = self.migrate(["vm2"], srchost, dsthost) mig2.join() mig1.join() mig = TestMultihostMigration(test, params, env) mig.run()
-
before_migration
(mig_data)[source]¶ Do something right before migration.
Parameters: mig_data – object with migration data.
-
check_vms_dst
(mig_data)[source]¶ Check vms after migrate.
Parameters: mig_data – object with migration data.
-
check_vms_src
(mig_data)[source]¶ Check vms after migrate.
Parameters: mig_data – object with migration data.
-
migrate
(vms_name, srchost, dsthost, start_work=None, check_work=None, params_append=None)[source]¶ Migrate machine from srchost to dsthost. It executes start_work on source machine before migration and executes check_work on dsthost after migration.
Migration execution progress:
source host | dest host -------------------------------------------------------- prepare guest on both sides of migration - start machine and check if machine works - synchronize transfer data needed for migration -------------------------------------------------------- start work on source guests | wait for migration -------------------------------------------------------- migrate guest to dest host. wait on finish migration synchronization -------------------------------------------------------- | check work on vms -------------------------------------------------------- wait for sync on finish migration
Parameters: - vms_name – List of vms.
- srchost – src host id.
- dsthost – dst host id.
- start_work – Function started before migration.
- check_work – Function started after migration.
- params_append – Append params to self.params only for migration.
-
migrate_vms_dest
(mig_data)[source]¶ Migrate vms destination. This function is started on dest host during migration.
Parameters: mig_Data – Data for migration.
-
migrate_vms_src
(mig_data)[source]¶ Migrate vms source.
Parameters: mig_Data – Data for migration. For change way how machine migrates is necessary re implement this method.
-
migrate_wait
(vms_name, srchost, dsthost, start_work=None, check_work=None, params_append=None)[source]¶ Migrate machine from srchost to dsthost and wait for finish. It executes start_work on source machine before migration and executes check_work on dsthost after migration.
Parameters: - vms_name – List of vms.
- srchost – src host id.
- dsthost – dst host id.
- start_work – Function which is started before migration.
- check_work – Function which is started after done of migration.
-
migration_scenario
()[source]¶ Multi Host migration_scenario is started from method run where the exceptions are checked. It is not necessary to take care of cleaning up after test crash or finish.
-
post_migration
(vm, cancel_delay, mig_offline, dsthost, vm_ports, not_wait_for_migration, fd, mig_data)[source]¶
-
-
class
virttest.utils_test.qemu.
MultihostMigrationExec
(test, params, env, preprocess_env=True)[source]¶ Bases:
virttest.utils_test.qemu.MultihostMigration
-
migrate_vms_src
(mig_data)[source]¶ Migrate vms source.
Parameters: mig_Data – Data for migration. For change way how machine migrates is necessary re implement this method.
-
-
class
virttest.utils_test.qemu.
MultihostMigrationFd
(test, params, env, preprocess_env=True)[source]¶
-
class
virttest.utils_test.qemu.
MultihostMigrationRdma
(test, params, env, preprocess_env=True)[source]¶
-
virttest.utils_test.qemu.
clear_win_driver_verifier
(session, vm, timeout=300)[source]¶ Clear the driver verifier in windows guest.
Parameters: - session – VM session.
- timeout – Timeout in seconds.
Returns: Session after reboot.
-
virttest.utils_test.qemu.
get_numa_status
(numa_node_info, qemu_pid, debug=True)[source]¶ Get the qemu process memory use status and the cpu list in each node.
Parameters: Returns: memory and cpu list in each node
Return type:
-
virttest.utils_test.qemu.
migrate
(vm, env=None, mig_timeout=3600, mig_protocol='tcp', mig_cancel=False, offline=False, stable_check=False, clean=False, save_path=None, dest_host='localhost', mig_port=None)[source]¶ Migrate a VM locally and re-register it in the environment.
Parameters: - vm – The VM to migrate.
- env – The environment dictionary. If omitted, the migrated VM will not be registered.
- mig_timeout – timeout value for migration.
- mig_protocol – migration protocol
- mig_cancel – Test migrate_cancel or not when protocol is tcp.
- dest_host – Destination host (defaults to ‘localhost’).
- mig_port – Port that will be used for migration.
Returns: The post-migration VM, in case of same host migration, True in case of multi-host migration.
Module contents¶
High-level virt test utility functions.
This module is meant to reduce code size by performing common test procedures. Generally, code here should look like test code.
- More specifically:
- Functions in this module should raise exceptions if things go wrong
- Functions in this module typically use functions and classes from lower-level modules (e.g. utils_misc, aexpect).
- Functions in this module should not be used by lower-level modules.
- Functions in this module should be used in the right context. For example, a function should not be used where it may display misleading or inaccurate info or debug messages.
copyright: | 2008-2013 Red Hat Inc. |
---|
-
class
virttest.utils_test.
BackgroundTest
(func, params, kwargs={})[source]¶ Bases:
object
This class would run a test in background through a dedicated thread.
-
class
virttest.utils_test.
HostStress
(params, stress_type)[source]¶ Bases:
object
Run Stress tool on host, such as stress, unixbench, iozone and etc.
-
load_stress_tool
(*args, **kwargs)¶ load stress tool on host.
-
unload_stress
(*args, **kwargs)¶ stop stress tool manually
-
-
class
virttest.utils_test.
RemoteDiskManager
(params)[source]¶ Bases:
object
Control images on remote host
-
create_image
(disk_type, path=None, size=10, vgname=None, lvname=None, sparse=True, timeout=60, img_frmt=None)[source]¶ Create an image for target path.
-
get_free_space
(disk_type, path='/', vgname=None)[source]¶ Get free space of remote host for path.
:return : the unit is ‘G’.
-
iscsi_login_setup
(host, target_name, is_login=True)[source]¶ Login or logout to a target on remote host.
-
-
exception
virttest.utils_test.
StressError
(msg)[source]¶ Bases:
exceptions.Exception
Stress test exception.
-
class
virttest.utils_test.
VMStress
(vm, stress_type)[source]¶ Bases:
object
Run Stress tool in vms, such as stress, unixbench, iozone and etc.
-
load_stress_tool
(*args, **kwargs)¶ load stress tool in guest
-
unload_stress
(*args, **kwargs)¶ stop stress tool manually
-
-
virttest.utils_test.
canonicalize_disk_address
(disk_address)[source]¶ Canonicalize disk address. Convert {decimal|octal|hexadecimal} to decimal pci:0x0000.0x00.0x0b.0x0 => pci:0.0.11.0 ide:00.00.00 => ide:0.0.0 scsi:00.00.0x11 => scsi:0.0.17
-
virttest.utils_test.
check_dest_vm_network
(vm, ip, remote_host, username, password)[source]¶ Ping migrated vms on remote host.
-
virttest.utils_test.
get_driver_hardware_id
(driver_path, mount_point='/tmp/mnt-virtio', storage_path='/tmp/prewhql.iso', re_hw_id='(PCI.{14, 50})', run_cmd=True)[source]¶ Get windows driver’s hardware id from inf files.
Parameters: - dirver – Configurable driver name.
- mount_point – Mount point for the driver storage
- storage_path – The path of the virtio driver storage
- re_hw_id – the pattern for getting hardware id from inf files
- run_cmd – Use hardware id in windows cmd command or not
Returns: Windows driver’s hardware id
-
virttest.utils_test.
get_loss_ratio
(output)[source]¶ Get the packet loss ratio from the output of ping.
Parameters: output – Ping output.
-
virttest.utils_test.
get_memory_info
(lvms)[source]¶ Get memory information from host and guests in format: Host: memfree = XXXM; Guests memsh = {XXX,XXX,...}
Params lvms: List of VM objects Returns: String with memory info report
-
virttest.utils_test.
get_readable_cdroms
(params, session)[source]¶ Get the cdrom list which contain media in guest.
Parameters: - params – Dictionary with the test parameters.
- session – A shell session on the VM provided.
-
virttest.utils_test.
get_time
(session, time_command, time_filter_re, time_format)[source]¶ Return the host time and guest time. If the guest time cannot be fetched a TestError exception is raised.
Note that the shell session should be ready to receive commands (i.e. should “display” a command prompt and should be done with all previous commands).
Parameters: - session – A shell session.
- time_command – Command to issue to get the current guest time.
- time_filter_re – Regex filter to apply on the output of time_command in order to get the current time.
- time_format – Format string to pass to time.strptime() with the result of the regex filter.
Returns: A tuple containing the host time and guest time.
-
virttest.utils_test.
get_windows_disk_drive
(session, filename, extension='exe', tmout=240)[source]¶ Get the windows disk drive number
-
virttest.utils_test.
get_windows_file_abs_path
(session, filename, extension='exe', tmout=240)[source]¶ return file abs path “drive+path” by “wmic datafile”
-
virttest.utils_test.
load_stress
(stress_type, vms, params)[source]¶ Load stress for tests.
Parameters: - stress_type – The stress type you need
- params – Useful parameters for stress
- vms – Used when it’s stress in vms
-
virttest.utils_test.
ping
(dest=None, count=None, interval=None, interface=None, packetsize=None, ttl=None, hint=None, adaptive=False, broadcast=False, flood=False, timeout=0, output_func=<function debug>, session=None)[source]¶ Wrapper of ping.
Parameters: - dest – Destination address.
- count – Count of icmp packet.
- interval – Interval of two icmp echo request.
- interface – Specified interface of the source address.
- packetsize – Packet size of icmp.
- ttl – IP time to live.
- hint – Path mtu discovery hint.
- adaptive – Adaptive ping flag.
- broadcast – Broadcast ping flag.
- flood – Flood ping flag.
- timeout – Timeout for the ping command.
- output_func – Function used to log the result of ping.
- session – Local executon hint or session to execute the ping command.
-
virttest.utils_test.
raw_ping
(command, timeout, session, output_func)[source]¶ Low-level ping command execution.
Parameters: - command – Ping command.
- timeout – Timeout of the ping command.
- session – Local executon hint or session to execute the ping command.
-
virttest.utils_test.
run_autotest
(vm, session, control_path, timeout, outputdir, params, copy_only=False, control_args=None, ignore_session_terminated=False)[source]¶ Run an autotest control file inside a guest (linux only utility).
Parameters: - vm – VM object.
- session – A shell session on the VM provided.
- control_path – A path to an autotest control file.
- timeout – Timeout under which the autotest control file must complete.
- outputdir – Path on host where we should copy the guest autotest results to.
- copy_only – If copy_only is True, copy the autotest to guest and return the command which need to run test on guest, without executing it.
- control_args – The arguments for control file.
- ignore_session_terminated – If set up this parameter to True we will ignore the session terminated during test.
The following params is used by the migration :param params: Test params used in the migration test
-
virttest.utils_test.
run_virt_sub_test
(test, params, env, sub_type=None, tag=None)[source]¶ Call another test script in one test script. :param test: Virt Test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. :param sub_type: Type of called test script. :param tag: Tag for get the sub_test params
-
virttest.utils_test.
start_windows_service
(session, service, timeout=120)[source]¶ Start a Windows service using sc. If the service is already running, do nothing. If the service isn’t installed, fail.
Parameters: - service – The name of the service
- timeout – Time duration to wait for service to start
Raises: error.TestError – Raised if the service can’t be started
-
virttest.utils_test.
stop_windows_service
(session, service, timeout=120)[source]¶ Stop a Windows service using sc. If the service is already stopped or is not installed, do nothing.
Parameters: - service – The name of the service
- timeout – Time duration to wait for service to stop
Raises: error.TestError – Raised if the service can’t be stopped
-
virttest.utils_test.
summary_up_result
(result_file, ignore, row_head, column_mark)[source]¶ Use to summary the monitor or other kinds of results. Now it calculates the average value for each item in the results. It fits to the records that are in matrix form.
@result_file: files which need to calculate @ignore: pattern for the comment in results which need to through away @row_head: pattern for the items in row @column_mark: pattern for the first line in matrix which used to generate the items in column :return: A dictionary with the average value of results