Source code for labgrid.strategy.shellstrategy

import enum

import attr

from ..driver import ShellDriver
from ..factory import target_factory
from ..protocol import PowerProtocol
from ..step import step
from .common import Strategy, StrategyError

[docs]class Status(enum.Enum): unknown = 0 off = 1 shell = 2
[docs]@target_factory.reg_driver @attr.s(cmp=False) class ShellStrategy(Strategy): """ShellStrategy - Strategy to switch to shell""" bindings = { "power": PowerProtocol, "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): if not isinstance(status, Status): status = Status[status] if status == Status.unknown: raise StrategyError("can not transition to {}".format(status)) elif status == self.status: step.skip("nothing to do") return # nothing to do elif status == elif status == self.transition( # pylint: disable=missing-kwoa self.power.cycle() else: raise StrategyError( "no transition found from {} to {}". format(self.status, status) ) self.status = status