Skip to content

Commit e45780b

Browse files
committed
remote/client: Provide a way to set the strategy end-state
It is possible to set the initial state of a strategy, but not the final state. In many cases we want to power the board off and otherwise clean things up at the end. Provide a -e option to accomplish this. Signed-off-by: Simon Glass <sjg@chromium.org>
1 parent b00baf0 commit e45780b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

labgrid/remote/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,12 @@ def set_initial_state(self, target):
884884
logging.info("Transitioning into state %s", self.args.state)
885885
strategy.transition(self.args.state)
886886

887+
def set_end_state(self, target):
888+
if self.args.end_state:
889+
strategy = target.get_driver("Strategy")
890+
logging.info("Transitioning into state %s", self.args.end_state)
891+
strategy.transition(self.args.end_state)
892+
887893
def _get_target(self, place):
888894
self._prepare_manager()
889895
target = None
@@ -1882,6 +1888,7 @@ def get_parser(auto_doc_mode=False) -> "argparse.ArgumentParser | AutoProgramArg
18821888
type=str,
18831889
help="strategy state to force into before switching to desired state",
18841890
)
1891+
parser.add_argument("-e", "--end-state", type=str, help="strategy state to switch into after command")
18851892
parser.add_argument(
18861893
"-d", "--debug", action="store_true", default=False, help="enable debug mode (show python tracebacks)"
18871894
)
@@ -2274,6 +2281,7 @@ def main():
22742281
place = os.environ.get("LG_PLACE", place)
22752282
state = os.environ.get("STATE", None)
22762283
state = os.environ.get("LG_STATE", state)
2284+
end_state = os.environ.get("LG_END_STATE", state)
22772285
initial_state = os.environ.get("LG_INITIAL_STATE", None)
22782286
token = os.environ.get("LG_TOKEN", None)
22792287

@@ -2299,6 +2307,9 @@ def main():
22992307
if args.initial_state is None:
23002308
args.initial_state = initial_state
23012309

2310+
if args.end_state is None:
2311+
args.end_state = end_state
2312+
23022313
if args.command in ["cancel-reservation", "wait"] and args.token is None:
23032314
if token:
23042315
args.token = token
@@ -2370,6 +2381,7 @@ def main():
23702381
try:
23712382
if inspect.iscoroutinefunction(args.func):
23722383
auto_release = False
2384+
target = None
23732385
if getattr(args.func, "needs_target", False):
23742386
if args.acquire:
23752387
place = session.get_place(args.place)
@@ -2384,6 +2396,7 @@ def main():
23842396
else:
23852397
coro = args.func(session)
23862398
session.loop.run_until_complete(coro)
2399+
session.set_end_state(target)
23872400
if auto_release:
23882401
coro = session.release()
23892402
session.loop.run_until_complete(coro)

man/labgrid-client.1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This is the client to control a boards status and interface with it on remote ma
4040
.sp
4141
.EX
4242
usage: labgrid\-client [\-x ADDRESS] [\-c CONFIG] [\-p PLACE] [\-s STATE] [\-a]
43-
[\-i INITIAL_STATE] [\-d] [\-v] [\-P PROXY]
43+
[\-i INITIAL_STATE] [\-e END_STATE] [\-d] [\-v] [\-P PROXY]
4444
COMMAND ...
4545
.EE
4646
.UNINDENT
@@ -77,6 +77,11 @@ strategy state to force into before switching to desired state
7777
.UNINDENT
7878
.INDENT 0.0
7979
.TP
80+
.B \-e <end_state>, \-\-end\-state <end_state>
81+
strategy state to switch into after command
82+
.UNINDENT
83+
.INDENT 0.0
84+
.TP
8085
.B \-d, \-\-debug
8186
enable debug mode (show python tracebacks)
8287
.UNINDENT

0 commit comments

Comments
 (0)