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.
- project – openshift’s project which holds CFME pods
- 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.
-
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:
-
is_container
¶
-
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.
-
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_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.
-
status
¶ Parses the output of the
systemctl status evmserverd
.Returns: A dictionary containing servers
andworkers
, both lists. Each of the lists contains dictionaries, one per line. You can refer inside the dictionary using the headers.
-
username
¶
-
vmdb_version
¶
-
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 ofSSHResult
, you can do as followsassert 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