runperf.utils package

Submodules

runperf.utils.cloud_image_providers module

class runperf.utils.cloud_image_providers.BaseProvider(distro, arch, pub_key, base_path, session, setup_script)

Bases: object

Base provider to fetch and prepare a cloudinit image

get_url()

Return url to the base cloud image

static is_for(distro, arch)

Check whether this provider is valid for given combination

is_up_to_date()

Check whether base_path contains up-to-date distro of given arch

Parameters:
  • distro – Version, eg. (RHEL-8.0.0-20200408.n.0)
  • arch – Guest architecture (x86_64)
  • base_path – Basic path to store images (/var/lib/libvirt/images)
Returns:

None when up to date, explanation why not otherwise

prepare(default_password)

Prepare the image for use

class runperf.utils.cloud_image_providers.Fedora(distro, arch, pub_key, base_path, session, setup_script)

Bases: runperf.utils.cloud_image_providers.BaseProvider

Fedora image provider

get_url()

Return url to the base cloud image

static is_for(distro, arch)

Check whether this provider is valid for given combination

runperf.utils.pbench module

class runperf.utils.pbench.Dnf(session, extra=None, test=None)

Bases: object

Install pbench via “dnf” (Fedora/RHEL)

install()

Make sure pbench is installed and the default toolset is registered

runperf.utils.pbench.install_on(session, extra=None, test=None)

Try available providers to install pbench

Module contents

class runperf.utils.ThreadWithStatus(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)

Bases: threading.Thread

Thread class that sets “self.completed” to True after execution

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

completed = False
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

runperf.utils.check_output(*args, **kwargs)

Execute command while masking stdin and providing better errors.

Parameters:
  • args – args to be passed to subprocess.check_output
  • kwargs – kwargs to be passed to subprocess.check_output * when stdin is not present, devnull is used * when stderr is not present, subprocess.STDOUT is used
Raises:

RuntimeError – In case of subprocess.CalledProcessError

runperf.utils.comma_separated_ranges_to_list(text)

Provides a list from comma separated ranges

Parameters:text – string of comma separated range
Return list:list of integer values in comma separated range
runperf.utils.iter_tabular_output(matrix, header=None)

Generator for a pretty, aligned string representation of a nxm matrix.

This representation can be used to print any tabular data, such as database results. It works by scanning the lengths of each element in each column, and determining the format string dynamically.

Parameters:
  • matrix – Matrix representation (list with n rows of m elements).
  • header – Optional tuple or list with header elements to be displayed.
runperf.utils.list_of_threads(cpus)

How many threads to use depending on no cpus

runperf.utils.random_string(length)

Generates string of random characters

Parameters:length – number or characters to generate
runperf.utils.read_file(path)

Read a file and return it’s content or -1 in case the file does not exists

runperf.utils.shell_find_command(session, command)

Helper to detect path to a command

Parameters:
  • session – aexpect.ShellSession session
  • command – command we are looking for
Returns:

path or empty string when not found

runperf.utils.shell_write_content_cmd(path, content, append=False)

Generate shell cmd to safely write/append content to file

runperf.utils.ssh_copy_id(log, addr, passwords, hop=None)

Use “ssh-copy-id” to copy ssh id, try passwords if asked for.

runperf.utils.string_to_safe_path(input_str)

Convert string to a valid file/dir name.

This takes a string that may contain characters that are not allowed on FAT (Windows) filesystems and/or ext3 (Linux) filesystems, and replaces them for safe (boring) underlines.

It limits the size of the path to be under 255 chars, and make hidden paths (starting with “.”) non-hidden by making them start with “_”.

Parameters:input_str – String to be converted
Returns:String which is safe to pass as a file/dir name (on recent fs)
runperf.utils.tabular_output(matrix, header=None)

Pretty, aligned string representation of a nxm matrix.

This representation can be used to print any tabular data, such as database results. It works by scanning the lengths of each element in each column, and determining the format string dynamically.

Parameters:
  • matrix – Matrix representation (list with n rows of m elements)
  • header – Optional tuple or list with header elements to be displayed
Returns:

String with the tabular output, lines separated by unix line feeds

runperf.utils.wait_for(func, timeout, step=1.0, args=None, kwargs=None)

Wait until func() evaluates to True.

If func() evaluates to True before timeout expires, return the value of func(). Otherwise return None.

Parameters:
  • timeout – Timeout in seconds
  • first – Time to sleep before first attempt
  • step – Time to sleep between attempts in seconds
  • text – Text to print while waiting, for debug purposes
  • args – Positional arguments to func
  • kwargs – Keyword arguments to func
runperf.utils.wait_for_machine_calms_down(session, timeout=600)

Wait until 1m system load calms below 1.0

Parameters:
  • session – session
  • timeout – timeout
Returns:

True on success, False when it’s still busy

runperf.utils.write_file(path, content, mode='w')

Write content to path, create the necessary upper dirs