labgrid.util package

Submodules

labgrid.util.agent module

labgrid.util.agent.b2s(b)[source]
labgrid.util.agent.s2b(s)[source]
class labgrid.util.agent.Agent[source]

Bases: object

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

send(data)[source]
register(name, func)[source]
load(name, source)[source]
list()[source]
run()[source]
__dict__ = mappingproxy({'__module__': 'labgrid.util.agent', '__init__': <function Agent.__init__>, 'send': <function Agent.send>, 'register': <function Agent.register>, 'load': <function Agent.load>, 'list': <function Agent.list>, 'run': <function Agent.run>, '__dict__': <attribute '__dict__' of 'Agent' objects>, '__weakref__': <attribute '__weakref__' of 'Agent' objects>, '__doc__': None})
__module__ = 'labgrid.util.agent'
__weakref__

list of weak references to the object (if defined)

labgrid.util.agent.handle_test(*args, **kwargs)[source]
labgrid.util.agent.handle_error(message)[source]
labgrid.util.agent.handle_usbtmc(index, cmd, read=False)[source]
labgrid.util.agent.main()[source]

labgrid.util.agentwrapper module

labgrid.util.agentwrapper.b2s(b)[source]
labgrid.util.agentwrapper.s2b(s)[source]
exception labgrid.util.agentwrapper.AgentError[source]

Bases: Exception

__module__ = 'labgrid.util.agentwrapper'
__weakref__

list of weak references to the object (if defined)

exception labgrid.util.agentwrapper.AgentException[source]

Bases: Exception

__module__ = 'labgrid.util.agentwrapper'
__weakref__

list of weak references to the object (if defined)

class labgrid.util.agentwrapper.MethodProxy(wrapper, name)[source]

Bases: object

__init__(wrapper, name)[source]

Initialize self. See help(type(self)) for accurate signature.

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

Call self as a function.

__dict__ = mappingproxy({'__module__': 'labgrid.util.agentwrapper', '__init__': <function MethodProxy.__init__>, '__call__': <function MethodProxy.__call__>, '__dict__': <attribute '__dict__' of 'MethodProxy' objects>, '__weakref__': <attribute '__weakref__' of 'MethodProxy' objects>, '__doc__': None})
__module__ = 'labgrid.util.agentwrapper'
__weakref__

list of weak references to the object (if defined)

class labgrid.util.agentwrapper.ModuleProxy(wrapper, name)[source]

Bases: object

__init__(wrapper, name)[source]

Initialize self. See help(type(self)) for accurate signature.

__getattr__(name)[source]
__dict__ = mappingproxy({'__module__': 'labgrid.util.agentwrapper', '__init__': <function ModuleProxy.__init__>, '__getattr__': <function ModuleProxy.__getattr__>, '__dict__': <attribute '__dict__' of 'ModuleProxy' objects>, '__weakref__': <attribute '__weakref__' of 'ModuleProxy' objects>, '__doc__': None})
__module__ = 'labgrid.util.agentwrapper'
__weakref__

list of weak references to the object (if defined)

class labgrid.util.agentwrapper.AgentWrapper(host=None)[source]

Bases: object

__init__(host=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__del__()[source]
__getattr__(name)[source]
call(method, *args, **kwargs)[source]
__dict__ = mappingproxy({'__module__': 'labgrid.util.agentwrapper', '__init__': <function AgentWrapper.__init__>, '__del__': <function AgentWrapper.__del__>, '__getattr__': <function AgentWrapper.__getattr__>, 'call': <function AgentWrapper.call>, 'load': <function AgentWrapper.load>, 'close': <function AgentWrapper.close>, '__dict__': <attribute '__dict__' of 'AgentWrapper' objects>, '__weakref__': <attribute '__weakref__' of 'AgentWrapper' objects>, '__doc__': None})
__module__ = 'labgrid.util.agentwrapper'
__weakref__

list of weak references to the object (if defined)

load(name)[source]
close()[source]

labgrid.util.dict module

labgrid.util.dict.diff_dict(old, new)[source]

Compares old and new dictionaries, yielding for each difference (key, old_value, new_value). None is used for missing values.

labgrid.util.dict.flat_dict(d)[source]
labgrid.util.dict.filter_dict(d, cls, warn=False)[source]

Returns a copy a dictionary which only contains the attributes defined on an attrs class.

labgrid.util.exceptions module

exception labgrid.util.exceptions.NoValidDriverError(msg)[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__init__(msg) → None

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'labgrid.util.exceptions'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.util.expect module

class labgrid.util.expect.PtxExpect(driver, logfile=None, timeout=30, cwd=None)[source]

Bases: pexpect.pty_spawn.spawn

labgrid Wrapper of the pexpect module.

This class provides pexpect functionality for the ConsoleProtocol classes. driver: ConsoleProtocol object to be passed in

__init__(driver, logfile=None, timeout=30, cwd=None)[source]

Initializes a pexpect spawn instanse with required configuration

send(s)[source]

Write to underlying transport, return number of bytes written

read_nonblocking(size=1, timeout=-1)[source]

Pexpects needs a nonblocking read function, simply use pyserial with a timeout of 0

__module__ = 'labgrid.util.expect'

labgrid.util.helper module

labgrid.util.helper.get_free_port()[source]

Helper function to always return an unused port.

labgrid.util.helper.get_user()[source]

labgrid.util.managedfile module

class labgrid.util.managedfile.ManagedFile(local_path, resource, detect_nfs=True)[source]

Bases: object

The ManagedFile allows the synchronisation of a file to a remote host. It has to be created with the to be synced file and the target resource as argument:

::

from labgrid.util.managedfile import ManagedFile

ManagedFile(“/tmp/examplefile”, <your-resource>)

Synchronisation is done with the sync_to_resource method.

__attrs_post_init__()[source]
sync_to_resource()[source]

sync the file to the host specified in a resource

Raises

ExecutionError – if the SSH connection/copy fails

get_remote_path()[source]

Retrieve the remote file path

Returns

path to the file on the remote host

Return type

str

get_hash()[source]

Retrieve the hash of the file

Returns

SHA256 hexdigest of the file

Return type

str

__attrs_attrs__ = (Attribute(name='local_path', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=<function ManagedFile.<lambda>>, kw_only=False), Attribute(name='resource', default=NOTHING, validator=<instance_of validator for type <class 'labgrid.resource.common.Resource'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='detect_nfs', default=True, validator=<instance_of validator for type <class 'bool'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__dict__ = mappingproxy({'__module__': 'labgrid.util.managedfile', '__doc__': ' The ManagedFile allows the synchronisation of a file to a remote host.\n It has to be created with the to be synced file and the target resource as\n argument:\n\n ::\n from labgrid.util.managedfile import ManagedFile\n\n ManagedFile("/tmp/examplefile", <your-resource>)\n\n\n Synchronisation is done with the sync_to_resource method.\n ', '__attrs_post_init__': <function ManagedFile.__attrs_post_init__>, 'sync_to_resource': <function ManagedFile.sync_to_resource>, '_on_nfs': <function ManagedFile._on_nfs>, 'get_remote_path': <function ManagedFile.get_remote_path>, 'get_hash': <function ManagedFile.get_hash>, '__dict__': <attribute '__dict__' of 'ManagedFile' objects>, '__weakref__': <attribute '__weakref__' of 'ManagedFile' objects>, '__attrs_attrs__': (Attribute(name='local_path', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=<function ManagedFile.<lambda>>, kw_only=False), Attribute(name='resource', default=NOTHING, validator=<instance_of validator for type <class 'labgrid.resource.common.Resource'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='detect_nfs', default=True, validator=<instance_of validator for type <class 'bool'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False)), '__repr__': <function ManagedFile.__repr__>, '__eq__': <function ManagedFile.__eq__>, '__ne__': <function EthernetPortExport.__ne__>, '__lt__': <function ManagedFile.__lt__>, '__le__': <function ManagedFile.__le__>, '__gt__': <function ManagedFile.__gt__>, '__ge__': <function ManagedFile.__ge__>, '__hash__': None, '__init__': <function ManagedFile.__init__>})
__eq__(other)

Return self==value.

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__hash__ = None
__init__(local_path, resource, detect_nfs=True) → None

Initialize self. See help(type(self)) for accurate signature.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__module__ = 'labgrid.util.managedfile'
__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.util.marker module

labgrid.util.marker.gen_marker()[source]

labgrid.util.proxy module

labgrid.util.qmp module

class labgrid.util.qmp.QMPMonitor(monitor_out, monitor_in)[source]

Bases: object

__attrs_post_init__()[source]
execute(command)[source]
__attrs_attrs__ = (Attribute(name='monitor_out', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='monitor_in', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__dict__ = mappingproxy({'__module__': 'labgrid.util.qmp', '__attrs_post_init__': <function QMPMonitor.__attrs_post_init__>, '_negotiate_capabilities': <function QMPMonitor._negotiate_capabilities>, '_read_parse_json': <function QMPMonitor._read_parse_json>, 'execute': <function QMPMonitor.execute>, '__dict__': <attribute '__dict__' of 'QMPMonitor' objects>, '__weakref__': <attribute '__weakref__' of 'QMPMonitor' objects>, '__doc__': None, '__attrs_attrs__': (Attribute(name='monitor_out', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='monitor_in', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False)), '__repr__': <function QMPMonitor.__repr__>, '__init__': <function QMPMonitor.__init__>})
__init__(monitor_out, monitor_in) → None

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'labgrid.util.qmp'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

exception labgrid.util.qmp.QMPError(msg)[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__init__(msg) → None

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'labgrid.util.qmp'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.util.ssh module

class labgrid.util.ssh.SSHConnection(host)[source]

Bases: object

SSHConnections are individual connections to hosts managed by a control socket. In addition to command execution this class also provides an interface to manage port forwardings. These are used in the remote infrastructure to tunnel multiple connections over one SSH link.

A public identity infrastructure is assumed, no extra username or passwords are supported.

__attrs_post_init__()[source]
get_prefix()[source]
run(command, *, codec='utf-8', decodeerrors='strict', force_tty=False, stderr_merge=False, stderr_loglevel=None, stdout_loglevel=None)[source]

Run a command over the SSHConnection

Parameters
  • command (string) – The command to run

  • codec (string, optional) – output encoding. Defaults to “utf-8”.

  • decodeerrors (string, optional) – behavior on decode errors. Defaults to “strict”. Refer to stdtypes’ bytes.decode for details.

  • force_tty (bool, optional) – force allocate a tty (ssh -tt). Defaults to False

  • stderr_merge (bool, optional) – merge ssh subprocess stderr into stdout. Defaults to False.

  • stdout_loglevel (int, optional) – log stdout with specific log level as well. Defaults to None, i.e. don’t log.

  • stderr_loglevel (int, optional) – log stderr with specific log level as well. Defaults to None, i.e. don’t log.

Returns

(stdout, stderr, returncode)

run_check(command, *, codec='utf-8', decodeerrors='strict', force_tty=False, stderr_merge=False, stderr_loglevel=None, stdout_loglevel=None)[source]

Runs a command over the SSHConnection returns the output if successful, raises ExecutionError otherwise.

Except for the means of returning the value, this is equivalent to run.

Parameters
  • command (string) – The command to run

  • codec (string, optional) – output encoding. Defaults to “utf-8”.

  • decodeerrors (string, optional) – behavior on decode errors. Defaults to “strict”. Refer to stdtypes’ bytes.decode for details.

  • force_tty (bool, optional) – force allocate a tty (ssh -tt). Defaults to False

  • stderr_merge (bool, optional) – merge ssh subprocess stderr into stdout. Defaults to False.

  • stdout_loglevel (int, optional) – log stdout with specific log level as well. Defaults to None, i.e. don’t log.

  • stderr_loglevel (int, optional) – log stderr with specific log level as well. Defaults to None, i.e. don’t log.

Returns

stdout of the executed command if successful and

otherwise an ExecutionError Exception

Return type

List[str]

get_file(remote_file, local_file)[source]

Get a file from the remote host

put_file(local_file, remote_path)[source]

Put a file onto the remote host

add_port_forward(remote_host, remote_port)[source]

forward command

remove_port_forward(remote_host, remote_port)[source]

cancel command

connect()[source]
disconnect()[source]
isconnected()[source]
__attrs_attrs__ = (Attribute(name='host', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='_connected', default=False, validator=<instance_of validator for type <class 'bool'>>, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='_tmpdir', default=Factory(factory=<function SSHConnection.<lambda>>, takes_self=False), validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='_forwards', default=Factory(factory=<class 'dict'>, takes_self=False), validator=None, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__dict__ = mappingproxy({'__module__': 'labgrid.util.ssh', '__doc__': 'SSHConnections are individual connections to hosts managed by a control\n socket. In addition to command execution this class also provides an\n interface to manage port forwardings. These are used in the remote\n infrastructure to tunnel multiple connections over one SSH link.\n\n A public identity infrastructure is assumed, no extra username or passwords\n are supported.', '__attrs_post_init__': <function SSHConnection.__attrs_post_init__>, '_get_ssh_base_args': <staticmethod object>, '_get_ssh_control_args': <function SSHConnection._get_ssh_control_args>, '_get_ssh_args': <function SSHConnection._get_ssh_args>, '_open_connection': <function SSHConnection._open_connection>, '_run_socket_command': <function SSHConnection._run_socket_command>, '_check_connected': <function SSHConnection._check_connected>, 'get_prefix': <function SSHConnection.get_prefix>, 'run': <function SSHConnection.run>, 'run_check': <function SSHConnection.run_check>, 'get_file': <function SSHConnection.get_file>, 'put_file': <function SSHConnection.put_file>, 'add_port_forward': <function SSHConnection.add_port_forward>, 'remove_port_forward': <function SSHConnection.remove_port_forward>, 'connect': <function SSHConnection.connect>, 'disconnect': <function SSHConnection.disconnect>, 'isconnected': <function SSHConnection.isconnected>, '_check_external_master': <function SSHConnection._check_external_master>, '_start_own_master': <function SSHConnection._start_own_master>, '_stop_own_master': <function SSHConnection._stop_own_master>, '_start_keepalive': <function SSHConnection._start_keepalive>, '_check_keepalive': <function SSHConnection._check_keepalive>, '_stop_keepalive': <function SSHConnection._stop_keepalive>, '_disconnect': <function SSHConnection._disconnect>, '__dict__': <attribute '__dict__' of 'SSHConnection' objects>, '__weakref__': <attribute '__weakref__' of 'SSHConnection' objects>, '__attrs_attrs__': (Attribute(name='host', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='_connected', default=False, validator=<instance_of validator for type <class 'bool'>>, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='_tmpdir', default=Factory(factory=<function SSHConnection.<lambda>>, takes_self=False), validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='_forwards', default=Factory(factory=<class 'dict'>, takes_self=False), validator=None, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False)), '__repr__': <function SSHConnection.__repr__>, '__eq__': <function SSHConnection.__eq__>, '__ne__': <function EthernetPortExport.__ne__>, '__lt__': <function SSHConnection.__lt__>, '__le__': <function SSHConnection.__le__>, '__gt__': <function SSHConnection.__gt__>, '__ge__': <function SSHConnection.__ge__>, '__hash__': None, '__init__': <function SSHConnection.__init__>})
__eq__(other)

Return self==value.

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__hash__ = None
__init__(host) → None

Initialize self. See help(type(self)) for accurate signature.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__module__ = 'labgrid.util.ssh'
__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

exception labgrid.util.ssh.ForwardError(msg)[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__eq__(other)

Return self==value.

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__hash__ = None
__init__(msg) → None

Initialize self. See help(type(self)) for accurate signature.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__module__ = 'labgrid.util.ssh'
__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.util.timeout module

class labgrid.util.timeout.Timeout(timeout=120.0)[source]

Bases: object

Reperents a timeout (as a deadline)

__attrs_post_init__()[source]
property remaining
property expired
__attrs_attrs__ = (Attribute(name='timeout', default=120.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__dict__ = mappingproxy({'__module__': 'labgrid.util.timeout', '__doc__': 'Reperents a timeout (as a deadline)', '__attrs_post_init__': <function Timeout.__attrs_post_init__>, 'remaining': <property object>, 'expired': <property object>, '__dict__': <attribute '__dict__' of 'Timeout' objects>, '__weakref__': <attribute '__weakref__' of 'Timeout' objects>, '__attrs_attrs__': (Attribute(name='timeout', default=120.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),), '__repr__': <function Timeout.__repr__>, '__init__': <function Timeout.__init__>})
__init__(timeout=120.0) → None

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'labgrid.util.timeout'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.util.yaml module

labgrid.util.yaml.load(stream)[source]
labgrid.util.yaml.dump(data, stream=None)[source]
labgrid.util.yaml.resolve_templates(data, mapping)[source]

Iterate recursively over data and call substitute(mapping) on all Templates.