Skip to content

Commit 200de32

Browse files
Charles Shortportante
authored andcommitted
Pythonize pbench-register-tool-trigger
Replaced shell script with python script and make it installable. Signed-off-by: Charles Short <[email protected]>
1 parent dcb6ed2 commit 200de32

File tree

12 files changed

+192
-144
lines changed

12 files changed

+192
-144
lines changed

agent/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ util-scripts = \
4444
pbench-postprocess-tools-cdm \
4545
pbench-register-tool \
4646
pbench-register-tool-set \
47-
pbench-register-tool-trigger \
4847
pbench-send-tools \
4948
pbench-start-tools \
5049
pbench-stop-tools \
@@ -253,6 +252,7 @@ install-python3-setup: install-util-scripts install-lib
253252
${COPY} ${DESTDIR}/python3/bin/pbench-clear-results ${UTILDIR}/
254253
${COPY} ${DESTDIR}/python3/bin/pbench-cleanup ${UTILDIR}/
255254
${COPY} ${DESTDIR}/python3/bin/pbench-list-tools ${UTILDIR}/
255+
${COPY} ${DESTDIR}/python3/bin/pbench-register-tool-trigger ${UTILDIR}/
256256
rm -rf ${DESTDIR}/python3
257257
${COPY} ../lib/pbench ${LIBDIR}/
258258
rm -r $$(find ${LIBDIR} -name __pycache__) ${LIBDIR}/pbench/test ${LIBDIR}/pbench/server ${LIBDIR}/pbench/cli/server

agent/util-scripts/gold/pbench-register-tool-trigger/test-15.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

agent/util-scripts/gold/pbench-register-tool-trigger/test-35.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

agent/util-scripts/gold/pbench-register-tool-trigger/test-36.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

agent/util-scripts/pbench-register-tool-trigger

Lines changed: 0 additions & 99 deletions
This file was deleted.

agent/util-scripts/samples/pbench-register-tool-trigger/test-15/pbench/tools-v1-default/testhost.example.com/pidstat

Whitespace-only changes.

agent/util-scripts/samples/pbench-register-tool-trigger/test-35/pbench/tools-v1-default/testhost.example.com/pidstat

Whitespace-only changes.

agent/util-scripts/samples/pbench-register-tool-trigger/test-36/pbench/tools-v1-default/testhost.example.com/pidstat

Whitespace-only changes.

agent/util-scripts/unittests

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ declare -A tools=(
336336
[test-11.12]="pbench-register-tool-set"
337337
[test-11.13]="pbench-register-tool-set"
338338
[test-11.14]="pbench-register-tool-set"
339-
[test-15]="pbench-register-tool-trigger"
340339
[test-19]="test-tool-trigger"
341340
[test-20]="pbench-move-results"
342341
[test-21]="pbench-move-results"
@@ -353,8 +352,6 @@ declare -A tools=(
353352
[test-32]="pbench-copy-results"
354353
[test-33]="pbench-move-results"
355354
[test-34]="pbench-copy-results"
356-
[test-35]="pbench-register-tool-trigger"
357-
[test-36]="pbench-register-tool-trigger"
358355
[test-37]="pbench-copy-results"
359356
[test-38]="pbench-copy-results"
360357
[test-39]="pbench-copy-results"
@@ -422,7 +419,6 @@ declare -A options=(
422419
# verify --group option works along side --no-install
423420
[test-11.12]="--group=other --no-install"
424421
[test-11.13]="--help"
425-
[test-15]="--group=default --start-trigger=\"START DEFAULT\" --stop-trigger=\"STOP DEFAULT\""
426422
# pbench-move-results
427423
[test-20]="--help"
428424
# pbench-move-results - no args, nothing to do
@@ -444,8 +440,6 @@ declare -A options=(
444440
#[test-33]=""
445441
# pbench-copy-results - no args, 2 bad, 1 good result directory moved
446442
#[test-34]=""
447-
[test-35]="--group=default --start-trigger=\"START:DEFAULT\" --stop-trigger=\"STOP DEFAULT\""
448-
[test-36]="--group=default --start-trigger=\"START DEFAULT\" --stop-trigger=\"STOP:DEFAULT\""
449443
# pbench-copy-results - same controller specified as in metadata.log, no-op
450444
[test-37]="--controller=testhost.example.com"
451445
# pbench-copy-results - explicit controller different from recorded controller
@@ -484,8 +478,6 @@ declare -A expected_status=(
484478
[test-11.08]=1
485479
[test-11.11]=1
486480
[test-29]=1
487-
[test-35]=1
488-
[test-36]=1
489481
[test-44]=1
490482
[test-46]=1
491483
[test-47]=1
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"""
2+
pbench-register-tool-trigger
3+
4+
The sole purpose of this script is to register tool triggers for a given
5+
tool group of your choosing. During the execution of a benchmark, the
6+
output of the benchmark is used to trigger the starting of tools and the
7+
stopping of tools.
8+
9+
For a list of performance tools, look at the ${pbench_bin}/tool-scripts
10+
directory.
11+
12+
"""
13+
import logging
14+
import sys
15+
16+
import click
17+
18+
from pbench.agent.utils import setup_logging
19+
from pbench.cli.agent import CliContext, pass_cli_context
20+
from pbench.cli.agent.commands.triggers.base import TriggerCommand
21+
from pbench.cli.agent.options import common_options
22+
23+
LOG = logging.getLogger(__name__)
24+
25+
26+
class TriggerRegister(TriggerCommand):
27+
"""Register tool trigger"""
28+
29+
def __init__(self, context):
30+
super().__init__(context)
31+
32+
setup_logging(debug=False, logfile=None)
33+
34+
def execute(self):
35+
if self.verify_tool_group(self.context.group) != 0:
36+
return 1
37+
38+
if ":" in self.context.start:
39+
LOG.error(
40+
'%s: the start trigger cannot have a colon in it: "%s"',
41+
self.name,
42+
self.context.start,
43+
)
44+
return 1
45+
46+
if ":" in self.context.stop:
47+
LOG.error(
48+
'%s: the stop trigger cannot have a colon in it: "%s"',
49+
self.name,
50+
self.context.stop,
51+
)
52+
return 1
53+
54+
# Remember this trigger
55+
trigger = self.tool_group_dir / "__trigger__"
56+
trigger.write_text(f"{self.context.start}:{self.context.stop}\n")
57+
click.secho(
58+
f'tool trigger strings for start: "{self.context.start}" and for stop: "{self.context.stop}" are now registered for tool group: "{self.context.group}"'
59+
)
60+
61+
return 0
62+
63+
64+
def _group_option(f):
65+
"""Group option"""
66+
67+
def callback(ctxt, param, value):
68+
clictxt = ctxt.ensure_object(CliContext)
69+
clictxt.group = value
70+
return value
71+
72+
return click.option(
73+
"-g",
74+
"--groups",
75+
"--group",
76+
default="default",
77+
expose_value=False,
78+
callback=callback,
79+
)(f)
80+
81+
82+
def _start_option(f):
83+
def callback(ctxt, param, value):
84+
clictxt = ctxt.ensure_object(CliContext)
85+
clictxt.start = value
86+
return value
87+
88+
return click.option(
89+
"--start-trigger", required=True, expose_value=False, callback=callback,
90+
)(f)
91+
92+
93+
def _stop_option(f):
94+
def callback(ctxt, param, value):
95+
clictxt = ctxt.ensure_object(CliContext)
96+
clictxt.stop = value
97+
return value
98+
99+
return click.option(
100+
"--stop-trigger", required=True, expose_value=False, callback=callback,
101+
)(f)
102+
103+
104+
@click.command(help="list registered triggers")
105+
@common_options
106+
@_group_option
107+
@_start_option
108+
@_stop_option
109+
@pass_cli_context
110+
def main(ctxt):
111+
status = TriggerRegister(ctxt).execute()
112+
sys.exit(status)

0 commit comments

Comments
 (0)