This isn’t final API documentation, more of an example of how we can do API docs.
Once more of our code is using sphinx-style docs, we can start finalizing the format for this page.
Note that the docs here are for libtaskotron library functions and don’t include directives or task yaml details.
Helper class for working with supported arches inside taskotron
all supported architectures
base architectures
meta architectures
This returns the ‘base’ architecture identifier for a specified architecture (e.g. i386 for i[3-6]86), to be used by YUM etc.
Parameters: | arch (str) – an architecture to be converted to a basearch. If None, then the arch of the current machine is used. |
---|---|
Returns: | basearch, or arch if no basearch was found for it |
Return type: | str |
Utility functions for dealing with Bodhi
Helper Bodhi methods.
Variables: | client (fedora.client.Bodhi2Client) – Bodhi2 client instance |
---|
Create a new BodhiUtils instance.
Parameters: | client – custom Bodhi2Client instance. If None, a default Bodhi2Client instance is used. |
---|
Find matching Bodhi updates for provided builds.
Parameters: |
|
---|---|
Returns: | a tuple of two dictionaries:
|
Raises TaskotronValueError: | |
if builds type is incorrect |
Get the last Bodhi update for the specified update ID.
Parameters: | updateid (str) – update ID, e.g. ‘FEDORA-2015-13787’ |
---|---|
Returns: | Bodhi update object with that ID, or None when no such update is found |
Return type: | munch.Munch |
Utility functions for dealing with Buildbot
Form url to the job and its logs based on given jobid.
Parameters: |
|
---|---|
Returns: | (job_url, log_url) |
Parse the incoming jobid which should either be ‘-1’ to indicate that dummy values should be used or in the form of <builder>/<buildid>.
If the passed in format is invalid, no exceptions will be raised but a warning message will be emitted to logs
Parameters: | jobid (str) – jobid from runner |
---|---|
Returns: | (builder, buildid) |
Helper tools for managing check status, outcome, and output.
Class encompassing everything related to the outcome of a check run. It contains convenience methods for tracking, evaluating and reporting check results.
For some checks, it’s trivial to parse its output at the end of its execution and evaluate the results. For some, however, it’s much easier to do this continuously during check execution. This is especially true for multi-item checks (a single check providing results for many items - builds, updates, etc). That’s when this class comes very handy (it can be used even for the simple use cases, of course).
Variables: |
|
---|
Tells whether the check outcome is set to one of the broken states (i.e. ABORTED or CRASHED).
Compare two outcomes according to outcome_priority and return -1/0/1 if outcome1 has lower/equal/higher priority than outcome2.
Parameters: |
|
---|---|
Raises TaskotronValueError: | |
if any of the outcome keywords are not specified in outcome_priority |
Create a string containing a sum of all outcomes, like this: 3 PASSED, 1 INFO, 2 FAILED
Parameters: | outcomes – either one CheckDetail instance or an iterable of CheckDetails or an iterable of outcome strings |
---|
Add a string to the output, and print it optionally as well.
This is just a convenience method for most common use case, you can of course always access and modify output directly, and print or use logging facilities directly as well. This combines both into a single call.
Parameters: |
|
---|
Update outcome with the provided value only and only if it has a higher priority than its current value (according to outcome_priority). Otherwise this call does nothing.
This is useful if your check performs a number of ‘sub-tasks’, each passing or failing, and you want to final outcome to be the worst/most serious one of those. You can just keep calling update_outcome() and the highest priority outcome type will be stored at outcome at the end.
Parameters: | outcome (str) – the outcome value to assign to outcome if it has a higher priority than its current value. Handles None values gracefully (no action). |
---|---|
Raises TaskotronValueError: | |
if any of the outcome keywords are not specified in outcome_priority |
Enum for different types of CheckDetail.report_type
Generate YAML output used for reporting to ResultsDB.
Note: You need to provide all your CheckDetails in a single pass in order to generate a valid YAML output. You can’t call this method several times and then simply join the outputs simply as strings.
Parameters: | check_details – iterable of CheckDetail instances or single instance of CheckDetail |
---|---|
Returns: | YAML output with results for every CheckDetail instance provided |
Return type: | str |
Raises TaskotronValueError: | |
if CheckDetail.item or CheckDetail.outcome is empty for any parameter provided |
Example output:
results:
- item: xchat-0.5-1.fc20
type: koji_build
outcome: PASSED
note: 5 ERRORS, 10 WARNINGS
artifact: xchat-0.5-1.fc20.x86_64.log
Parses YAML and returns a list of CheckDetails.
Parameters: | source (str) – YAML-formatted text |
---|---|
Raises TaskotronValueError: | |
if YAML syntax is incorrect |
Global configuration for Taskotron and relevant helper methods.
A list of directories where config files are stored. The config files are loaded from these locations in the specified order, and only the first config file found is used (further locations are ignored). The first location is dynamic, relative to the package location and it reflects the usual config location in a git checkout.
the name of our configuration file
environment variable name for setting config profile
Get the Config instance. This method is implemented using the singleton pattern - you will always receive the same instance, which will get auto-initialized on the first method call.
Returns: | either Config or its subclass, depending on taskotron profile used. |
---|---|
Raises TaskotronConfigError: | |
if config file parsing and handling failed |
This includes the default values for Taskotron configuration. This is automatically loaded by config.py and then overridden by values from config files available in system-wide location.
Global configuration for Taskotron (development profile).
The documentation for individual options is available in the config files (unless they’re not present in the config files, then they’re documented here).
Implementation notes:
Configuration for production profile. Inherits values from Config and overrides some. Read Config documentation.
Enum of available profile names. These can be specified in the config file or as the environment variable.
Enum of available runtask mode names. These can be specified in the config file.
Configuration for testing suite profile. Inherits values from Config and overrides some. Read Config documentation.
This module contains custom Taskotron exceptions
All errors related to Taskotron config files
All errors related to Taskotron directives
Common ancestor for Taskotron related exceptions
All generic image related errors
Requested image not found error
All issues with Extensions
NotImplementedError for Taskotron classes, methods and functions
All network and remote-server related errors
Taskotron-specific ValueError
Error in YAML config file of the executed check
This class serves the purpose of actual task execution. It is instantiated by Overlord, PersistentMinion or DisposableMinion.
Create a new instance.
Parameters: |
|
---|
Execute the task (consists of preparing the task and running it).
int exitcode set by exitcode directive, is None if exitcode directive was not used
Helper class for writing data to different streams.
Download a file.
Parameters: |
|
---|---|
Returns: | the path to the downloaded file |
Return type: | str |
Raises TaskotronRemoteError: | |
if download fails |
This is the same as os.makedirs(), but does not raise an exception when the destination directory already exists.
Raises OSError: | if directory doesn’t exist and can’t be created |
---|
Utility methods related to Koji
Helper Koji methods.
Variables: | session (koji.ClientSession) – Koji client session |
---|
Create a new KojiClient
Parameters: | koji_session (koji.ClientSession) – an existing Koji session instance or None if you want a new default session to be created |
---|
Retrieve the RPMs associated with a build NVR into the specified directory.
Parameters: |
|
---|---|
Returns: | list of local filenames of the grabbed RPMs (might be empty, according to your option choices and the particular NVR) |
Return type: | list of str |
Raises: |
|
Downloads all RPMs of all NVRs tagged by a specific Koji tag.
Note: This works basically the same as get_nvr_rpms(), it just downloads a lot of builds instead of a single one. For description of all shared parameters and return values, please see that method.
Parameters: | tag (str) – Koji tag to be queried for available builds, e.g. f20-updates-pending |
---|
Get the latest Koji build for the given package name in the given tag(s).
Parameters: |
|
---|---|
Returns: | str containing NVR of the latest build, None if no build was found |
Get list of URLs for RPMs corresponding to a build.
Parameters: |
|
---|---|
Return type: | list of str |
Raises: |
|
Get list of koji build objects for the rpms. Order of koji objects in this list is the same as order of the respective rpm objects.
Parameters: | rpms (list of str) – list of filenames as either /my/path/nvr.a.rpm or nvr.a.rpm |
---|---|
Returns: | list of Koji buildinfo dictionaries (as returned e.g. from koji.getBuild()) in the same respective order as in``rpms`` |
Return type: | list |
Raises TaskotronRemoteError: | |
if rpm or it’s related build is not found |
Extract RPM version identifier in NEVR format from Koji build object
Parameters: | build (dict) – Koji buildinfo dictionary (as returned e.g. from koji.getBuild()) |
---|---|
Returns: | NEVR string; epoch is included when non-zero, otherwise omitted |
Raises TaskotronValueError: | |
if build is of incorrect type |
Configure logging in libtaskotron.
There are two modes how to operate - as an external library, or as the main script runner:
Add a file handler.
Parameters: |
|
---|---|
Returns: | created file handler |
Raises IOError: | if log file can’t be opened for writing |
Initialize Taskotron logging.
Note: Since this touches the root logger, it should be called only when Taskotron is run as the main program (through its runner), not when it is used as a library.
Parameters: |
|
---|
Initialize Taskotron logging with default values which do not rely on a config file. Only stream logging is enabled here. This is used before the config file is loaded. After that a proper initialization should take place through the init() method.
Note: Since this touches the root logger, it should be called only when Taskotron is run as the main program (through its runner), not when it is used as a library.
Parameters: | level_stream (int) – message level of the stream logger. The level definitions are in logging. If None, the default level is used (i.e. logging.NOTSET). |
---|
the main logger for libtaskotron library, easily accessible from all our modules
our current memory handler sending logged messages to memory log prior to creating file log (after its creation, content of the memory log is flushed into the file log)
our current stream handler sending logged messages to stderr
our current syslog handler sending logged messages to syslog
Check if passed args doesn’t have conflicts and have proper format. In case of error, this function prints error message and exits the program.
Parameters: |
|
---|
Processes raw input args and converts them into specific data types that can be used by tasks. This includes e.g. creating new args based on (item, item_type) pairs, or adjusting selected architecture.
Parameters: | args (dict) – dictionary of raw arguments |
---|---|
Returns: | dict of args with appended specific data |
Base Minion class that shouldn’t be used on its own, it solely initiates inner attributes and environment. It also provides method _run() that delegates the task execution to Executor over SSH.
Create a new instance.
Parameters: |
|
---|
This method has to be implemented by classes that inherits from BaseMinion. It should contain environment initialization, namely set self.ssh to properly instantiated ParamikoWrapper and cleanup (if necessarily). Moreover, the order of private methods has to be: _prepare_task(), _run() and _get_output().
int exitcode set by exitcode directive.
str uuid_dir with path to artifactsdir for storing logs
Minion class that creates a disposable client, connects to it over SSH and runs the task there.
Create a new instance.
Parameters: |
|
---|
Init environment and connect to disposable client for task execution.
Minion class that connects to alredy running machine using SSH and runs the task there.
Create a new instance.
Parameters: |
|
---|
Init environment and connect to remote machine for task execution.
Overlord class encapsulates decision whether the task is run locally or remotely (in persistent or disposable client) and orchestrates the execution.
Create new instance of Overlord.
Parameters: | arg_data (dict) – data from command line arguments |
---|
int exitcode contains the exitcode of task, if None, method start() was not called yet.
Start the overlord, get runner and execute the task (either locally or remotely).
A collection of convenience methods related to Python base libraries.
Decide whether obj is an Iterable (you can traverse through its elements - e.g. list, tuple, set, even dict), but not basestring (which satisfies most collections’ requirements, but we don’t often want to consider as a collection). You can also verify the types of items in the collection.
Parameters: |
|
---|---|
Returns: | whether obj is iterable but not a string, and whether obj contains only item_type items |
Return type: | bool |
Raises TaskotronValueError: | |
if you provide invalid parameter value |
This has the same functionality and basic arguments as iterable() (read its documentation), but decides whether obj is a Sequence (ordered and indexable collection - e.g. list or tuple, but not set or dict).
Parameters: | mutable (bool) – if True, the obj must be a mutable sequence (e.g. list, but not tuple) |
---|
Tools for remote execution primary for disposable clients
Wrapper for SSH communication using paramiko library
Close open connections and files.
Execute a command.
Parameters: | cmd (str) – A command to be executed |
---|---|
Returns: | returncode of the command |
Raises TaskotronRemoteError: | |
If the command has non-zero return code and it isn’t a code of exitcode directive failure. Or if the remote hasn’t sent any data for TIMEOUT seconds. |
Connect to a machine over ssh. Open sftp channel and, if applicable, file that stdout/err from the machine will be saved to.
Raises TaskotronRemoteError: | |
---|---|
when the connection does not succeed |
Get a directory from a remote path.
Parameters: |
|
---|---|
Raises TaskotronRemoteError: | |
If the directory could not be downloaded |
Get a file from a remote path.
Parameters: |
|
---|---|
Raises TaskotronRemoteError: | |
If the file could not be downloaded |
Install packages via dnf.
Parameters: | pkgs (list) – A list of packages to be installed |
---|---|
Raises TaskotronRemoteError: | |
If the command has non-zero return code |
Create a directory on a remote machine.
Parameters: |
|
---|---|
Raises TaskotronRemoteError: | |
If the directory could not be created |
Copy a directory to a remote path.
Parameters: |
|
---|---|
Raises TaskotronRemoteError: | |
If the directory could not be uploaded |
Copy a file to a remote path.
Parameters: |
|
---|---|
Returns: | an SFTPAttributes object containing attributes about the given file, if successful. None otherwise. |
Raises TaskotronRemoteError: | |
If the file could not be copied |
Write data to a remote file.
Parameters: |
|
---|---|
Raises TaskotronRemoteError: | |
If data could not be written |
Utility methods related to RPM
Compare two RPM version identifiers in NEVR format.
Parameters: |
|
---|---|
Returns: | -1/0/1 if nevr1 < nevr2 / nevr1 == nevr2 / nevr1 > nevr2 |
Return type: | int |
Raises TaskotronValueError: | |
if name in nevr1 doesn’t match name in nevr2 |
Parse disttag from an RPM package version string.
Parameters: | rpmstr (str) – string to be manipulated in a format of N(E)VR (foo-1.2-3.fc20 or bar-4:1.2-3.fc20) or N(E)VRA (foo-1.2-3.fc20.x86_64 or bar-4:1.2-3.fc20.i686) |
---|---|
Returns: | string containing dist tag (fc20) |
Raises TaskotronValueError: | |
if rpmstr does not contain dist tag |
Install packages from system repositories using DNF. You need to have enough permissions to run dnf through sudo.
Parameters: | pkgs (list of str) – packages to be installed, e.g. ['pidgin'], or any other specifier supported by dnf install command |
---|---|
Raises TaskotronError: | |
if DNF returncode is not zero |
Check if packages are installed using DNF. No additional permissions needed.
Parameters: | pkgs (list of str) – packages to be checked whether they are installed, e.g. ['pidgin'], or any other specifier supported by dnf install command |
---|---|
Returns: | True if all specified packages are installed, False otherwise |
Return type: | bool |
Parse and convert an RPM package version string into a different format. String identifiers: N - name, E - epoch, V - version, R - release, A - architecture.
Parameters: |
|
---|---|
Returns: | string based on the specified format, or integer if fmt='e' |
Raises TaskotronValueError: | |
if fmt value is not supported |
Methods for operating with a task formula
Find all variables that are leaves (in a tree sense) in an action. Leaves are variables which can no longer be traversed, i.e. “primitive” types like str or int. Non-leaves are containers like dict or list.
For all leaves, call _replace_vars() and update their value with the function’s output.
Parameters: |
|
---|---|
Raises TaskotronYamlError: | |
if text contains a variable that is not present in variables, or if the variable syntax is incorrect |
Interface to locally spawned virtual machines that are used as disposable clients for executing Taskotron tasks.
Retrieve images from either local or remote sources
Get list of images present on the system.
Parameters: | imagesdir – absolute path to directory containing the images, path from config is used if None |
---|
Search for the most recent image available on the system.
Parameters: |
|
---|---|
Returns: | testcloud.image.Image instance |
Raises TaskotronImageError: | |
if no such image for given release and flavor was found |
Search for the most recent image available on the system.
Parameters: |
|
---|---|
Returns: | metadata of the most recent image |
Return type: | dict {‘date’: str, ‘version’: str, ‘release’: str, ‘arch’: str, ‘filename’: str} |
Launch virtual machines with TestCloud and prepare them for executing tasks (install packages etc.)
Parameters: | uuid – unicode string uuid for the task being executed |
---|
hostname to use for spawned instance - based on username of current user
name of the testcloud instance spawned for this task
ip address of the remote machine (only set after prepared and spawned successfully)
password for user on the remote machine
Prepare a virtual machine for running tasks.
Raises TaskotronRemoteError: | |
---|---|
if there are any errors while preparing the virtual machine. |
Tear down the virtual machine by shutting it down and removing any trace of it from the host machine.
Raises TaskotronRemoteError: | |
---|---|
if there is a failure while stopping or removing the virtual machine instance |
username to use when connecting to the virtual machine
uuid of the task which spawned this instance
Wait until port is open. Repeatedly tries to socket.connect on given port.
Parameters: |
|
---|---|
Raises TaskotronInstanceError: | |
when timeouted |
A wrapper object for yumrepoinfo.conf to access its information easily
This class is a wrapper for easily accessing repoinfo.conf file.
Parameters: |
|
---|---|
Raises TaskotronConfigError: | |
if no YUM repositories data is found (empty or non-existent config file). It’s not raised if you specifically request no data to load (filelist=[]). |
Get the list of all supported architectures for a repo
Parameters: | reponame (str) – repository name |
---|
Get branched Fedora release (or None if it doesn’t exist).
Return type: | str or None |
---|
Get a specific key value from a repo
Parameters: |
|
---|---|
Raises TaskotronConfigError: | |
if the key can’t be retrieved (e.g. wrong key or repo name) |
Return release status of specified repo. For non-top-parent repos, return release_status of top parent repo.
Parameters: | reponame (str) – repository name |
---|---|
Returns: | release status of specified repo, lowercased. One of: rawhide, branched, stable, obsolete. |
Return type: | str |
Get the list of stable (supported) Fedora releases.
Return type: | list of str |
---|
Given a repo name, return the yumrepoinfo dict with keys: arches, parents, tag, url, path and name
Parameters: | reponame (str) – repository name |
---|---|
Return type: | dict |
Given a Koji tag, return the corresponding repo dict.
Parameters: | tag (str) – a koji tag, e.g. f20-updates. Note: rawhide is not used as a Koji tag, use number identifier instead or use repo('rawhide')['tag'] to discover it first. |
---|---|
Returns: | repo dict as from repo(), or None if no such Koji tag is found |
Get the list of all known repository names.
Return type: | list of str |
---|
Go through the repo hiearchy and find the top parent for a repo
Parameters: | reponame (str) – repository name |
---|---|
Returns: | the top parent reponame. If reponame doesn’t have any parent, its name is returned (it’s its own top parent) |
Return type: | str |
Raises TaskotronConfigError: | |
if infinite parent loop detected |
Get YumRepoInfo instance. This method is implemented using the singleton pattern - you will always receive the same instance, which will get auto-initialized on the first method call.
Parameters: |
|
---|---|
Returns: | shared YumRepoInfo instance |
Raises TaskotronConfigError: | |
if file config parsing and handling failed |