Skip to content

Commit 1eb0844

Browse files
doc: configuration: add example configs for strategies, test via doctest
Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent 2c4f25f commit 1eb0844

1 file changed

Lines changed: 114 additions & 18 deletions

File tree

doc/configuration.rst

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,19 +2623,44 @@ A BareboxStrategy has four states:
26232623
- barebox
26242624
- shell
26252625

2626+
Here is an example environment config:
26262627

2627-
to transition to the shell state:
2628+
.. code-block:: yaml
2629+
:name: barebox-env.yaml
26282630
2629-
::
2631+
targets:
2632+
main:
2633+
resources:
2634+
RawSerialPort:
2635+
port: '/dev/ttyUSB0'
2636+
drivers:
2637+
ManualPowerDriver: {}
2638+
SerialDriver: {}
2639+
BareboxDriver: {}
2640+
ShellDriver:
2641+
prompt: 'root@\w+:[^ ]+ '
2642+
login_prompt: ' login: '
2643+
username: root
2644+
BareboxStrategy: {}
2645+
2646+
In order to use the BareboxStrategy via labgrid as a library and transition to
2647+
the ``shell`` state:
2648+
2649+
.. testsetup:: barebox-strategy
2650+
2651+
from labgrid.strategy import BareboxStrategy
2652+
2653+
BareboxStrategy.transition = Mock(return_value=None)
2654+
2655+
.. doctest:: barebox-strategy
26302656

26312657
>>> from labgrid import Environment
2632-
>>> e = Environment("local.yaml")
2658+
>>> e = Environment("barebox-env.yaml")
26332659
>>> t = e.get_target("main")
26342660
>>> s = t.get_driver("BareboxStrategy")
26352661
>>> s.transition("shell")
26362662

2637-
2638-
this command would transition from the bootloader into a Linux shell and
2663+
This command would transition from the bootloader into a Linux shell and
26392664
activate the ShellDriver.
26402665

26412666
ShellStrategy
@@ -2646,19 +2671,42 @@ A ShellStrategy has three states:
26462671
- off
26472672
- shell
26482673

2674+
Here is an example environment config:
26492675

2650-
to transition to the shell state:
2676+
.. code-block:: yaml
2677+
:name: shell-env.yaml
26512678
2652-
::
2679+
targets:
2680+
main:
2681+
resources:
2682+
RawSerialPort:
2683+
port: '/dev/ttyUSB0'
2684+
drivers:
2685+
ManualPowerDriver: {}
2686+
SerialDriver: {}
2687+
ShellDriver:
2688+
prompt: 'root@\w+:[^ ]+ '
2689+
login_prompt: ' login: '
2690+
username: root
2691+
ShellStrategy: {}
2692+
2693+
In order to use the ShellStrategy via labgrid as a library and transition to
2694+
the ``shell`` state:
2695+
2696+
.. testsetup:: shell-strategy
2697+
2698+
from labgrid.strategy import ShellStrategy
2699+
2700+
ShellStrategy.transition = Mock(return_value=None)
2701+
2702+
.. doctest:: shell-strategy
26532703

26542704
>>> from labgrid import Environment
2655-
>>> e = Environment("local.yaml")
2705+
>>> e = Environment("shell-env.yaml")
26562706
>>> t = e.get_target("main")
26572707
>>> s = t.get_driver("ShellStrategy")
2658-
>>> s.transition("shell")
26592708

2660-
2661-
this command would transition directly into a Linux shell and
2709+
This command would transition directly into a Linux shell and
26622710
activate the ShellDriver.
26632711

26642712
UBootStrategy
@@ -2670,19 +2718,44 @@ A UBootStrategy has four states:
26702718
- uboot
26712719
- shell
26722720

2721+
Here is an example environment config:
26732722

2674-
to transition to the shell state:
2723+
.. code-block:: yaml
2724+
:name: uboot-env.yaml
26752725
2676-
::
2726+
targets:
2727+
main:
2728+
resources:
2729+
RawSerialPort:
2730+
port: '/dev/ttyUSB0'
2731+
drivers:
2732+
ManualPowerDriver: {}
2733+
SerialDriver: {}
2734+
UBootDriver: {}
2735+
ShellDriver:
2736+
prompt: 'root@\w+:[^ ]+ '
2737+
login_prompt: ' login: '
2738+
username: root
2739+
UBootStrategy: {}
2740+
2741+
In order to use the UBootStrategy via labgrid as a library and transition to
2742+
the ``shell`` state:
2743+
2744+
.. testsetup:: uboot-strategy
2745+
2746+
from labgrid.strategy import UBootStrategy
2747+
2748+
UBootStrategy.transition = Mock(return_value=None)
2749+
2750+
.. doctest:: uboot-strategy
26772751

26782752
>>> from labgrid import Environment
2679-
>>> e = Environment("local.yaml")
2753+
>>> e = Environment("uboot-env.yaml")
26802754
>>> t = e.get_target("main")
26812755
>>> s = t.get_driver("UBootStrategy")
26822756
>>> s.transition("shell")
26832757

2684-
2685-
this command would transition from the bootloader into a Linux shell and
2758+
This command would transition from the bootloader into a Linux shell and
26862759
activate the ShellDriver.
26872760

26882761
DockerStrategy
@@ -2693,14 +2766,37 @@ A DockerStrategy has three states:
26932766
- gone
26942767
- accessible
26952768

2769+
Here is an example environment config:
2770+
2771+
.. code-block:: yaml
2772+
:name: docker-env.yaml
2773+
2774+
targets:
2775+
main:
2776+
resources:
2777+
DockerDaemon:
2778+
docker_daemon_url: unix://var/run/docker.sock
2779+
drivers:
2780+
DockerDriver:
2781+
image_uri: "rastasheep/ubuntu-sshd:16.04"
2782+
container_name: "ubuntu-lg-example"
2783+
host_config: {"network_mode":"bridge"}
2784+
network_services: [{"port":22,"username":"root","password":"root"}]
2785+
DockerStrategy: {}
26962786
26972787
In order to use the DockerStrategy via labgrid as a library and transition to
26982788
the ``accessible`` state:
26992789

2700-
::
2790+
.. testsetup:: docker-strategy
2791+
2792+
from labgrid.strategy import DockerStrategy
2793+
2794+
DockerStrategy.transition = Mock(return_value=None)
2795+
2796+
.. doctest:: docker-strategy
27012797

27022798
>>> from labgrid import Environment
2703-
>>> e = Environment("local.yaml")
2799+
>>> e = Environment("docker-env.yaml")
27042800
>>> t = e.get_target("main")
27052801
>>> s = t.get_driver("DockerStrategy")
27062802
>>> s.transition("accessible")

0 commit comments

Comments
 (0)