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:
- If two separate generic implementations could reasonably be concatenated, then the abstract implementation should pass and subclasses should chain calls to super.
- 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.
-
DEFAULT_REBOOT_TIMEOUT
= 1800¶
-
HARDWARE_REPAIR_REQUEST_THRESHOLD
= 4¶
-
HOURS_TO_WAIT_FOR_RECOVERY
= 2.5¶
-
WAIT_DOWN_REBOOT_TIMEOUT
= 840¶
-
WAIT_DOWN_REBOOT_WARNING
= 540¶
-
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
-
cleanup_kernels
(boot_dir='/boot')[source]¶ Remove any kernel image and associated files (vmlinux, system.map, 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’
-
erase_dir_contents
(path, ignore_status=True, timeout=3600)[source]¶ Empty a given directory path contents.
-
get_boot_id
(timeout=60)[source]¶ 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_meminfo
()[source]¶ Get the kernel memory info (/proc/meminfo) of the remote machine and return a dictionary mapping the various statistics.
-
get_open_func
(use_cache=True)[source]¶ 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 self.run(‘cat <file>’) and may cache the results for the same filename.
- :param use_cache Cache results of self.run(‘cat <filename>’) for the
- same filename
Returns: a function that can be used instead of built-in open()
-
job
= None¶
-
log_kernel
()[source]¶ 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.
-
log_reboot
(reboot_func)[source]¶ 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.
-
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.
-
repair_with_protection
(protection_level)[source]¶ 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
-
request_hardware_repair
()[source]¶ 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.
Parameters: - 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
Returns: a utils.CmdResult object
Raises: AutotestHostRunError – the exit code of the command execution was not 0 and ignore_status was not enabled
-
symlink_closure
(paths)[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.