-
Notifications
You must be signed in to change notification settings - Fork 1
virttest.utils_test
virttest.utils_test package¶
Subpackages¶
Submodules¶
virttest.utils_test.libguestfs module¶
classvirttest.utils_test.libguestfs.``GuestfishTools
(params)¶
Bases: virttest.utils_libguestfs.GuestfishPersistent
Useful Tools for Guestfish class.
Init a persistent guestfish shellsession.
analyse_release
()¶
Analyse /etc/redhat-release
copy_ifcfg_back
()¶
create_fs
()¶
Create filesystem of disk
Choose lvm or physical partition and create fs on it
create_msdos_part
(device, start='1', end='-1')¶
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)¶
Create only one msdos partition in given device. And return its part name if part add succeed.
get_bootable_part
(device='/dev/sda')¶
get_mbr_id
(device='/dev/sda')¶
get_md5
(path)¶
Get files md5 value.
get_part_size
(part_num)¶
get_part_type
(device='/dev/sda')¶
get_partitions_info
(device='/dev/sda')¶
Get disk partition’s information.
get_root
()¶
Get root filesystem w/ guestfish
params
¶
reset_interface
(iface_mac)¶
Check interface through guestfish.Fix mac if necessary.
write_file
(path, content)¶
Create a new file to vm with guestfish
exceptionvirttest.utils_test.libguestfs.``VTAttachError
(cmd, output)¶
Bases: virttest.utils_test.libguestfs.VTError
exceptionvirttest.utils_test.libguestfs.``VTError
¶
Bases: exceptions.Exception
exceptionvirttest.utils_test.libguestfs.``VTMountError
(cmd, output)¶
Bases: virttest.utils_test.libguestfs.VTError
exceptionvirttest.utils_test.libguestfs.``VTXMLParseError
(cmd, output)¶
Bases: virttest.utils_test.libguestfs.VTError
classvirttest.utils_test.libguestfs.``VirtTools
(vm, params)¶
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.
cat
(filename, vm_ref=None)¶
clone_vm_filesystem
(newname=None)¶
Clone a new vm with only its filesystem disk.
:param newname:if newname is None,
create a new name with clone added.
copy_in
(filename, dest='/tmp', vm_ref=None)¶
copy_out
(file_path, localdir='/tmp', vm_ref=None)¶
define_vm_with_newdisk
()¶
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)¶
Expand vm’s filesystem with virt-resize.
format_disk
(disk_path=None, filesystem=None, partition=None, lvm=None)¶
Parameters:
disk_path – None for additional disk by update_vm_disk() only
get_filesystems_info
(vm_ref=None)¶
get_primary_disk_fs_type
()¶
Get primary disk filesystem type
get_vm_info_with_inspector
(vm_ref=None)¶
Return a dict includes os information.
guestmount
(mountpoint, disk_or_domain=None)¶
Mount filesystems in a disk or domain to host mountpoint.
Parameters:
disk_or_domain – if it is None, use default vm in params
list_df
(vm_ref=None)¶
sparsify_disk
()¶
Sparsify a disk
tar_in
(tar_file, dest='/tmp', vm_ref=None)¶
tar_out
(directory, tar_file='temp.tar', vm_ref=None)¶
update_vm_disk
()¶
Update oldvm’s disk, and then create a newvm.
write_file_with_guestmount
(mountpoint, path, content=None, vm_ref=None, cleanup=True)¶
Write content to file with guestmount
virttest.utils_test.libguestfs.``attach_additional_disk
(vm, disksize, targetdev)¶
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)¶
Cleanup the vm with its disk deleted.
virttest.utils_test.libguestfs.``define_new_vm
(vm_name, new_name)¶
Just define a new vm from given name
virttest.utils_test.libguestfs.``get_primary_disk
(vm)¶
Get primary disk source.
Parameters:
vm – Libvirt VM object.
virttest.utils_test.libguestfs.``preprocess_image
(params)¶
Create a disk which used by guestfish
params: Get params from cfg file
virttest.utils_test.libguestfs.``primary_disk_virtio
(vm)¶
To verify if system disk is virtio.
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 linux_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.
classvirttest.utils_test.libvirt.``LibvirtNetwork
(net_type, **kwargs)¶
Bases: object
Class to create a temporary network for testing.
cleanup
()¶
Clear up network.
create_bridge_xml
()¶
Create XML for a bridged network.
create_macvtap_xml
()¶
Create XML for a macvtap network.
create_vnet_xml
()¶
Create XML for a virtual network.
classvirttest.utils_test.libvirt.``MigrationTest
¶
Bases: object
Class for migration tests
cleanup_dest_vm
(vm, srcuri, desturi)¶
Cleanup migrated vm on remote host.
do_migration
(vms, srcuri, desturi, migration_type, options=None, thread_timeout=60, ignore_status=False, func=None, **args)¶
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
- options – migration options
- thread_timeout – time out seconds for the migration thread running
- ignore_status – determine if an exception is raised for errors
- func – the function executed during migration thread is running
- args – dictionary used by func, ‘func_param’ is mandatory if no real func_param, none is requested. ‘shell’ is optional, where shell=True(bool) can be used for process.run
thread_func_migration
(vm, desturi, options=None, ignore_status=False)¶
Thread for virsh migrate command.
Parameters:
- vm – A libvirt vm instance(local or remote).
- desturi – Remote host uri.
- options – The options for migration command.
- ignore_status – True, means no CmdError will be caught for the failure. False, means an CmdError will be caught for the failure.
classvirttest.utils_test.libvirt.``PoolVolumeTest
(test, params)¶
Bases: object
Test class for storage pool or volume
cleanup_pool
(pool_name, pool_type, pool_target, emulated_image, **kwargs)¶
Delete vols, destroy the created pool and restore the env
pre_pool
(pool_name, pool_type, pool_target, emulated_image, **kwargs)¶
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
pre_vol
(vol_name, vol_format, capacity, allocation, pool_name)¶
Preapare the specific type volume in pool
pre_vol_by_xml
(pool_name, **vol_params)¶
Prepare volume by xml file
virttest.utils_test.libvirt.``alter_boot_order
(vm_name, pci_id, boot_order=0)¶
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)¶
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)¶
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)¶
Check if pool_name exist in active pool list
virttest.utils_test.libvirt.``check_blockjob
(vm_name, target, check_point='none', value='0')¶
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(with unit) or 0(no job)
Returns:
Boolean value, true for pass, false for fail
virttest.utils_test.libvirt.``check_exit_status
(result, expect_error=False)¶
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)¶
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)¶
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 TestSkipError 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=[], domxml=None)¶
Do recovery after snapshot
Parameters:
- vm_name – Name of domain
- snapshot_list – The list of snapshot name you want to remove
- domxml – The object of domain xml for dumpxml command
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*.*', patterns_extra_dict=None)¶
Connect to libvirt daemon
Parameters:
- uri – the uri to connect the libvirtd
- read_only – the read only option for virsh
- virsh_cmd – the virsh command for virsh
- auth_user – the user used to connect
- auth_pwd – the password for the user
- vm_name – the guest name to operate
- status_error – if expect error status
- extra – extra parameters
- log_level – logging level
- su_user – the user to su
- patterns_virsh_cmd – the pattern to match in virsh command output
- patterns_extra_dict – a mapping with extra patterns and responses
Returns:
True if success, otherwise False
virttest.utils_test.libvirt.``cpu_allowed_list_by_task
(pid, tid)¶
Get the Cpus_allowed_list in status of task.
virttest.utils_test.libvirt.``cpus_parser
(cpulist)¶
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)¶
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)¶
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_disk_xml
(params)¶
Create a disk configuration file.
virttest.utils_test.libvirt.``create_hostdev_xml
(pci_id, boot_order=0)¶
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)¶
virttest.utils_test.libvirt.``create_net_xml
(net_name, params)¶
Create a new network or update an existed network xml
virttest.utils_test.libvirt.``create_nwfilter_xml
(params)¶
Create a new network filter or update an existed network filter xml
virttest.utils_test.libvirt.``create_scsi_disk
(scsi_option, scsi_size='2048')¶
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)¶
Just define a new vm from given name
virttest.utils_test.libvirt.``define_pool
(pool_name, pool_type, pool_target, cleanup_flag, **kwargs)¶
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)¶
virttest.utils_test.libvirt.``delete_scsi_disk
()¶
Delete scsi device by removing scsi_debug kernel module.
virttest.utils_test.libvirt.``device_exists
(vm, target_dev)¶
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, extra_opt='')¶
Migrate VM to target host.
virttest.utils_test.libvirt.``exec_virsh_edit
(source, edit_cmd, connect_uri='qemu:///system')¶
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
()¶
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_all_vol_paths
()¶
Get all volumes’ path in host
virttest.utils_test.libvirt.``get_host_ipv4_addr
()¶
Get host ipv4 addr
virttest.utils_test.libvirt.``get_ifname_host
(vm_name, mac)¶
Get the vm interface name on host
Returns:
interface name, None if not exist
virttest.utils_test.libvirt.``get_interface_details
(vm_name)¶
Get the interface details from virsh domiflist command output
Returns:
list of all interfaces details
virttest.utils_test.libvirt.``get_iothreadsinfo
(vm_name, options=None)¶
Parse domain iothreadinfo.
Parameters:
vm_name – Domain name
Returns:
The dict of domain iothreads
::
# virsh iothreadinfo vm2 IOThread ID CPU Affinity ————————————————— 2 3 1 0-4 4 0-7 3 0-7
The function return a dict like:
::
{‘2’: ‘3’, ‘1’: ‘0-4’, ‘4’: ‘0-7’, ‘3’: ‘0-7’}
virttest.utils_test.libvirt.``get_parts_list
(session=None)¶
Get all partition lists.
virttest.utils_test.libvirt.``get_vol_list
(pool_name, vol_check=True, timeout=5)¶
This is a wrapper to get all volumes of a pool, especially for iscsi type pool as the volume may not appear immediately after iscsi target login.
Parameters:
- pool_name – Libvirt pool name
- vol_check – Check if volume and volume path exist
- timeout – Timeout in seconds.
Returns:
A dict include volumes’ name(key) and path(value).
virttest.utils_test.libvirt.``hotplug_domain_vcpu
(domain, count, by_virsh=True, hotplug=True)¶
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)¶
Set label for disk.
virttest.utils_test.libvirt.``mk_part
(disk, size='100M', session=None)¶
Create a partition for disk
virttest.utils_test.libvirt.``mkfs
(partition, fs_type, options='', session=None)¶
Make a file system on the partition
virttest.utils_test.libvirt.``new_disk_vol_name
(pool_name)¶
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)¶
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')¶
Remotely restart libvirt service
virttest.utils_test.libvirt.``set_controller_multifunction
(vm_name, controller_type='scsi')¶
Set multifunction on for controller device and expand to all function.
virttest.utils_test.libvirt.``set_domain_state
(vm, vm_state)¶
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)¶
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)¶
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 disk
Parameters:
- 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')¶
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')¶
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='')¶
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)¶
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, disk_image_name='', source_type='file')¶
Update disk source path of the VM
Parameters:
source_type – it may be ‘dev’ or ‘file’ type, which is default
virttest.utils_test.libvirt.``verify_virsh_console
(session, user, passwd, timeout=10, debug=False)¶
Run commands in console session.
virttest.utils_test.libvirt.``virsh_cmd_has_option
(cmd, option, raise_skip=True)¶
Check whether virsh command support given option.
Parameters:
- cmd – Virsh command name
- option – Virsh command option
Raise_skip:
Whether raise exception when option not find
Returns:
True/False or raise TestSkipError
virttest.utils_test.libvirt.``yum_install
(pkg_list, session=None)¶
Try to install packages on system
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.
classvirttest.utils_test.``BackgroundTest
(func, params, kwargs={})¶
Bases: object
This class would run a test in background through a dedicated thread.
Initialize the object and set a few attributes.
is_alive
()¶
Check whether the test is still alive.
join
(timeout=600, ignore_status=False)¶
Wait for the join of thread and raise its exception if any.
launch
(func, params, kwargs)¶
Catch and record the exception.
start
()¶
Run func(params) in a dedicated thread
classvirttest.utils_test.``HostStress
(params, stress_type)¶
Bases: object
Run Stress tool on host, such as stress, unixbench, iozone and etc.
Set parameters for stress type
app_running
()¶
check whether app really run in background
load_stress_tool
(*args, **kwargs)¶
load stress tool on host.
unload_stress
(*args, **kwargs)¶
stop stress tool manually
classvirttest.utils_test.``RemoteDiskManager
(params)¶
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)¶
Create an image for target path.
create_vg
(vgname, device)¶
Create volume group with provided device.
get_free_space
(disk_type, path='/', vgname=None)¶
Get free space of remote host for path.
:return : the unit is ‘G’.
iscsi_login_setup
(host, target_name, is_login=True)¶
Login or logout to a target on remote host.
occupy_space
(disk_type, need_size, path=None, vgname=None, timeout=60)¶
Create an image or volume to occupy the space of destination path
remove_path
(disk_type, path)¶
Only allowed to remove path to file or volume.
remove_vg
(vgname)¶
Remove volume group on remote host.
classvirttest.utils_test.``RemoteVMManager
(params)¶
Bases: object
Manage VM on remote host
check_network
(vm_ip, count=5, timeout=60)¶
Check VM network connectivity
run_command
(vm_ip, command, vm_user='root', runner=None, ignore_status=False)¶
Run command in the VM.
Parameters:
- vm_ip – The IP address of the VM
- command – The command to be executed in the VM
- vm_user – The logon user to the VM
- runner – The runner to execute the command
- ignore_status – True, not raise an exception and will return CmdResult object. False, raise an exception.
Raise:
exceptions.TestFail, if the command fails
Returns:
CmdResult object
setup_ssh_auth
(vm_ip, vm_pwd, vm_user='root', port=22, timeout=10)¶
Setup SSH passwordless access between remote host and VM, which is on the remote host.
exceptionvirttest.utils_test.``StressError
(msg)¶
Bases: exceptions.Exception
Stress test exception.
classvirttest.utils_test.``VMStress
(vm, stress_type)¶
Bases: object
Run Stress tool in vms, such as stress, unixbench, iozone and etc.
Set parameters for stress type
app_running
()¶
check whether app really run in background
get_session
()¶
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)¶
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, vm_ip, remote_host, username, password, shell_prompt='[\\#\\$]\\s*$', timeout=60)¶
Ping migrated vms on remote host.
virttest.utils_test.``get_date
(session=None)¶
Get the date time
virttest.utils_test.``get_driver_hardware_id
(driver_path, mount_point='/tmp/avocado_Wt9Uw4/mnt-virtio', storage_path='/tmp/avocado_Wt9Uw4/prewhql.iso', re_hw_id='(PCI.{14, 50})', run_cmd=True)¶
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_image_info
(image_file)¶
virttest.utils_test.``get_loss_ratio
(output)¶
Get the packet loss ratio from the output of ping.
Parameters:
output – Ping output.
virttest.utils_test.``get_memory_info
(lvms)¶
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)¶
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)¶
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)¶
Get the windows disk drive number
virttest.utils_test.``get_windows_file_abs_path
(session, filename, extension='exe', tmout=240)¶
return file abs path “drive+path” by “wmic datafile”
virttest.utils_test.``load_stress
(stress_type, vms, params)¶
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.``ntpdate
(service_ip, session=None)¶
set the date and time via NTP
virttest.utils_test.``run_autotest
(vm, session, control_path, timeout, outputdir, params, copy_only=False, control_args=None, ignore_session_terminated=False)¶
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)¶
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.``service_setup
(vm, session, directory)¶
virttest.utils_test.``start_windows_service
(session, service, timeout=120)¶
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:
exceptions.TestError – Raised if the service can’t be started
virttest.utils_test.``stop_windows_service
(session, service, timeout=120)¶
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:
exceptions.TestError – Raised if the service can’t be stopped
virttest.utils_test.``summary_up_result
(result_file, ignore, row_head, column_mark)¶
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
virttest.utils_test.``unload_stress
(stress_type, vms)¶
Unload stress loaded by load_stress(...).
virttest.unittest_utils package
virttest.utils_test.qemu package
© Copyright 2014, Red Hat. Created using Sphinx 1.5.1.