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()

Parameters:
  • 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.
appliance_has_netapp()[source]
client_address()[source]
close()[source]
connect(hostname=None, **kwargs)[source]

See paramiko.SSHClient.connect

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

Creates a CPU spike of specific length and processes.

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

See SSHClient.run_command()

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

Patches a single file on the appliance

Parameters:
  • 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
Returns:

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

Note

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.

Parameters:
  • 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.
Returns:

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]
status

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.
uptime()[source]
username
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.

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

Bases: cfme.utils.ssh.SSHClient

lines_as_list()[source]

Return lines as list

raw_lines()[source]
raw_string()[source]
set_initial_file_end()[source]
cfme.utils.ssh.keygen()[source]

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