labgrid package

Subpackages

Submodules

labgrid.binding module

exception labgrid.binding.StateError(msg)[source]

Bases: Exception

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

Bases: Exception

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

Bases: enum.Enum

An enumeration.

error = -1
idle = 0
bound = 1
active = 2
class labgrid.binding.BindingMixin(target)[source]

Bases: object

Handles the binding and activation of drivers and their supplying resources and drivers.

One client can be bound to many suppliers, and one supplier can be bound by many clients.

Conflicting access to one supplier can be avoided by deactivating conflicting clients before activation (using the resolve_conflicts callback).

bindings = {}
target = Attribute(name='target', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))
state = Attribute(name='state', default=<BindingState.idle: 0>, validator=None, repr=True, cmp=True, hash=None, init=False, convert=None, metadata=mappingproxy({}))
on_supplier_bound(supplier, name)[source]

Called by the Target after a new supplier has been bound

on_client_bound(client)[source]

Called by the Target after a new client has been bound

on_activate()[source]

Called by the Target when this object has been activated

on_deactivate()[source]

Called by the Target when this object has been deactivated

resolve_conflicts(client)[source]

Called by the Target to allow this object to deactivate conflicting clients.

classmethod check_active(func)[source]

labgrid.config module

Config convenience class

This class encapsulates access functions to the environment configuration

class labgrid.config.Config(filename)[source]

Bases: object

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

Resolve an absolute path

Parameters:path (str) – path to resolve
Returns:the absolute path
Return type:str
get_tool(tool)[source]

Retrieve an entry from the tools subkey

Parameters:tool (str) – the tool to retrieve the path for
Returns:path to the requested tools
Return type:str
get_image_path(kind)[source]

Retrieve an entry from the images subkey

Parameters:kind (str) – the kind of the image to retrieve the path for
Returns:path to the image
Return type:str
Raises:KeyError – if the requested image can not be found in the configuration
get_path(kind)[source]

Retrieve an entry from the paths subkey

Parameters:kind (str) – the type of path to retrieve the path for
Returns:path to the path
Return type:str
Raises:KeyError – if the requested image can not be found in the configuration
get_option(name, default=None)[source]

Retrieve an entry from the options subkey

Parameters:
  • name (str) – name of the option
  • default (str) – A default parameter in case the option can not be found
Returns:

value of the option or default parameter

Return type:

str

Raises:

KeyError – if the requested image can not be found in the configuration

set_option(name, value)[source]

Set an entry in the options subkey

Parameters:
  • name (str) – name of the option
  • value (str) – the new value
get_targets()[source]
get_imports()[source]

Helper function that returns the list of all imports

Returns:List of files which should be imported
Return type:list
get_paths()[source]

Helper function that returns the subdict of all paths

Returns:Dictionary containing all path definitions
Return type:Dict
get_images()[source]

Helper function that returns the subdict of all images

Returns:Dictionary containing all image definitions
Return type:Dict

labgrid.environment module

class labgrid.environment.Environment(config_file='config.yaml', interact=<built-in function input>)[source]

Bases: object

An environment encapsulates targets.

config_file = Attribute(name='config_file', default='config.yaml', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))
interact = Attribute(name='interact', default=<built-in function input>, validator=None, repr=False, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))
get_target(role: str = 'main') → labgrid.target.Target[source]

Returns the specified target.

Each target is initialized as needed.

cleanup()[source]

labgrid.exceptions module

exception labgrid.exceptions.NoConfigFoundError(msg)[source]

Bases: Exception

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

Bases: Exception

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

Bases: labgrid.exceptions.NoSupplierFoundError

exception labgrid.exceptions.NoResourceFoundError(msg)[source]

Bases: labgrid.exceptions.NoSupplierFoundError

labgrid.factory module

class labgrid.factory.TargetFactory[source]

Bases: object

reg_resource(cls)[source]

Register a resource with the factory.

Returns the class to allow using it as a decorator.

reg_driver(cls)[source]

Register a driver with the factory.

Returns the class to allow using it as a decorator.

make_resource(target, resource, args)[source]
make_target(name, config, *, env=None)[source]
labgrid.factory.target_factory = <labgrid.factory.TargetFactory object>

Global TargetFactory instance

This instance is used to register Resource and Driver classes so that Targets can be created automatically from YAML files.

labgrid.step module

class labgrid.step.Steps[source]

Bases: object

get_current()[source]
get_new(title)[source]
push(step)[source]
pop(step)[source]
subscribe(callback)[source]
notify(event)[source]
class labgrid.step.StepEvent(step, data, *, resource=None, stream=False)[source]

Bases: object

merge(other)[source]
age
class labgrid.step.Step(title, level)[source]

Bases: object

duration
status
is_active
is_done
start()[source]
skip(reason)[source]
stop()[source]
labgrid.step.step(*, title=None, args=[], result=False)[source]

labgrid.stepreporter module

class labgrid.stepreporter.StepReporter[source]

Bases: object

instance = None
classmethod start()[source]
notify(event)[source]

labgrid.target module

class labgrid.target.Target(name, env=None)[source]

Bases: object

activate(client)[source]

Activate the client by activating all bound suppliers. This may require deactivating other clients.

await_resources(resources, timeout=None)[source]

Poll the given resources and wait until they are available.

bind(bindable)[source]
bind_driver(client)[source]

Bind the driver to all suppliers (resources and other drivers).

Currently, we only support binding all suppliers at once.

bind_resource(resource)[source]

Bind the resource to this target.

cleanup()[source]

Clean up conntected drivers and resources in reversed order

deactivate(client)[source]

Recursively deactivate the client’s clients and itself.

This is needed to ensure that no client has an inactive supplier.

env = Attribute(name='env', default=None, validator=None, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))
get_active_driver(cls)[source]

Helper function to get the active driver of the target. Returns the active driver found, otherwise None.

Arguments: cls – driver-class to return as a resource

get_driver(cls, *, activate=True)[source]

Helper function to get a driver of the target. Returns the first valid driver found, otherwise None.

Arguments: cls – driver-class to return as a resource activate – activate the driver (default True)

get_resource(cls, *, await=True)[source]

Helper function to get a resource of the target. Returns the first valid resource found, otherwise None.

Arguments: cls – resource-class to return as a resource await – wait for the resource to become available (default True)

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

Iterate over all relevant managers and deactivate any active but unavailable resources.