cfme.utils.ssh module

class cfme.utils.ssh.SSHClient(stream_output=False, **connect_kwargs)[source]

Bases: paramiko.client.SSHClient

paramiko.SSHClient wrapper

Allows copying/overriding and use as a context manager Constructor kwargs are handed directly to paramiko.SSHClient.connect()

  • container – If specified, then it is assumed that the VM hosts a container of CFME. The param then contains the name of the container.
  • is_pod – If specified and True, then it is assumed that the target is a podified openshift app and container then specifies the name of the pod to interact with.
  • stdout – If specified, overrides the system stdout file for streaming output.
  • stderr – If specified, overrides the system stderr file for streaming output.
connect(hostname=None, **kwargs)[source]

See paramiko.SSHClient.connect

cpu_spike(seconds=60, cpus=2, **kwargs)[source]

Creates a CPU spike of specific length and processes.

  • seconds – How long the spike should last.
  • cpus – How many processes to use.

See SSHClient.run_command()

get_file(remote_file, local_path='', **kwargs)[source]
get_transport(*args, **kwargs)[source]
open_sftp(*args, **kwargs)[source]
patch_file(local_path, remote_path, md5=None)[source]

Patches a single file on the appliance

  • local_path – Path to patch (diff) file
  • remote_path – Path to file to be patched (on the appliance)
  • md5 – MD5 checksum of the original file to check if it has changed

True if changes were applied, False if patching was not necessary


If there is a .bak file present and the file-to-be-patched was not patched by the current patch-file, it will be used to restore it first. Recompiling assets and restarting appropriate services might be required.

put_file(local_file, remote_file='.', **kwargs)[source]
run_command(command, timeout=1200.0, reraise=False, ensure_host=False, ensure_user=False)[source]

Run a command over SSH.

  • command – The command. Supports taking dicts as version picking.
  • timeout – Timeout after which the command execution fails.
  • reraise – Does not muffle the paramiko exceptions in the log.
  • ensure_host – Ensure that the command is run on the machine with the IP given, not any container or such that we might be using by default.
  • ensure_user – Ensure that the command is run as the user we logged in, so in case we are not root, setting this to True will prevent from running sudo.

A SSHResult instance.

run_rails_command(command, timeout=1200.0, **kwargs)[source]
run_rails_console(command, sandbox=False, timeout=1200.0)[source]

Runs Ruby inside of rails console. stderr is thrown away right now but could prove useful for future performance analysis of the queries rails runs. The command is encapsulated by double quotes. Sandbox rolls back all changes made to the database if used.

run_rake_command(command, timeout=1200.0, **kwargs)[source]

Parses the output of the systemctl status evmserverd.

Returns:A dictionary containing servers and workers, both lists. Each of the lists contains dictionaries, one per line. You can refer inside the dictionary using the headers.
class cfme.utils.ssh.SSHResult[source]

Bases: cfme.utils.ssh.SSHResult

Allows rich comparison for more convenient testing.

Given you have result which is an instance of SSHResult, you can do as follows

assert result  # If $?=0, then the result evaluates to a truthy value and passes the assert
assert result == 'installed'  # direct matching of the output value
assert 'something' in result  # like before but uses the ``in`` matching for a partial match
assert result == 5  # assert that the $?=5 (you can use <, >, ...)

Therefore this class can act like 3 kinds of values

  • Like a string (with the output of the command) when compared with or cast to one
  • Like a number (with the return code) when compared with or cast to one
  • Like a bool, giving truthy value if the return code was zero. That is related to the preceeding bullet.

But it still subclasses the original class therefore all old behaviour is kept. But you don’t have to expand the tuple or pull the value out if you are checking only one of them.

class cfme.utils.ssh.SSHTail(remote_filename, **connect_kwargs)[source]

Bases: cfme.utils.ssh.SSHClient


Return lines as list


Generate temporary ssh keypair for appliance SSH auth

Intended not only to simplify ssh access to appliances, but also to simplify SSH access from one appliance to another in multi-appliance setups