Source code for labgrid.strategy.bareboxstrategy

import enum

import attr

from ..factory import target_factory
from ..step import step
from .common import Strategy, StrategyError

[docs] class Status(enum.Enum): unknown = 0 off = 1 barebox = 2 shell = 3
[docs] @target_factory.reg_driver @attr.s(eq=False) class BareboxStrategy(Strategy): """BareboxStrategy - Strategy to switch to barebox or shell""" bindings = { "power": "PowerProtocol", "console": "ConsoleProtocol", "barebox": "BareboxDriver", "shell": "ShellDriver", } status = attr.ib(default=Status.unknown)
[docs] def __attrs_post_init__(self): super().__attrs_post_init__()
[docs] @step(args=['status']) def transition(self, status, *, step): # pylint: disable=redefined-outer-name if not isinstance(status, Status): status = Status[status] if status == Status.unknown: raise StrategyError(f"can not transition to {status}") elif status == self.status: step.skip("nothing to do") return # nothing to do elif status == elif status == Status.barebox: self.transition( # cycle power self.power.cycle() # interrupt barebox elif status == # transition to barebox self.transition(Status.barebox) self.barebox.boot("") self.barebox.await_boot()"systemctl is-system-running --wait") else: raise StrategyError( f"no transition found from {self.status} to {status}" ) self.status = status
[docs] @step(args=['status']) def force(self, status): if not isinstance(status, Status): status = Status[status] if status == Status.barebox: elif status == else: raise StrategyError("can not force state {}".format(status)) self.status = status