Wrapper

This package contains the wrappers to submit and execute jobs.

RemoteWrapper is the main Wrapper. LocalWrapper inherits from it but runs in the same machine that submitts the jobs.

RemoteWrapper

Provides a wrapper around Paramiko to simplify the API.

This module is meant to be a general wrapper so other wrappers can also be created to run tests in continuous integration services where SSH is not available.

class django_remote_submission.wrapper.remote.RemoteWrapper(hostname, username, port=22)[source]

Wrapper around Paramiko which simplifies the remote connection API.

__init__(hostname, username, port=22)[source]

Initialize the wrapper.

Parameters:
  • hostname (str) – the hostname of the server to connect to
  • username (str) – the username of the user on the remote server
  • port (int) – the SSH port to connect to
deploy_key_if_it_does_not_exist()[source]

Deploy our public key to the remote server.

Parameters:
This can be called as:
key = os.path.expanduser(‘~/.ssh/id_rsa.pub’) wrapper = RemoteWrapper(hostname=server.hostname, username=username) wrapper.connect(password) wrapper.deploy_key_if_it_does_not_exist() wrapper.close()
delete_key()[source]

Delete the server’s public key from remote host.

For example:

wrapper = RemoteWrapper(hostname, username)
with wrapper.connect(password, public_key_filename):
    wrapper.delete_key()
connect(password=None, public_key_filename=None)[source]

Connect to the remote host with the given password and public key.

Meant to be used like:

with wrapper.connect(password='password0'):
    pass
Parameters:
  • password (str) – the password of the user on the remote server
  • public_key_filename (str) – the file containing the public key
close()[source]

Close any open connections and clear their attributes.

chdir(remote_directory)[source]

Change directories to the remote directory.

Parameters:remote_directory (str) – the directory to change to
open(filename, mode)[source]

Open a file from the last used remote directory.

Parameters:
  • filename (str) – the name of the file to open
  • mode (str) – the mode to use to open the file (see file()’s documentation for more information)
listdir_attr()[source]

Retrieve a list of files and their attributes.

Each object is guaranteed to have a filename attribute as well as an st_mtime attribute, which gives the last modified time in seconds.

exec_command(args, workdir, timeout=None, stdout_handler=None, stderr_handler=None)[source]

Execute a command on the remote server.

An example of how to use this function:

from datetime import timedelta
wrapper.exec_command(
    args=["ls", "-la", "."],
    workdir="/",
    timeout=timedelta(minute=5),
    stdout_handler=lambda now, output: print('stdout, now, output),
    stderr_handler=lambda now, output: print('stderr, now, output),
)
Parameters:
  • args (list(str)) – the command and arguments to run
  • workdir (str) – the directory to run the commands from
  • timeout (datetime.timedelta) – the timeout to use for the command
  • stdout_handler – a function that accepts now and output parameters and is called when new output appears on stdout.
  • stderr_handler – a function that accepts now and output parameters and is called when new output appears on stderr.
deploy_key_if_it_does_not_exist()[source]

Deploy our public key to the remote server.

Parameters:
This can be called as:
key = os.path.expanduser(‘~/.ssh/id_rsa.pub’) wrapper = RemoteWrapper(hostname=server.hostname, username=username) wrapper.connect(password) wrapper.deploy_key_if_it_does_not_exist() wrapper.close()
delete_key()[source]

Delete the server’s public key from remote host.

For example:

wrapper = RemoteWrapper(hostname, username)
with wrapper.connect(password, public_key_filename):
    wrapper.delete_key()

LocalWrapper

Provides a Local Wrapper to run the commands in the local machine without the need of a sshd server.

The goal with this class is to also be able to provide a LocalWrapper which works with the local file system, so that tests can be run on continuous integration servers.

class django_remote_submission.wrapper.local.LocalWrapper(*args, **kwargs)[source]

This class extends and modify the functionality of the RemoteWrapper. It has the same functionality but does not perform any SSH connections.

connect(*args, **kwargs)[source]

Connect to the remote host with the given password and public key.

Meant to be used like:

with wrapper.connect(password='password0'):
    pass
Parameters:
  • password (str) – the password of the user on the remote server
  • public_key_filename (str) – the file containing the public key
close(*args, **kwargs)[source]

Close any open connections and clear their attributes.

chdir(remote_directory)[source]

Change directories to the remote directory.

Parameters:remote_directory (str) – the directory to change to
open(filename, mode)[source]

Open a file from the last used remote directory.

Parameters:
  • filename (str) – the name of the file to open
  • mode (str) – the mode to use to open the file (see file()’s documentation for more information)
listdir_attr()[source]

Retrieve a list of files and their attributes.

Each object is guaranteed to have a filename attribute as well as an st_mtime attribute, which gives the last modified time in seconds.

exec_command(args, workdir, timeout=None, stdout_handler=None, stderr_handler=None)[source]

Altouhgh Log.LIVE is possible, the Local does not support True Live Log. In local for large outputs, it looks like stdXXX_handle takes too long and the buffer of the process over runs and the log gets truncated