Welcome to labgridhelper’s documentation!¶
Labgridhelper provides utility functions for the labgrid library and labgrid testsuites.
It is meant to provide wrapper functions for commonly used functionality such as the retrieval of the system service status information.
Overview¶
Labgridhelper is separated into different submodules. These submodules are created for different stages of a device boot, i.e. the barebox submodules is used for the barebox bootloader and the linux submodule is used for a fully booted linux system.
Writing new helper functions¶
Helper functions usually use one of the protocols from labgrid to retrive data from the device, reformat the data and return it to be consumed in the test case. These functions should not perform test asserts, this should be done in the individual test cases, to separate data reformating from testing. Asserts however are needed to verify that the correct protocol is passed to the helper function. This is usually done by importing the protocol from labgrid and performing the assert in the beginning of the helper, i.e.:
def get_systemd_status(command):
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
This should ensure that the correct protocol is used and the helper function is used correctly in the test suite.
Helper functions should also contain a docstring to document its function for the user, i.e.:
def get_commands(command, directories=None):
"""Returns the commands of a running linux system
Args:
command (CommandProtocol): An instance of a Driver implementing the CommandProtocol
directories (list): An optional list of directories to include
Returns:
list: list of commands available under linux
"""
Modules¶
labgridhelper package¶
Submodules¶
labgridhelper.barebox module¶
-
labgridhelper.barebox.
get_commands
(command)[source]¶ Returns the available commands of a running Barebox bootloader
Parameters: command (BareboxDriver) – An instance of the BareboxDriver Returns: list of the available commands Return type: list
labgridhelper.linux module¶
-
labgridhelper.linux.
get_systemd_version
(command)[source]¶ Returns systemd version retrieved by parsing output of systemd –version
Parameters: command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol Returns: systemd version number Return type: int
-
labgridhelper.linux.
get_systemd_status
(command)[source]¶ Returns parsed output of systemd Manager’s ListUnits DBus command
Parameters: command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol Returns: dictionary of service names to their properties Return type: dict
-
labgridhelper.linux.
get_commands
(command, directories=None)[source]¶ Returns the commands of a running linux system
Parameters: - command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol
- directories (list) – An optional list of directories to include
Returns: list of commands available under linux
Return type: list
-
labgridhelper.linux.
get_systemd_service_active
(command, service)[source]¶ Returns True if service is active, False in all other cases
Parameters: - command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol
- service (str) – name of the service
Returns: True if service is active, False otherwise
Return type: bool
-
labgridhelper.linux.
get_interface_ip
(command, interface='eth0')[source]¶ Returns the global valid IPv4 address of the supplied interface
Parameters: - command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol
- interface (string) – name of the interface
Returns: IPv4 address of the interface, None otherwise
Return type: str
-
labgridhelper.linux.
get_hostname
(command)[source]¶ Returns the hostname
Parameters: command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol Returns: hostname of the target, None otherwise Return type: str
-
labgridhelper.linux.
systemd_unit_properties
(command, unit_properties, unit='')[source]¶ Yields the values of the properties of a unit
Parameters: - command (CommandProtocol) – An instance of a Driver implementing the CommandProtocol
- unit_properties (iterable) – Names of the properties of interest
- unit (str, optional) – The systemd unit of interest, defaults to empty (systemd manager itself)
Yields: str – Property value of the unit