labgrid.driver package

Submodules

labgrid.driver.bareboxdriver module

class labgrid.driver.bareboxdriver.BareboxDriver(target, prompt='', autoboot='stop autoboot', interrupt='n')[source]

Bases: labgrid.driver.commandmixin.CommandMixin, labgrid.driver.common.Driver, labgrid.protocol.commandprotocol.CommandProtocol, labgrid.protocol.linuxbootprotocol.LinuxBootProtocol

BareboxDriver - Driver to control barebox via the console.
BareboxDriver binds on top of a ConsoleProtocol.
Parameters:prompt (str) – The default Barebox Prompt
bindings = {'console': <class 'labgrid.protocol.consoleprotocol.ConsoleProtocol'>}
prompt = Attribute(name='prompt', default='', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
autoboot = Attribute(name='autoboot', default='stop autoboot', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
interrupt = Attribute(name='interrupt', default='\n', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]

Activate the BareboxDriver

This function checks for a prompt and awaits it if not already active

on_deactivate()[source]

Deactivate the BareboxDriver

Simply sets the internal status to 0

run(cmd: str, *, step)[source]

Runs the specified command on the shell and returns the output.

Parameters:cmd (str) – command to run on the shell
Returns:if successful, None otherwise
Return type:Tuple[List[str],List[str], int]
run_check(cmd: str)[source]

Runs the specified command on the shell and returns the output if successful, raises ExecutionError otherwise.

Parameters:cmd (str) – command to run on the shell
Returns:stdout of the executed command
Return type:List[str]
get_status()[source]

Retrieve status of the BareboxDriver 0 means inactive, 1 means active.

Returns:status of the driver
Return type:int
await_boot()[source]

Wait for the initial Linux version string to verify we succesfully jumped into the kernel.

boot(name: str)[source]

Boot the default or a specific boot entry

Parameters:name (str) – name of the entry to boot

labgrid.driver.commandmixin module

class labgrid.driver.commandmixin.CommandMixin[source]

Bases: object

CommandMixin implementing common functions for drivers which support the CommandProtocol

wait_for(cmd, pattern, timeout=30.0, sleepduration=1)[source]

labgrid.driver.common module

class labgrid.driver.common.Driver(target)[source]

Bases: labgrid.binding.BindingMixin

Represents a driver which is used externally or by other drivers. It implements functionality based on directly accessing the Resource or by building on top of other Drivers.

Life cycle: - create - bind (n times) - activate - usage - deactivate

labgrid.driver.common.check_file(filename, *, command_prefix=[])[source]

labgrid.driver.consoleexpectmixin module

class labgrid.driver.consoleexpectmixin.ConsoleExpectMixin[source]

Bases: object

Console driver mixin to implement the read, write, expect and sendline methods. It uses the internal _read and _write methods.

The class using the ConsoleExpectMixin must provide a logger and a txdelay attribute.

read(size=1, timeout=0.0)[source]
write(data)[source]
sendline(line)[source]
sendcontrol(char)[source]
expect(pattern, timeout=-1)[source]
resolve_conflicts(client)[source]

labgrid.driver.exception module

exception labgrid.driver.exception.ExecutionError(msg)[source]

Bases: Exception

msg = Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
exception labgrid.driver.exception.CleanUpError(msg)[source]

Bases: Exception

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

labgrid.driver.externalconsoledriver module

class labgrid.driver.externalconsoledriver.ExternalConsoleDriver(target, cmd, txdelay=0.0)[source]

Bases: labgrid.driver.consoleexpectmixin.ConsoleExpectMixin, labgrid.driver.common.Driver, labgrid.protocol.consoleprotocol.ConsoleProtocol

Driver implementing the ConsoleProtocol interface using a subprocess

cmd = Attribute(name='cmd', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
txdelay = Attribute(name='txdelay', default=0.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
open()[source]

Starts the subprocess, does nothing if it is already closed

close()[source]

Stops the subprocess, does nothing if it is already closed

on_deactivate()[source]

labgrid.driver.fake module

class labgrid.driver.fake.FakeConsoleDriver(target, txdelay=0.0)[source]

Bases: labgrid.driver.consoleexpectmixin.ConsoleExpectMixin, labgrid.driver.common.Driver, labgrid.protocol.consoleprotocol.ConsoleProtocol

txdelay = Attribute(name='txdelay', default=0.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
open()[source]
close()[source]
class labgrid.driver.fake.FakeCommandDriver(target)[source]

Bases: labgrid.driver.commandmixin.CommandMixin, labgrid.driver.common.Driver, labgrid.protocol.commandprotocol.CommandProtocol

run(*args)[source]
run_check(*args)[source]
get_status()[source]
class labgrid.driver.fake.FakeFileTransferDriver(target)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.filetransferprotocol.FileTransferProtocol

get(*args)[source]
put(*args)[source]
class labgrid.driver.fake.FakePowerDriver(target)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.powerprotocol.PowerProtocol

on(*args)[source]
off(*args)[source]
cycle(*args)[source]

labgrid.driver.fastbootdriver module

class labgrid.driver.fastbootdriver.AndroidFastbootDriver(target, image=None)[source]

Bases: labgrid.driver.common.Driver

bindings = {'fastboot': {<class 'labgrid.resource.udev.AndroidFastboot'>, <class 'labgrid.resource.remote.NetworkAndroidFastboot'>}}
image = Attribute(name='image', default=None, validator=None, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]
on_deactivate()[source]
boot(filename)[source]
flash(partition, filename)[source]

labgrid.driver.infodriver module

class labgrid.driver.infodriver.InfoDriver(target)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.infoprotocol.InfoProtocol

InfoDriver implementing the InfoProtocol on top of CommandProtocol drivers

bindings = {'command': <class 'labgrid.protocol.commandprotocol.CommandProtocol'>}
get_ip(interface='eth0')[source]

Returns the IP of the supplied interface

get_service_status(service)[source]

Returns True if service is active, False in all other cases

get_hostname()[source]

labgrid.driver.onewiredriver module

class labgrid.driver.onewiredriver.OneWirePIODriver(target)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.digitaloutputprotocol.DigitalOutputProtocol

bindings = {'port': <class 'labgrid.resource.onewireport.OneWirePIO'>}
set(status)[source]
get()[source]

labgrid.driver.openocddriver module

class labgrid.driver.openocddriver.OpenOCDDriver(target, config, search=None, image=None)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.bootstrapprotocol.BootstrapProtocol

bindings = {'interface': {<class 'labgrid.resource.udev.AlteraUSBBlaster'>, <class 'labgrid.resource.remote.NetworkAlteraUSBBlaster'>}}
config = Attribute(name='config', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
search = Attribute(name='search', default=None, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
image = Attribute(name='image', default=None, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
load(filename=None)[source]

labgrid.driver.powerdriver module

class labgrid.driver.powerdriver.ManualPowerDriver(target, name)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.powerprotocol.PowerProtocol

ManualPowerDriver - Driver to tell the user to control a target’s power

name = Attribute(name='name', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on()[source]
off()[source]
cycle()[source]
class labgrid.driver.powerdriver.ExternalPowerDriver(target, cmd_on, cmd_off, cmd_cycle=None, delay=2.0)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.powerprotocol.PowerProtocol

ExternalPowerDriver - Driver using an external command to control a target’s power

cmd_on = Attribute(name='cmd_on', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
cmd_off = Attribute(name='cmd_off', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
cmd_cycle = Attribute(name='cmd_cycle', default=None, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
delay = Attribute(name='delay', default=2.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on()[source]
off()[source]
cycle()[source]
class labgrid.driver.powerdriver.NetworkPowerDriver(target, delay=2.0)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.powerprotocol.PowerProtocol

NetworkPowerDriver - Driver using a networked power switch to control a target’s power

bindings = {'port': <class 'labgrid.resource.power.NetworkPowerPort'>}
delay = Attribute(name='delay', default=2.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on()[source]
off()[source]
cycle()[source]
get()[source]
class labgrid.driver.powerdriver.DigitalOutputPowerDriver(target, cmd_on, cmd_off, delay=1.0)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.powerprotocol.PowerProtocol

DigitalOutputPowerDriver - Driver using a DigitalOutput to reset the target and subprocesses to turn it on and off

bindings = {'output': <class 'labgrid.protocol.digitaloutputprotocol.DigitalOutputProtocol'>}
cmd_on = Attribute(name='cmd_on', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
cmd_off = Attribute(name='cmd_off', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
delay = Attribute(name='delay', default=1.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on()[source]
off()[source]
cycle()[source]
get()[source]

labgrid.driver.serialdriver module

class labgrid.driver.serialdriver.SerialDriver(target, txdelay=0.0)[source]

Bases: labgrid.driver.consoleexpectmixin.ConsoleExpectMixin, labgrid.driver.common.Driver, labgrid.protocol.consoleprotocol.ConsoleProtocol

Driver implementing the ConsoleProtocol interface over a SerialPort connection

bindings = {'port': {<class 'labgrid.resource.base.SerialPort'>, <class 'labgrid.resource.serialport.NetworkSerialPort'>}}
txdelay = Attribute(name='txdelay', default=0.0, validator=<instance_of validator for type <class 'float'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]
open()[source]

Opens the serialport, does nothing if it is already closed

close()[source]

Closes the serialport, does nothing if it is already closed

labgrid.driver.shelldriver module

The ShellDriver provides the CommandProtocol, ConsoleProtocol and InfoProtocol on top of a SerialPort.

class labgrid.driver.shelldriver.ShellDriver(target, prompt, login_prompt, username, password='', keyfile='')[source]

Bases: labgrid.driver.commandmixin.CommandMixin, labgrid.driver.common.Driver, labgrid.protocol.commandprotocol.CommandProtocol

ShellDriver - Driver to execute commands on the shell ShellDriver binds on top of a ConsoleProtocol.

Parameters:
  • prompt (regex) – The Linux Prompt to detect
  • login_prompt (regex) – The Login Prompt to detect
  • username (str) – username to login with
  • password (str) – password to login with
  • keyfile (str) – keyfile to bind mount over users authorized keys
bindings = {'console': <class 'labgrid.protocol.consoleprotocol.ConsoleProtocol'>}
prompt = Attribute(name='prompt', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
login_prompt = Attribute(name='login_prompt', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
username = Attribute(name='username', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
password = Attribute(name='password', default='', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
keyfile = Attribute(name='keyfile', default='', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]
on_deactivate()[source]
run(cmd, timeout=30.0)[source]
run_check(cmd, timeout=30)[source]

Runs the specified cmd on the shell and returns the output if successful, raises ExecutionError otherwise.

Arguments: cmd - cmd to run on the shell

get_status()[source]

Returns the status of the shell-driver. 0 means not connected/found, 1 means shell

put_ssh_key(key)[source]

labgrid.driver.sshdriver module

The SSHDriver uses SSH as a transport to implement CommandProtocol and FileTransferProtocol

class labgrid.driver.sshdriver.SSHDriver(target, keyfile='')[source]

Bases: labgrid.driver.commandmixin.CommandMixin, labgrid.driver.common.Driver, labgrid.protocol.commandprotocol.CommandProtocol, labgrid.protocol.filetransferprotocol.FileTransferProtocol

SSHDriver - Driver to execute commands via SSH

bindings = {'networkservice': <class 'labgrid.resource.networkservice.NetworkService'>}
keyfile = Attribute(name='keyfile', default='', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]
on_deactivate()[source]
run(cmd)[source]

Execute cmd on the target.

This method runs the specified cmd as a command on its target. It uses the ssh shell command to run the command and parses the exitcode. cmd - command to be run on the target

returns: (stdout, stderr, returncode)

run_check(cmd)[source]

Runs the specified cmd on the shell and returns the output if successful, raises ExecutionError otherwise.

Arguments: cmd - cmd to run on the shell

get_status()[source]

The SSHDriver is always connected, return 1

put(filename, remotepath=None)[source]
get(filename, destination='.')[source]

labgrid.driver.ubootdriver module

The U-Boot Module contains the UBootDriver

class labgrid.driver.ubootdriver.UBootDriver(target, prompt='', password='', init_commands=NOTHING)[source]

Bases: labgrid.driver.commandmixin.CommandMixin, labgrid.driver.common.Driver, labgrid.protocol.commandprotocol.CommandProtocol, labgrid.protocol.linuxbootprotocol.LinuxBootProtocol

UBootDriver - Driver to control uboot via the console. UBootDriver binds on top of a ConsoleProtocol.

Parameters:
  • prompt (str) – The default UBoot Prompt
  • password (str) – optional password to unlock UBoot
  • init_commands (Tuple[str]) – a tuple of commands to run after unlock
bindings = {'console': <class 'labgrid.protocol.consoleprotocol.ConsoleProtocol'>}
prompt = Attribute(name='prompt', default='', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
password = Attribute(name='password', default='', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
init_commands = Attribute(name='init_commands', default=Factory(factory=<class 'tuple'>), validator=None, repr=True, cmp=True, hash=True, init=True, convert=<class 'tuple'>, metadata=mappingproxy({}))
on_activate()[source]

Activate the UBootDriver

This function checks for a prompt and awaits it if not already active

on_deactivate()[source]

Deactivate the UBootDriver

Simply sets the internal status to 0

run(cmd)[source]

Runs the specified command on the shell and returns the output.

Parameters:cmd (str) – command to run on the shell
Returns:if successful, None otherwise
Return type:Tuple[List[str],List[str], int]
run_check(cmd)[source]

Runs the specified command on the shell and returns the output if successful, raises ExecutionError otherwise.

Parameters:cmd (str) – command to run on the shell
Returns:stdout of the executed command
Return type:List[str]
get_status()[source]

Retrieve status of the UBootDriver. 0 means inactive, 1 means active.

Returns:status of the driver
Return type:int
await_boot()[source]

Wait for the initial Linux version string to verify we succesfully jumped into the kernel.

boot(name)[source]

Boot the default or a specific boot entry

Parameters:name (str) – name of the entry to boot

labgrid.driver.usbloader module

class labgrid.driver.usbloader.MXSUSBDriver(target, image=None)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.bootstrapprotocol.BootstrapProtocol

bindings = {'loader': {<class 'labgrid.resource.udev.MXSUSBLoader'>, <class 'labgrid.resource.remote.NetworkMXSUSBLoader'>}}
image = Attribute(name='image', default=None, validator=None, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]
on_deactivate()[source]
load(filename=None)[source]
class labgrid.driver.usbloader.IMXUSBDriver(target, image=None)[source]

Bases: labgrid.driver.common.Driver, labgrid.protocol.bootstrapprotocol.BootstrapProtocol

bindings = {'loader': {<class 'labgrid.resource.udev.IMXUSBLoader'>, <class 'labgrid.resource.remote.NetworkIMXUSBLoader'>}}
image = Attribute(name='image', default=None, validator=None, repr=True, cmp=True, hash=True, init=True, convert=None, metadata=mappingproxy({}))
on_activate()[source]
on_deactivate()[source]
load(filename=None)[source]

labgrid.driver.usbstorage module

class labgrid.driver.usbstorage.USBStorageDriver(target)[source]

Bases: labgrid.driver.common.Driver

bindings = {'storage': <class 'labgrid.resource.udev.USBMassStorage'>}
on_activate()[source]
on_deactivate()[source]
write_image(filename)[source]
get_size()[source]