hosts Package

hosts Package

This is a convenience module to import all available types of hosts.

Implementation details: You should ‘import hosts’ instead of importing every available host module.

base_classes Module

This module defines the base classes for the Host hierarchy.

Implementation details: You should import the “hosts” package instead of importing each type of host.

Host: a machine on which you can run programs
class autotest.client.shared.hosts.base_classes.Host(*args, **dargs)[source]

Bases: object

This class represents a machine on which you can run programs.

It may be a local machine, the one autoserv is running on, a remote machine or a virtual machine.

Implementation details: This is an abstract class, leaf subclasses must implement the methods listed here. You must not instantiate this class but should instantiate one of those leaf subclasses.

When overriding methods that raise NotImplementedError, the leaf class is fully responsible for the implementation and should not chain calls to super. When overriding methods that are a NOP in Host, the subclass should chain calls to super(). The criteria for fitting a new method into one category or the other should be:

  1. If two separate generic implementations could reasonably be concatenated, then the abstract implementation should pass and subclasses should chain calls to super.
  2. If only one class could reasonably perform the stated function (e.g. two separate run() implementations cannot both be executed) then the method should raise NotImplementedError in Host, and the implementor should NOT chain calls to super, to ensure that only one implementation ever gets executed.
check_diskspace(path, gb)[source]

Raises an error if path does not have at least gb GB free.

:param path The path to check for free disk space. :param gb A floating point number to compare with a granularity

of 1 MB.

1000 based SI units are used.

:raise AutoservDiskFullHostError if path has less than gb GB free.

check_partitions(root_part, filter_func=None)[source]

Compare the contents of /proc/partitions with those of /proc/mounts and raise exception in case unmounted partitions are found

root_part: 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

filter_func: unnary predicate for additional filtering out of partitions required to be mounted

Raise: error.AutoservHostError if unfiltered unmounted partition found


Remove any kernel image and associated files (vmlinux,, modules) for any image found in the boot directory that is not referenced by entries in the bootloader configuration.

Parameters:boot_dir – boot directory path string, default ‘/boot’

Allow all network packets in and out of the host.


Re-enable the IP filters disabled from disable_ipfilters()

erase_dir_contents(path, ignore_status=True, timeout=3600)[source]

Empty a given directory path contents.


Get the hardware architecture of the remote machine.


Get a unique ID associated with the current boot.

Should return a string with the semantics such that two separate calls to Host.get_boot_id() return the same string if the host did not reboot between the two calls, and two different strings if it has rebooted at least once between the two calls.

:param timeout The number of seconds to wait before timing out.

Returns:A string unique to this boot or None if not available.

Get the kernel command line of the remote machine.

get_file(source, dest, delete_dest=False)[source]

Get the kernel version of the remote machine.


Get the kernel memory info (/proc/meminfo) of the remote machine and return a dictionary mapping the various statistics.


Get the number of CPUs in the host according to /proc/cpuinfo.


Defines and returns a function that may be used instead of built-in open() to open and read files. The returned function is implemented by using‘cat <file>’) and may cache the results for the same filename.

:param use_cache Cache results of‘cat <filename>’) for the
same filename
Returns:a function that can be used instead of built-in open()

Gets the list of local processes to wait for in wait_up.


Indicates is a machine is currently shutting down.

job = None

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


Helper method for logging kernel information into the status logs. Intended for cases where the “current” kernel is not really defined and we want to explicitly log it. Does nothing if this host isn’t actually associated with a job.


Decorator for wrapping a reboot in a group for status logging purposes. The reboot_func parameter should be an actual function that carries out the reboot.


Determine if path exists on the remote machine.

reboot_followup(*args, **dargs)[source]
reboot_setup(*args, **dargs)[source]
record(*args, **dargs)[source]

Helper method for recording status logs against Host.job that silently becomes a NOP if Host.job is not available. The args and dargs are passed on to Host.job.record unchanged.


perform file system repairs only


perform software repairs only


Perform the maximal amount of repair within the specified protection level.

Parameters:protection_level – the protection level to use for limiting repairs, a host_protections.Protection

Should somehow request (send a mail?) for hardware repairs on this machine. The implementation can either return by raising the special error.AutoservHardwareRepairRequestedError exception or can try to wait until the machine is repaired and then return normally.

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

Run a command on this host.

  • command – the command line string
  • timeout – time limit in seconds before attempting to kill the running process. The run() function will take a few seconds longer than ‘timeout’ to complete if it has to kill the process.
  • ignore_status – do not raise an exception, no matter what the exit code of the command is.
  • stdout_tee/stderr_tee – where to tee the stdout/stderr
  • stdin – stdin to pass (a string) to the executed command
  • args – sequence of strings to pass as arguments to command by quoting them in ” and escaping their contents if necessary

a utils.CmdResult object


AutotestHostRunError – the exit code of the command execution was not 0 and ignore_status was not enabled

run_output(command, *args, **dargs)[source]
send_file(source, dest, delete_dest=False)[source]

Called to start continuous host logging.


Called to stop continuous host logging.

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.
wait_down(timeout=None, warning_timer=None, old_boot_id=None)[source]
wait_for_restart(timeout=1800, down_timeout=840, down_warning=540, log_failure=True, old_boot_id=None, **dargs)[source]

Wait for the host to come back from a reboot. This is a generic implementation based entirely on wait_up and wait_down.


common Module