client Package

autotest_local Module

class autotest.client.autotest_local.AutotestLocalApp[source]

Autotest local app runs tests locally

Point it to a control file and let it rock


base_sysinfo Module

class autotest.client.base_sysinfo.base_sysinfo(job_resultsdir)[source]

Bases: object

log_after_each_iteration(*args, **dargs)
log_after_each_test(*args, **dargs)
log_before_each_iteration(*args, **dargs)
log_before_each_test(*args, **dargs)
log_per_reboot_data(*args, **dargs)

Logging hook called by log_after_each_test to collect keyval entries to be written in the test keyval.

class autotest.client.base_sysinfo.command(cmd, logf=None, log_in_keyval=False, compress_log=False)[source]

Bases: autotest.client.base_sysinfo.loggable

class autotest.client.base_sysinfo.logfile(path, logf=None, log_in_keyval=False)[source]

Bases: autotest.client.base_sysinfo.loggable

class autotest.client.base_sysinfo.loggable(logf, log_in_keyval)[source]

Bases: object

Abstract class for representing all things “loggable” by sysinfo.


base_utils Module

DO NOT import this file directly - import client/bin/, which will mix this in

Convenience functions for use by tests or whomever.

Note that this file is mixed in by - note very carefully the precedence order defined there

autotest.client.base_utils.append_path(oldpath, newpath)[source]

append newpath to oldpath


Calculate some benchmarking statistics. Input is a directory containing a file called ‘time’. File contains one-per-line results of /usr/bin/time. Output is average Elapsed, User, and System time in seconds,

and average CPU percentage.
autotest.client.base_utils.cat_file_to_cmd(file, command, ignore_status=0, return_output=False)[source]

equivalent to ‘cat file | command’ but knows to use zcat or bzcat if appropriate


number of CPUs in the local machine according to /proc/cpuinfo


Check if a list of flags are available on current CPU info

Parameters:flags – A list of cpu flags that must exists

on the current CPU. :type flags: list :returns: bool True if all the flags were found or False if not :rtype: list


Check out the available cpu online map

autotest.client.base_utils.difflist(list1, list2)[source]

returns items in list2 that are not in list1


Return the disk block size, in bytes


Dump an object’s attributes and methods

kind of like dir()


return the requested environment variable, or ‘’ if unset


Extract user, system, and elapsed times into a list of tuples


Returns the directory extracted by the tarball.

autotest.client.base_utils.extract_tarball_to_dir(tarball, dir)[source]

Extract a tarball to a specified directory name instead of whatever the top level of a tarball is - useful for versioned directory names, etc

autotest.client.base_utils.file_contains_pattern(file, pattern)[source]

Return true if file contains the specified egrep pattern

autotest.client.base_utils.force_copy(src, dest)[source]

Replace dest with a new copy of src, even if it exists

Link src to dest, overwriting it if it exists


Return the disk free space, in bytes


Work out which CPU architecture we’re running on


Reads /proc/cpuinfo and returns a list of file lines

Returns:list of lines from /proc/cpuinfo file
Return type:list

Get load per cpu from /proc/stat :return: list of values of CPU times


Get the current cpu vendor name

Returns:string ‘intel’ or ‘amd’ or ‘power7’ depending

on the current CPU architecture. :rtype: string


Get the machine architecture


Return the hardware clock in seconds as a floating point value. Use Coordinated Universal Time if utc is True, local time otherwise. Raise a ValueError if unable to read the hardware clock.


Return the modules dir for the running kernel version


Try to guess what’s the os vendor.


Return the full path to

Ahem. This is crap. Pray harder. Bad Martin.

Returns:return the uptime of system in secs in float

in error case return ‘None’


Return the full path to vmlinux

Ahem. This is crap. Pray harder. Bad Martin.

autotest.client.base_utils.grep(pattern, file)[source]

This is mainly to fix the return code inversion from grep Also handles compressed files.

returns 1 if the pattern is present in the file, 0 if not.

autotest.client.base_utils.hash_file(filename, size=None, method='md5')[source]

Calculate the hash of filename. If size is not None, limit to first size bytes. Throw exception if something is wrong with filename. Can be also implemented with bash one-liner (assuming size%1024==0): dd if=filename bs=1024 count=size/1024 | sha1sum -

  • filename – Path of the file that will have its hash calculated.
  • method – Method used to calculate the hash. Supported methods: * md5 * sha1

Hash of the file, if something goes wrong, return None.

autotest.client.base_utils.list_grep(list, pattern)[source]

True if any item in list matches the specified pattern.

autotest.client.base_utils.locate(pattern, root='/home/docs/checkouts/')[source]

Ping the default gateway.

autotest.client.base_utils.prepend_path(newpath, oldpath)[source]

prepend newpath to oldpath


Output string straight to the tty


‘pgrep name’ misses all python processes and also long process names. ‘pgrep -f name’ gets all shell commands with name in args. So look only for command whose initial pathname ends with name. Name itself is an egrep pattern, so it can use | etc for variations.


Return path of config file of the currently running kernel


Set the system power state to ‘state’.


Set the hardware RTC-based wake alarm to ‘alarm_time’.


Power-on suspend (S1)


Suspend the system to disk (S4)


Suspend the system to RAM (S3)

autotest.client.base_utils.sysctl(key, value=None)[source]

Generic implementation of sysctl, to read and write.

  • key – A location under /proc/sys
  • value – If not None, a value to write into the sysctl.

The single-line sysctl value as a string.

autotest.client.base_utils.sysctl_kernel(key, value=None)[source]

(Very) partial implementation of sysctl, for kernel params


Converts a string in M+:SS.SS format to S+.SS


Removes a module. Handles dependencies. If even then it’s not possible to remove one of the modules, it will trhow an error.CmdError exception.

Parameters:module_name – Name of the module we want to remove.
autotest.client.base_utils.unmap_url_cache(cachedir, url, expected_hash, method='md5')[source]

Downloads a file from a URL to a cache directory. If the file is already at the expected position and has the expected hash, let’s not download it again.

  • cachedir – Directory that might hold a copy of the file we want to download.
  • url – URL for the file we want to download.
  • expected_hash – Hash string that we expect the file downloaded to have.
  • method – Method used to calculate the hash string (md5, sha1).

Dump the current list of filehandles

bkr_proxy Module

bkr_proxy - class used to talk to beaker

class autotest.client.bkr_proxy.BkrProxy(recipe_id, labc_url=None)[source]

Bases: object

recipe_upload_file(localfile, remotepath='')[source]
result_upload_file(task_id, result_id, localfile, remotepath='')[source]
task_result(task_id, result_type, result_path, result_score, result_summary)[source]
task_start(task_id, kill_time=0)[source]
task_upload_file(task_id, localfile, remotepath='')[source]
update_watchdog(task_id, kill_time)[source]
exception autotest.client.bkr_proxy.BkrProxyException(text)[source]

Bases: exceptions.Exception

autotest.client.bkr_proxy.copy_data(data, dest, header=None, use_put=None)[source]

Copy data to a destination

To aid in debugging, copy a file locally to verify the contents. Attempts to write the same data that would otherwise be sent remotely.

  • data – data string to copy
  • dest – destination path
  • header – header info item to return
  • use_put – dictionary of items for PUT method

nothing or header info if requested

autotest.client.bkr_proxy.copy_local(data, dest, use_put=None)[source]

Copy data locally to a file

To aid in debugging, copy a file locally to verify the contents. Attempts to write the same data that would otherwise be sent remotely.

  • data – encoded data string to copy locally
  • dest – local file path
  • use_put – chooses to write in binary or text


autotest.client.bkr_proxy.copy_remote(data, dest, use_put=None)[source]

Copy data to a remote server using http calls POST or PUT

Using http POST and PUT methods, copy data over http. To use PUT method, provide a dictionary of values to be populated in the Content-Range and Content-Length headers. Otherwise default is to use POST method.

Traps on HTTPError 500 and 400

  • data – encoded data string to copy remotely
  • dest – remote server URL
  • use_put – dictionary of items if using PUT method

html header info for post processing


Converts a recipe id into an internal path for cache’ing recipe

Parameters:r – recipe id
Returns:a path to the internal recipe cache file

Converts a recipe id into an internal path for logging purposes

Parameters:r – recipe id
Returns:a path to the internal command log
autotest.client.bkr_proxy.make_path_log(r, t=None, i=None)[source]

Converts id into a beaker path to log file

Given a recipe id, a task id, and/or result id, translate them into the proper beaker path to the log file. Depending on which log file is needed, provide the appropriate params. Note the dependency, a result id needs a task id and recipe id, while a task id needs a recipe id.

  • r – recipe id
  • t – task id
  • i – result id

a beaker path of the task’s result file


Converts a recipe id into a beaker path

Parameters:r – recipe id
Returns:a beaker path to the recipe id
autotest.client.bkr_proxy.make_path_result(r, t)[source]

Converts task id into a beaker path to result file

Given a recipe id and a task id, translate them into the proper beaker path to the result file.

  • r – recipe id
  • t – task id

a beaker path of the task’s result file

autotest.client.bkr_proxy.make_path_status(r, t=None)[source]

Converts id into a beaker path to status file

Given a recipe id and/or a task id, translate them into the proper beaker path to the status file. Recipe only, returns the path to the recipe’s status, whereas including a task returns the path to the task’s status.

  • r – recipe id
  • t – task id

a beaker path of the recipe’s/task’s status file


Converts a recipe id into a beaker path for the watchdog

Parameters:r – recipe id
Returns:a beaker path of the recipe’s watchdog file

bkr_xml Module

module to parse beaker xml recipe

class autotest.client.bkr_xml.BeakerXMLParser[source]

Bases: object

Handles parsing of beaker job xml

handle_task(recipe, task_node)[source]
handle_task_param(task, param_node)[source]
handle_task_params(task, param_nodes)[source]
handle_tasks(recipe, task_nodes)[source]

Returns dict, mapping hostname to recipe

class autotest.client.bkr_xml.Recipe[source]

Bases: object

class autotest.client.bkr_xml.Task[source]

Bases: object

Simple record to store task properties

get_param(key, default=None)[source]
autotest.client.bkr_xml.xml_attr(node, key, default=None)[source]
autotest.client.bkr_xml.xml_get_nodes(node, tag)[source]

client_logging_config Module

class autotest.client.client_logging_config.ClientLoggingConfig(use_console=True)[source]

Bases: autotest.client.shared.logging_config.LoggingConfig

add_debug_file_handlers(log_dir, log_name=None)[source]
configure_logging(results_dir=None, verbose=False)[source]

cmdparser Module

Autotest command parser

copyright:Don Zickus <> 2011
class autotest.client.cmdparser.CmdParserLoggingConfig(use_console=True)[source]

Bases: autotest.client.shared.logging_config.LoggingConfig

Used with the sole purpose of providing convenient logging setup for the KVM test auxiliary programs.

configure_logging(results_dir=None, verbose=False)[source]
class autotest.client.cmdparser.CommandParser[source]

Bases: object

A client-side command wrapper for the autotest client.

COMMAND_LIST = ['help', 'list', 'run', 'fetch', 'bootstrap']
bootstrap(args, options)[source]

Bootstrap autotest by fetching the control file first and pass it back

Currently this relies on a harness to retrieve the file

fetch(args, options)[source]

fetch a remote control file or packages

classmethod help()[source]

List the commands and their usage strings.

:param args is not used here.

classmethod list_tests()[source]

List the available tests for users to choose from

parse_args(args, options)[source]

Process a client side command.

Parameters:args – Command line args.
run(args, options)[source]

Wrap args with a path and send it back to autotest.

common Module

config Module

The Job Configuration

The job configuration, holding configuration variable supplied to the job.

The config should be viewed as a hierarchical namespace. The elements of the hierarchy are separated by periods (.) and where multiple words are required at a level they should be separated by underscores (_). Please no StudlyCaps.

For example:
class autotest.client.config.config(job)[source]

Bases: object

The BASIC job configuration

The job object for this job
The job configuration dictionary
set(name, value)[source]

cpuset Module


Condense unsigned (0,4,5,6,7,10) to ‘0,4-7,10’.

autotest.client.cpuset.cpuset_attr(container_name, attr)[source]
autotest.client.cpuset.create_container_directly(name, mbytes, cpus)[source]
autotest.client.cpuset.create_container_via_memcg(name, parent, bytes, cpus)[source]
autotest.client.cpuset.create_container_with_mbytes_and_specific_cpus(name, mbytes, cpus=None, root='', io={}, move_in=True, timeout=0)[source]

Create a cpuset container and move job’s current pid into it Allocate the list “cpus” of cpus to that container

name = arbitrary string tag mbytes = reqested memory for job in megabytes cpus = list of cpu indices to associate with the cpuset

defaults to all cpus avail with given root
root = the parent cpuset to nest this new set within
‘’: unnested top-level container

io = arguments for proportional IO containers move_in = True: Move current process into the new container now. timeout = must be 0: persist until explicitly deleted.

autotest.client.cpuset.create_container_with_specific_mems_cpus(name, mems, cpus)[source]
autotest.client.cpuset.io_attr(container_name, attr)[source]
autotest.client.cpuset.move_tasks_into_container(name, tasks)[source]
autotest.client.cpuset.set_io_controls(container_name, disks=[], ioprio_classes=[2], io_shares=[95], io_limits=[0])[source]

fsdev_disks Module


This method can be called from the test file to optionally restore all the drives used by the test to a standard ext2 format. Note that if use_fsdev_lib() was invoked with ‘reinit_disks’ not set to True, this method does nothing. Note also that only fsdev “server-side” dynamic control files should ever set force_cleanup to True.

class autotest.client.fsdev_disks.fsdev_disks(job)[source]

Disk drive handling class used for file system development


Given a list of disks in the format returned by get_disk_list() above, set the I/O scheduler values on all the disks to the values loaded earlier by load_sched_tunables().

set_tunable(disk, name, path, val)[source]

Given a disk name, a path to a tunable value under _TUNE_PATH and the new value for the parameter, set the value and verify that the value has been successfully set.

autotest.client.fsdev_disks.get_disk_list(std_mounts_only=True, get_all_disks=False)[source]

Get a list of dictionaries with information about disks on this system.

  • std_mounts_only – Whether the function should return only disks that have a mount point defined (True) or even devices that doesn’t (False).
  • get_all_disks – Whether the function should return only partitioned disks (False) or return every disk, regardless of being partitioned or not (True).

List of dictionaries with disk information (see more below).

The ‘disk_list’ array returned by get_disk_list() has an entry for each disk drive we find on the box. Each of these entries is a map with the following 3 string values:

‘device’ disk device name (i.e. the part after /dev/) ‘mountpt’ disk mount path ‘tunable’ disk name for setting scheduler tunables (/sys/block/sd??)

The last value is an integer that indicates the current mount status of the drive:

‘mounted’ 0 = not currently mounted
1 = mounted r/w on the expected path

-1 = mounted readonly or at an unexpected path

When the ‘std_mounts_only’ argument is True we don’t include drives mounted on ‘unusual’ mount points in the result. If a given device is partitioned, it will return all partitions that exist on it. If it’s not, it will return the device itself (ie, if there are /dev/sdb1 and /dev/sdb2, those will be returned but not /dev/sdb. if there is only a /dev/sdc, that one will be returned).

autotest.client.fsdev_disks.match_fs(disk, dev_path, fs_type, fs_makeopt)[source]

Matches the user provided fs_type and fs_makeopt with the current disk.

autotest.client.fsdev_disks.mkfs_all_disks(job, disk_list, fs_type, fs_makeopt, fs_mnt_opt)[source]

Prepare all the drives in ‘disk_list’ for testing. For each disk this means unmounting any mount points that use the disk, running mkfs with ‘fs_type’ as the file system type and ‘fs_makeopt’ as the ‘mkfs’ options, and finally remounting the freshly formatted drive using the flags in ‘fs_mnt_opt’.

autotest.client.fsdev_disks.prepare_disks(job, fs_desc, disk1_only=False, disk_list=None)[source]

Prepare drive(s) to contain the file system type / options given in the description line ‘fs_desc’. When ‘disk_list’ is not None, we prepare all the drives in that list; otherwise we pick the first available data drive (which is usually hdc3) and prepare just that one drive.

fs_desc: A partition.FsOptions instance describing the test -OR- a
legacy string describing the same in ‘/’ separated format:
‘fstype / mkfs opts / mount opts / short name’.
disk1_only: Boolean, defaults to False. If True, only test the first
disk_list: A list of disks to prepare. If None is given we default to
asking get_disk_list().
(mount path of the first disk, short name of the test, list of disks) OR (None, ‘’, None) if no fs_desc was given.

Called from the test file to get the necessary drive(s) ready; return a pair of values: the absolute path to the first drive’s mount point plus the complete disk list (which is useful for tests that need to use more than one drive).

autotest.client.fsdev_disks.restore_disks(job, restore=False, disk_list=None)[source]

Restore ext2 on the drives in ‘disk_list’ if ‘restore’ is True; when disk_list is None, we do nothing.

autotest.client.fsdev_disks.use_fsdev_lib(fs_desc, disk1_only, reinit_disks)[source]

Called from the control file to indicate that fsdev is to be used.

autotest.client.fsdev_disks.wipe_disks(job, disk_list)[source]

Wipe all of the drives in ‘disk_list’ using the ‘wipe’ functionality in the filesystem class.

fsdev_mgr Module

This module defines the BaseFsdevManager Class which provides an implementation of the ‘fsdev’ helper API; site specific extensions to any of these methods should inherit this class.

class autotest.client.fsdev_mgr.BaseFsdevManager[source]

Bases: object

check_mount_point(part_name, mount_point)[source]
  • part_name – A partition name such as ‘sda3’ or similar.
  • mount_point – A mount point such as ‘/usr/local’ or an empty string if no mount point is known.

The expected mount point for part_name or a false value (None or ‘’) if the client should not mount this partition.

Parameters:part_name – A partition name such as ‘sda3’ or similar.
Returns:bool, should we use this partition for testing?
class autotest.client.fsdev_mgr.FsdevManager[source]

Bases: autotest.client.fsdev_mgr.BaseFsdevManager


alias of BaseFsdevManager

fsinfo Module

This module gives the mkfs creation options for an existing filesystem.

tune2fs or xfs_growfs is called according to the filesystem. The results, filesystem tunables, are parsed and mapped to corresponding mkfs options.

autotest.client.fsinfo.compare_features(needed_feature, current_feature)[source]

Compare two ext* feature lists.

autotest.client.fsinfo.ext_mkfs_options(tune2fs_dict, mkfs_option)[source]

Map the tune2fs options to mkfs options.


Call tune2fs -l and parse the result.

autotest.client.fsinfo.match_ext_options(fs_type, dev, needed_options)[source]

Compare the current ext* filesystem tunables with needed ones.

autotest.client.fsinfo.match_mkfs_option(fs_type, dev, needed_options)[source]

Compare the current filesystem tunables with needed ones.

autotest.client.fsinfo.match_xfs_options(dev, needed_options)[source]

Compare the current ext* filesystem tunables with needed ones.

autotest.client.fsinfo.merge_ext_features(conf_feature, user_feature)[source]

Breaks the mkfs.ext* option string into dictionary.

autotest.client.fsinfo.parse_mke2fs_conf(fs_type, conf_file='/etc/mke2fs.conf')[source]

Parses mke2fs config file for default settings.

autotest.client.fsinfo.xfs_mkfs_options(tune2fs_dict, mkfs_option)[source]

Maps filesystem tunables to their corresponding mkfs options.


Call xfs_grow -n to get filesystem tunables.

harness Module

The harness interface

The interface between the client and the server when hosted.

class autotest.client.harness.harness(job)[source]

Bases: object

The NULL server harness

The job object for this job

A run within this job is aborting. It all went wrong


A run within this job is completing (all done)


A run within this job is completing (expect continue)


A run within this job is performing a reboot (expect continue following reboot)


A run within this job is starting


A test run by this job is complete. Note that if multiple tests are run in parallel, this will only be called when all of the parallel runs complete.

The job object for this job
test_status(status, tag)[source]

A test within this job is completing

test_status_detail(code, subdir, operation, status, tag, optional_fields)[source]

A test within this job is completing (detail), job, harness_args)[source]

harness_ABAT Module

harness_autoserv Module

class autotest.client.harness_autoserv.AutoservFetcher(package_manager, job_harness)[source]

Bases: autotest.client.shared.base_packages.RepositoryFetcher

fetch_pkg_file(filename, dest_path)[source]
class autotest.client.harness_autoserv.harness_autoserv(job, harness_args)[source]

Bases: autotest.client.harness.harness

The server harness for running from autoserv

The job object for this job
fetch_package(pkg_name, dest_path)[source]

Request a package from the remote autoserv.

  • pkg_name – The name of the package, as generally used by the client.shared.packages infrastructure.
  • dest_path – The path the package should be copied to.

A test run by this job is complete, signal it to autoserv and wait for it to signal to continue

test_status(status, tag)[source]

A test within this job is completing

harness_beaker Module

The harness interface The interface between the client and beaker lab controller.

exception autotest.client.harness_beaker.HarnessException(text)[source]

Bases: exceptions.Exception

class autotest.client.harness_beaker.harness_beaker(job, harness_args)[source]

Bases: autotest.client.harness.harness


How to kickstart autotest when you have no control file? You download the beaker XML, convert it to a control file and pass it back to autotest. Much like bootstrapping.. :-)

convert_task_to_control(fetchdir, control, task)[source]

Tasks are really just: # yum install $TEST # cd /mnt/tests/$TEST # make run

Convert that into a test module with a control file

parse_args(args, is_bootstrap)[source]

A run within this job is aborting. It all went wrong


A run within this job is completing (all done)


A run within this job is completing (expect continue)


A run within this job is performing a reboot (expect continue following reboot)


A run within this job is starting


A test run by this job is complete. Note that if multiple tests are run in parallel, this will only be called when all of the parallel runs complete.


called from complete and abort. clean up and shutdown

test_status(status, tag)[source]

A test within this job is completing

test_status_detail(code, subdir, operation, status, tag, optional_fields)[source]

A test within this job is completing (detail)

upload_result_files(task_id, resultid, subdir)[source]
upload_task_files(task_id, subdir)[source]
write_processed_tests(subdir, t_id='0')[source]

harness_simple Module

The simple harness interface

class autotest.client.harness_simple.harness_simple(job, harness_args)[source]

Bases: autotest.client.harness.harness

The simple server harness

The job object for this job
test_status(status, tag)[source]

A test within this job is completing

harness_standalone Module

The standalone harness interface

The default interface as required for the standalone reboot helper.

class autotest.client.harness_standalone.harness_standalone(job, harness_args)[source]

Bases: autotest.client.harness.harness

The standalone server harness

The job object for this job

job Module

The main job wrapper

This is the core infrastructure.

Copyright Andy Whitcroft, Martin J. Bligh 2006

exception autotest.client.job.NotAvailableError[source]

Bases: autotest.client.shared.error.AutotestError

exception autotest.client.job.StepError[source]

Bases: autotest.client.shared.error.AutotestError

class autotest.client.job.base_client_job(control, options, drop_caches=True, extra_copy_cmdline=None)[source]

Bases: autotest.client.shared.base_job.base_job

The client-side concrete implementation of base_job.

Optional properties provided by this implementation:
control bootloader harness

Adds the repository locations to the job so that packages can be fetched from them when needed. The repository list needs to be a string list Ex: job.add_repository([‘http://blah1’,’http://blah2‘])

add_sysinfo_command(command, logfile=None, on_every_test=False)[source]
add_sysinfo_logfile(file, on_every_test=False)[source]
barrier(*args, **kwds)[source]

Create a barrier object


Write pending TAP reports, clean up, and exit

config_set(name, value)[source]
end_reboot(subdir, kernel, patches, running_id=None)[source]
end_reboot_and_verify(expected_when, expected_id, subdir, type='src', patches=[])[source]

Check the passed kernel identifier against the command line and the running kernel, abort the job on missmatch.

filesystem(*args, **dargs)

Same as partition

@deprecated: Use partition method instead

handle_persistent_option(options, option_name)[source]

Select option from command line or persistent state. Store selected option to allow standalone client to continue after reboot with previously selected options. Priority: 1. explicitly specified via command line 2. stored in state file (if continuing job ‘-c’) 3. default is None

harness_select(which, harness_args)[source]
install_pkg(name, pkg_type, install_dir)[source]

This method is a simple wrapper around the actual package installation method in the Packager class. This is used internally by the profilers, deps and tests code. name : name of the package (ex: sleeptest, dbench etc.) pkg_type : Type of the package (ex: test, dep etc.) install_dir : The directory in which the source is actually

untarred into. (ex: client/profilers/<name> for profilers)
kernel(base_tree, results_dir='', tmp_dir='', leave=False)[source]

Summon a kernel object


Signal that the job should monitor disk space usage on / and generate a warning if a test uses up disk space at a rate exceeding ‘max_rate’.

max_rate - the maximium allowed rate of disk consumption
during a test, in MB/hour, or 0 to indicate no limit.
next_step(fn, *args, **dargs)[source]

Create a new step and place it after any steps added while running the current step but before any steps added in previous steps

next_step_append(fn, *args, **dargs)[source]

Define the next step and place it at the end

next_step_prepend(fn, *args, **dargs)[source]

Insert a new step, executing first

parallel(*args, **dargs)[source]

Run tasks in parallel

partition(device, loop_size=0, mountpoint=None)[source]

Work with a machine partition

param device:e.g. /dev/sda2, /dev/sdb1 etc...
param mountpoint:
 Specify a directory to mount to. If not specified autotest tmp directory will be used.
param loop_size:
 Size of loopback device (in MB). Defaults to 0.
return:A L{client.partition.partition} object
reboot(tag=<object object>)[source]

Return a patch relative to the job results directory


Test whether gcc is installed on the machine.

run_group(function, tag=None, **dargs)[source]

Run a function nested within a group level.

Callable to run.
An optional tag name for the group. If None (default) function.__name__ will be used.
Named arguments for the function.
run_test(*args, **dargs)[source]

Summon a test object and run it.

:param url A url that identifies the test to run. :param tag An optional keyword argument that will be added to the

test and subdir name.
:param subdir_tag An optional keyword argument that will be added
to the subdir name.
Returns:True if the test passes, False otherwise.
run_test_detail(*args, **dargs)[source]

Summon a test object and run it, returning test status.

:param url A url that identifies the test to run. :param tag An optional keyword argument that will be added to the

test and subdir name.
:param subdir_tag An optional keyword argument that will be added
to the subdir name.
Returns:Test status

@see: client/shared/, exit_status


Set up the dependencies for this test. deps is a list of libraries required for this test.

setup_dirs(results_dir, tmp_dir)[source]

The multi-run engine used when the control file defines step_init.

Does the next step.

xen(base_tree, results_dir='', tmp_dir='', leave=False, kjob=None)[source]

Summon a xen object

class autotest.client.job.disk_usage_monitor(logging_func, device, max_mb_per_hour)[source]
classmethod watch(*monitor_args, **monitor_dargs)[source]

Generic decorator to wrap a function call with the standard create-monitor -> start -> call -> stop idiom.

class autotest.client.job.job(control, options, drop_caches=True, extra_copy_cmdline=None)[source]

Bases: autotest.client.job.base_client_job

autotest.client.job.runjob(control, drop_caches, options)[source]

Run a job using the given control file.

This is the main interface to this module.

@see base_job.__init__ for parameter info.


alias of base_client_job

class autotest.client.job.status_indenter(job)[source]

Bases: autotest.client.shared.base_job.status_indenter

Provide a status indenter that is backed by job._record_prefix.


kernel Module

class autotest.client.kernel.BootableKernel(job)[source]

Bases: object

autotest.client.kernel.auto_kernel(job, path, subdir, tmp_dir, build_dir, leave=False)[source]

Create a kernel object, dynamically selecting the appropriate class to use based on the path provided.

class autotest.client.kernel.kernel(job, base_tree, subdir, tmp_dir, build_dir, leave=False)[source]

Bases: autotest.client.kernel.BootableKernel

Class for compiling kernels.

Data for the object includes the src files used to create the kernel, patches applied, config (base + changes), the build directory itself, and logged output

Backpointer to the job object we’re part of
Path to the top level autotest dir (see global_config.ini, session COMMON/autotest_top_path)

apply the list of patches, in order

autodir = ''
boot(args='', ident=True)[source]

install and boot this kernel, do not care how just make it happen.

build(*args, **dargs)
build_timed(threads, timefile='/dev/null', make_opts='', output='/dev/null')[source]

time the bulding of the kernel

clean(*args, **dargs)
config(*args, **dargs)
extract(*args, **dargs)
extraversion(tag, append=True)[source]

Work out the current kernel architecture (as a kernel arch)


Check Makefile and .config to return kernel version


Extract/link base_tree to self.build_dir


fetch the patches to the local src_dir

install(*args, **dargs)
mkinitrd(*args, **dargs)
patch(*args, **dargs)

dump a pickle of ourself out to the specified filename

we can’t pickle the backreference to job (it contains fd’s), nor would we want to. Same for logfile (fd’s).

set_cross_cc(target_arch=None, cross_compile=None, build_target='bzImage')[source]

Set up to cross-compile. This is broken. We need to work out what the default compile produces, and if not, THEN set the cross compiler.

class autotest.client.kernel.rpm_kernel(job, rpm_package, subdir)[source]

Bases: autotest.client.kernel.BootableKernel

Class for installing a binary rpm kernel package

boot(args='', ident=True)[source]

install and boot this kernel

build(*args, **dargs)[source]

Dummy function, binary kernel so nothing to build.

install(*args, **dargs)
class autotest.client.kernel.rpm_kernel_suse(job, rpm_package, subdir)[source]

Bases: autotest.client.kernel.rpm_kernel

Class for installing openSUSE/SLE rpm kernel package

add_to_bootloader(tag='dummy', args='')[source]

Set parameters of this kernel in bootloader

autotest.client.kernel.rpm_kernel_vendor(job, rpm_package, subdir)[source]

kernel_config Module

autotest.client.kernel_config.apply_overrides(orig_file, changes_file, output_file)[source]
autotest.client.kernel_config.config_by_name(name, s)[source]
autotest.client.kernel_config.diff_configs(old, new)[source]
autotest.client.kernel_config.feature_enabled(feature, config)[source]

Verify whether a given kernel option is enabled.

  • feature – Kernel feature, such as “CONFIG_DEFAULT_UIMAGE”.
  • config – Config file path, such as /tmp/config.
class autotest.client.kernel_config.kernel_config(job, build_dir, config_dir, orig_file, overrides, defconfig=False, name=None, make=None)[source]

Bases: object

Build directory must be ready before init’ing config.

  1. Get original config file

  2. Apply overrides

  3. Do ‘make oldconfig’ to update it to current source code

    (gets done implicitly during the process)

You may specifiy the defconfig within the tree to build, or a custom config file you want, or None, to get machine’s default config file from the repo.


Copy the current .config file to the config.<name>[.<n>]

update_config(old_config, new_config=None)[source]

kernel_versions Module

autotest.client.kernel_versions.version_choose_config(version, candidates)[source]
autotest.client.kernel_versions.version_limit(version, n)[source]

kernelexpand Module

Program and API used to expand kernel versions, trying to match them with the URL of the correspondent package on or a mirror. Example:

$ ./ 3.1

author:Andy Whitcroft (
copyright:IBM 2008

@license: GPL v2 @see: Inspired by kernelexpand by Martin J. Bligh, 2003


Generate the parameters for the patches (2.X version):

full => full kernel name base => all but the matches suffix minor => 2.n.m major => 2.n minor-prev => 2.n.m-1

Parameters:kernel – String representing a kernel version to be expanded.

Generate the parameters for the patches (post 2.X version):

full => full kernel name base => all but the matches suffix minor => o.n.m major => o.n minor-prev => o.n.m-1

Parameters:kernel – String representing a kernel version to be expanded.
autotest.client.kernelexpand.expand_classic(kernel, mirrors)[source]
autotest.client.kernelexpand.mirror_kernel_components(mirrors, components)[source]

kvm_control Module

Utilities useful to client control files that test KVM.


Get the kvm kernel module to be loaded based on the CPU architecture

Raises:error.TestError if no vendor name or cpu flags are found
Returns:‘kvm_amd’ or ‘kvm_intel’ or ‘kvm_power7’
Return type:string

Loads the appropriate KVM kernel modules depending on the current CPU architecture

Returns:0 on success or 1 on failure
Return type:int

Unloads the current KVM kernel modules ( if loaded )

Returns:0 on success or 1 on failure
Return type:int

local_host Module

This file contains the implementation of a host object for the local machine.

class autotest.client.local_host.LocalHost(*args, **dargs)[source]

Bases: autotest.client.shared.hosts.base_classes.Host


Get a list of files on a remote host given a glob pattern path.

run(command, timeout=3600, ignore_status=False, stdout_tee=<object object>, stderr_tee=<object object>, stdin=None, args=())[source]


Given a sequence of path strings, return the set of all paths that can be reached from the initial set by following symlinks.

Parameters:paths – sequence of path strings.
Returns:a sequence of path strings that are all the unique paths that can be reached from the given ones after following symlinks.

lv_utils Module

Utility for taking shapshots from existing logical volumes or creates such.

author:Plamen Dimitrov
copyright:Intra2net AG 2012

@license: GPL v2

param vg_name:Name of the volume group.
param lv_name:Name of the logical volume.
param lv_size:Size of the logical volume as string in the form “#G” (for example 30G).
param lv_snapshot_name:
 Name of the snapshot with origin the logical volume.
param lv_snapshot_size:
 Size of the snapshot with origin the logical volume also as “#G”.
param ramdisk_vg_size:
 Size of the ramdisk virtual group.
param ramdisk_basedir:
 Base directory for the ramdisk sparse file.
param ramdisk_sparse_filename:
 Name of the ramdisk sparse file.
Sample ramdisk params:
ramdisk_vg_size = “40000” ramdisk_basedir = “/tmp” ramdisk_sparse_filename = “virtual_hdd”
Sample general params:
vg_name=’autotest_vg’, lv_name=’autotest_lv’, lv_size=‘1G’, lv_snapshot_name=’autotest_sn’, lv_snapshot_size=‘1G’

The ramdisk volume group size is in MB.

autotest.client.lv_utils.lv_check(vg_name, lv_name)[source]

Check whether provided logical volume exists.


Check whether provided volume group exists.


List available volume groups.

autotest.client.lv_utils.vg_ramdisk_cleanup(ramdisk_filename, vg_ramdisk_dir, vg_name, loop_device)[source]

Inline cleanup function in case of test error.

optparser Module

Autotest client/local option parser

class autotest.client.optparser.AutotestLocalOptionParser[source]

Bases: optparse.OptionParser

Default autotest option parser

os_dep Module


parallel Module

Parallel execution management

autotest.client.parallel.fork_nuke_subprocess(tmp, pid)[source]
autotest.client.parallel.fork_start(tmp, l)[source]
autotest.client.parallel.fork_waitfor(tmp, pid)[source]
autotest.client.parallel.fork_waitfor_timed(tmp, pid, timeout)[source]

Waits for pid until it terminates or timeout expires. If timeout expires, test subprocess is killed.

partition Module

APIs to write tests and control files that handle partition creation, deletion and formatting.

copyright:Google 2006-2008
author:Martin Bligh (
class autotest.client.partition.FsOptions(fstype, fs_tag, mkfs_flags=None, mount_options=None)[source]

Bases: object

A class encapsulating a filesystem test’s parameters.


Return a list of all available filesystems

autotest.client.partition.filter_partition_list(partitions, devnames)[source]

Pick and choose which partition to keep.

filter_partition_list accepts a list of partition objects and a list of strings. If a partition has the device name of the strings it is returned in a list.

  • partitions – A list of L{partition} objects
  • devnames – A list of devnames of the form ‘/dev/hdc3’ that specifies which partitions to include in the returned list.

A list of L{partition} objects specified by devnames, in the order devnames specified

autotest.client.partition.get_iosched_path(device_name, component)[source]

Picks up mount point information about the machine mounts. By default, we try to associate mount points with UUIDs, because in newer distros the partitions are uniquely identified using them.

autotest.client.partition.get_partition_list(job, min_blocks=0, filter_func=None, exclude_swap=True, open_func=<built-in function open>)[source]

Get a list of partition objects for all disk partitions on the system.

Loopback devices and unnumbered (whole disk) devices are always excluded.

  • job – The job instance to pass to the partition object constructor.
  • min_blocks – The minimum number of blocks for a partition to be considered.
  • filter_func – A callable that returns True if a partition is desired. It will be passed one parameter: The partition name (hdc3, etc.). Some useful filter functions are already defined in this module.
  • exclude_swap – If True any partition actively in use as a swap device will be excluded.
  • __open – Reserved for unit testing.

A list of L{partition} objects.

autotest.client.partition.get_unmounted_partition_list(root_part, job=None, min_blocks=0, filter_func=None, exclude_swap=True, open_func=<built-in function open>)[source]

Return a list of partition objects that are not mounted.

  • root_part

    The root device name (without the ‘/dev/’ prefix, example ‘hda2’) that will be filtered from the partition list.

    Reasoning: in Linux /proc/mounts will never directly mention the root partition as being mounted on / instead it will say that /dev/root is mounted on /. Thus require this argument to filter out the root_part from the ones checked to be mounted.

  • min_blocks, filter_func, exclude_swap, open_func (job,) – Forwarded to get_partition_list().

List of L{partition} objects that are not mounted.


Checks if specified partition is type 83

Parameters:device – the device, e.g. /dev/sda3
Returns:False if the supplied partition name is not type 83 linux, True otherwise

Checks if a disk is valid

Parameters:device – e.g. /dev/sda, /dev/hda

Checks if a partition is valid

Parameters:device – e.g. /dev/sda1, /dev/hda1
autotest.client.partition.parallel(partitions, method_name, *args, **dargs)[source]

Run a partition method (with appropriate arguments) in parallel, across a list of partition objects

class autotest.client.partition.partition(job, device, loop_size=0, mountpoint=None)[source]

Bases: object

Class for handling partitions and filesystems

fsck(args='-fy', record=True)[source]

Run filesystem check

Parameters:args – arguments to filesystem check tool. Default is “-n” which works on most tools.

Return the proper mkfs executable based on self.fstype

get_mountpoint(open_func=<built-in function open>, filename=None)[source]

Find the mount point of this partition object.

  • open_func – the function to use for opening the file containing the mounted partitions information
  • filename – where to look for the mounted partitions information (default None which means it will search /proc/mounts and/or /etc/mtab)

a string with the mount point of the partition or None if not mounted

mkfs(fstype=None, args='', record=True)[source]

Format a partition to filesystem type

  • fstype – the filesystem type, e.g.. “ext3”, “ext2”
  • args – arguments to be passed to mkfs command.
  • record – if set, output result of mkfs operation to autotest output

Return the proper mkfs executable based on fs

mount(mountpoint=None, fstype=None, args='', record=True)[source]

Mount this partition to a mount point

  • mountpoint – If you have not provided a mountpoint to partition object or want to use a different one, you may specify it here.
  • fstype – Filesystem type. If not provided partition object value will be used.
  • args – Arguments to be passed to “mount” command.
  • record – If True, output result of mount operation to autotest output.
run_test(test, **dargs)[source]
run_test_on_partition(test, mountpoint_func, **dargs)[source]

Executes a test fs-style (umount,mkfs,mount,test)

Here we unmarshal the args to set up tags before running the test. Tests are also run by first umounting, mkfsing and then mounting before executing the test.

  • test – name of test to run
  • mountpoint_func – function to return mount point string

Set filesystem options

param fs_options:
 A L{FsOptions} object
set_io_scheduler(device_name, name)[source]

Prepare a partition for running a test. Unmounts any filesystem that’s currently mounted on the partition, makes a new filesystem (according to this partition’s filesystem options) and mounts it where directed by mountpoint_func.

Parameters:mountpoint_func – A callable that returns a path as a string, given a partition instance.
unmount(ignore_status=False, record=True)[source]

Umount this partition.

It’s easier said than done to umount a partition. We need to lock the mtab file to make sure we don’t have any locking problems if we are umounting in paralllel.

If there turns out to be a problem with the simple umount we end up calling umount_force to get more aggressive.

  • ignore_status – should we notice the umount status
  • record – if True, output result of umount operation to autotest output

Kill all other jobs accessing this partition. Use fuser and ps to find all mounts on this mountpoint and unmount them.

Returns:true for success or false for any errors

Delete all files of a given partition filesystem.


Converts a partition name to its associated device

autotest.client.partition.run_test_on_partitions(job, test, partitions, mountpoint_func, tag, fs_opt, do_fsck=True, **dargs)[source]

Run a test that requires multiple partitions. Filesystems will be made on the partitions and mounted, then the test will run, then the filesystems will be unmounted and optionally fsck’d.

  • job – A job instance to run the test
  • test – A string containing the name of the test
  • partitions – A list of partition objects, these are passed to the test as partitions=
  • mountpoint_func – A callable that returns a mountpoint given a partition instance
  • tag – A string tag to make this test unique (Required for control files that make multiple calls to this routine with the same value of ‘test’.)
  • fs_opt – An FsOptions instance that describes what filesystem to make
  • do_fsck – include fsck in post-test partition cleanup.
  • dargs – Dictionary of arguments to be passed to job.run_test() and eventually the test

Unmount a mounted partition

Parameters:device – e.g. /dev/sda1, /dev/hda1
class autotest.client.partition.virtual_partition(file_img, file_size)[source]

Handles block device emulation using file images of disks. It’s important to note that this API can be used only if we have the following programs present on the client machine:

  • sfdisk
  • losetup
  • kpartx

Removes the virtual partition from /dev/mapper, detaches the image file from the loopback device and removes the image file.

autotest.client.partition.wipe_filesystem(job, mountpoint)[source]

profiler Module

class autotest.client.profiler.profiler(job)[source]
initialize(*args, **dargs)[source]
preserve_srcdir = False
setup(*args, **dargs)[source]
supports_reboot = False

setup Module


setup_job Module

autotest.client.setup_job.init_test(options, testdir)[source]

Instantiate a client test object from a given test directory.

:param options Command line options passed in to instantiate a setup_job
which associates with this test.

:param testdir The test directory. :return: A test object or None if failed to instantiate.


Load and instantiate all client tests.

This function is inspired from runtest() on client/shared/

Parameters:options – an object passed in from command line OptionParser. See all options defined on client/autotest.
Returns:a tuple containing the list of all instantiated tests and a list of tests that failed to instantiate.
class autotest.client.setup_job.setup_job(options)[source]

Bases: autotest.client.job.job

setup_job is a job which runs client test setup() method at server side.

This job is used to pre-setup client tests when development toolchain is not available at client.


Direct invoke test.setup() method.

Returns:A boolean to represent success or not.

Load and instantiate all client tests.

This function is inspired from runtest() on client/shared/

Parameters:options – an object passed in from command line OptionParser. See all options defined on client/autotest.

setup_modules Module

Module used to create the autotest namespace for single dir use case.

Autotest programs can be used and developed without requiring it to be installed system-wide. In order for the code to see the library namespace:

from autotest.client.shared import error from autotest.server import hosts ...

Without system wide install, we need some hacks, that are performed here.

author:John Admanski (
autotest.client.setup_modules.import_module(module, from_where)[source]

Equivalent to ‘from from_where import module’.

  • module – Module name.
  • from_where – Package from where the module is being imported.

The corresponding module.

autotest.client.setup_modules.setup(base_path, root_module_name='autotest')[source]

Setup a library namespace, with the appropriate top root module name.

Perform all the necessary setup so that all the packages at ‘base_path’ can be imported via “import root_module_name.package”.

  • base_path – Base path for the module.
  • root_module_name – Top level name for the module.

sysinfo Module

test Module

autotest.client.test.runtest(job, url, tag, args, dargs)[source]
class autotest.client.test.test(job, bindir, outputdir)[source]

Bases: autotest.client.shared.test.base_test

Configure the crash handler by:
  • Setting up core size to unlimited
  • Putting an appropriate crash handler on /proc/sys/kernel/core_pattern
  • Create files that the crash handler will use to figure which tests are active at a given moment

The crash handler will pick up the core file and write it to self.debugdir, and perform analysis on it to generate a report. The program also outputs some results to syslog.

If multiple tests are running, an attempt to verify if we still have the old PID on the system process table to determine whether it is a parent of the current test execution. If we can’t determine it, the core file and the report file will be copied to all test debug dirs.


If core dumps are found on the debugdir after the execution of the test, let the user know.

test_config Module

Wrapper around ConfigParser to manage testcases configuration. (Ricardo Salveti de Araujo)
class autotest.client.test_config.config_loader(cfg, tmpdir='/tmp', raise_errors=False)[source]

Base class of the configuration parser


Check if the config file has valid values

check_parameter(param_type, parameter)[source]

Check if a option has a valid value

get(section, option, default=None)[source]

Get the value of a option.

Section of the config file and the option name. You can pass a default value if the option doesn’t exist.

  • section – Configuration file section.
  • option – Option we’re looking after.
@default: In case the option is not available and raise_errors is set
to False, return the default.
remove(section, option)[source]

Remove an option.


Save the configuration file with all modifications

set(section, option, value)[source]

Set an option.

This change is not persistent unless saved with ‘save()’.

utils Module

Convenience functions for use by tests or whomever.

NOTE: this is a mixin library that pulls in functions from several places Note carefully what the precendece order is

There’s no really good way to do this, as this isn’t a class we can do inheritance with, just a collection of static methods.

xen Module

class autotest.client.xen.xen(job, base_tree, results_dir, tmp_dir, build_dir, leave=False, kjob=None)[source]

Bases: autotest.client.kernel.kernel

add_to_bootloader(tag='autotest', args='')[source]

add this kernel to bootloader, taking an optional parameter of space separated parameters e.g.: kernel.add_to_bootloader(‘mykernel’, ‘ro acpi=off’)

build(make_opts='', logfile='', extraversion='autotest')[source]

build xen

additional options to make, if any
build_timed(*args, **kwds)[source]
config(config_file, config_list=None)[source]

Fix up broken EXTRAVERSION in xen-ified Linux kernel Makefile


Check Makefile and .config to return kernel version


Check xen buildconfig for current kernel version

install(tag='', prefix='/', extraversion='autotest')[source]

make install in the kernel tree