Skip to content

Commit 761445c

Browse files
committed
Separate pbench-config and pbench-server-config
1 parent 87d739a commit 761445c

File tree

6 files changed

+53
-40
lines changed

6 files changed

+53
-40
lines changed

lib/pbench/cli/agent/commands/conf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import sys
3+
4+
from pbench.common.conf import common_main
5+
6+
7+
def main():
8+
sys.exit(common_main(os.path.basename(sys.argv[0]), "_PBENCH_AGENT_CONFIG"))
9+
10+
11+
if __name__ == "__main__":
12+
main()

lib/pbench/cli/server/conf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import sys
3+
4+
from pbench.common.conf import common_main
5+
6+
7+
def main():
8+
sys.exit(common_main(os.path.basename(sys.argv[0]), "_PBENCH_SERVER_CONFIG"))
9+
10+
11+
if __name__ == "__main__":
12+
main()

lib/pbench/common/conf.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
1-
import os
2-
import sys
3-
41
from pbench.common import configtools
52

63

7-
def get_pbench_config():
8-
"""Determine if we are using agent or server."""
9-
agent_cfg = os.environ.get("_PBENCH_AGENT_CONFIG")
10-
server_cfg = os.environ.get("_PBENCH_SERVER_CONFIG")
11-
if agent_cfg:
12-
return "_PBENCH_AGENT_CONFIG"
13-
elif server_cfg:
14-
return "_PBENCH_SERVER_CONFIG"
15-
else:
16-
return sys.exit(1)
4+
def common_main(prog: str, env: str):
5+
"""Common entry point for agent and server pbench-config commands.
176
7+
Args:
8+
prog : invocation program name to use in Usage message
9+
env : environment variable for configuration file
1810
19-
def main():
20-
prog = os.path.basename(sys.argv[0])
11+
Returns:
12+
Pass through of return code from `configtools.main`
13+
"""
2114
opts, args = configtools.parse_args(
2215
configtools.options,
2316
usage=f"Usage: {prog} [options] <item>|-a <section> [<section> ...]",
2417
)
25-
conf, files = configtools.init(opts, get_pbench_config())
26-
status = configtools.main(conf, args, opts, files)
27-
sys.exit(status)
28-
29-
30-
if __name__ == "__main__":
31-
main()
18+
conf, files = configtools.init(opts, env)
19+
return configtools.main(conf, args, opts, files)

server/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ install-python3-setup: install-bin install-lib
5151
mkdir -p ${DESTDIR}/python3
5252
${COPY} requirements.txt ${DESTDIR}
5353
(cd ..; /usr/bin/python3 -m pip install --prefix=${DESTDIR}/python3 -e .)
54-
${COPY} $(addprefix ${DESTDIR}/python3/bin/, pbench-config pbench-server ${click-scripts}) ${BINDIR}/
54+
${COPY} $(addprefix ${DESTDIR}/python3/bin/, pbench-server-config pbench-server ${click-scripts}) ${BINDIR}/
5555
${RM} -r ${DESTDIR}/python3
5656
${COPY} ../lib/pbench ${LIBDIR}/
5757
${RM} -r $$(find ${LIBDIR} -name __pycache__) ${LIBDIR}/pbench/test ${LIBDIR}/pbench/agent ${LIBDIR}/pbench/cli/agent

server/bin/pbench-create-crontab

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ if [ ! -f "$_PBENCH_SERVER_CONFIG" ] ;then
2828
exit 2
2929
fi
3030

31-
bindir=$(pbench-config script-dir pbench-server)
31+
bindir=$(pbench-server-config script-dir pbench-server)
3232
if [ -z "$bindir" ] ;then
3333
echo "No 'script-dir' setting in [pbench-server] section of config file $_PBENCH_SERVER_CONFIG"
3434
exit 3
3535
fi
3636

3737
# what roles does this server play?
38-
roles=$(pbench-config -l roles pbench-server)
38+
roles=$(pbench-server-config -l roles pbench-server)
3939
if [ -z "$roles" ] ;then
4040
echo "No 'roles' setting in [pbench-server] section of config file $_PBENCH_SERVER_CONFIG"
4141
exit 3
@@ -51,21 +51,21 @@ hostname=$(hostname -f)
5151
# the sanity check below will just skip all the roles for
5252
# the host, leaving us with an empty crontab. If you do
5353
# get an empty crontab, this is a good thing to check.
54-
realhost=$(pbench-config realhost pbench-server)
54+
realhost=$(pbench-server-config realhost pbench-server)
5555

5656
function crontab_header() {
5757
local mailfrom mailto
5858

5959
echo "_PBENCH_SERVER_CONFIG=$_PBENCH_SERVER_CONFIG" >> $crontab
60-
echo "PYTHONPATH=$(pbench-config lib-dir pbench-server)" >> $crontab
60+
echo "PYTHONPATH=$(pbench-server-config lib-dir pbench-server)" >> $crontab
6161

62-
mailto=$(pbench-config mailto pbench-server)
62+
mailto=$(pbench-server-config mailto pbench-server)
6363
if [ -z "$mailto" ] ;then
6464
echo "No 'mailto' specified in [pbench-server] section of the config file $_PBENCH_SERVER_CONFIG"
6565
else
6666
echo "MAILTO=$mailto" >> $crontab
6767
fi
68-
mailfrom=$(pbench-config mailfrom pbench-server)
68+
mailfrom=$(pbench-server-config mailfrom pbench-server)
6969
if [ -z "$mailfrom" ] ;then
7070
echo "No 'mailfrom' specified in [pbench-server] section of the config file $_PBENCH_SERVER_CONFIG"
7171
else
@@ -76,12 +76,12 @@ function crontab_header() {
7676
function crontab_normal() {
7777
local role=$1
7878

79-
tasks=$(pbench-config -l tasks $role)
79+
tasks=$(pbench-server-config -l tasks $role)
8080
if [ -z "$tasks" ] ;then
8181
echo "No 'tasks' specified in [$role] section of the config file $_PBENCH_SERVER_CONFIG"
8282
else
8383
for task in $tasks ;do
84-
crontabline=$(pbench-config crontab $task)
84+
crontabline=$(pbench-server-config crontab $task)
8585
if [ -z "$tasks" ] ;then
8686
echo "No 'crontab' specified in [$task] section of the config file $_PBENCH_SERVER_CONFIG"
8787
else
@@ -99,12 +99,12 @@ function crontab_with_substitutions() {
9999
local section=$1
100100
local task=$2
101101

102-
crontabline=$(pbench-config crontab $task)
102+
crontabline=$(pbench-server-config crontab $task)
103103
if [ -z "$crontabline" ] ;then
104104
echo "No 'crontab' specified in [$task] section of the config file $_PBENCH_SERVER_CONFIG"
105105
else
106106
echo "$crontabline" |
107-
sed "$(pbench-config -a $section | grep = | awk -F' = ' '{gsub(/-/, "_", $1); printf "s;$%s;%s;g\n", toupper($1) , $2;}')" >> $crontab
107+
sed "$(pbench-server-config -a $section | grep = | awk -F' = ' '{gsub(/-/, "_", $1); printf "s;$%s;%s;g\n", toupper($1) , $2;}')" >> $crontab
108108
fi
109109
}
110110

@@ -113,7 +113,7 @@ crontab_header
113113

114114
for role in $roles ;do
115115

116-
host=$(pbench-config host $role)
116+
host=$(pbench-server-config host $role)
117117
# Sanity test: either host or realhost (from the config file)
118118
# *must* match the hostname of the host where this is being
119119
# installed, otherwise this role is irrelevant for this host
@@ -123,8 +123,8 @@ for role in $roles ;do
123123
fi
124124
case $role in
125125
pbench-prep)
126-
versions=$(pbench-config -l pbench-move-results-receive-versions pbench-server)
127-
tasks=$(pbench-config -l tasks $role)
126+
versions=$(pbench-server-config -l pbench-move-results-receive-versions pbench-server)
127+
tasks=$(pbench-server-config -l tasks $role)
128128
for version in $versions ;do
129129
for task in $tasks; do
130130
crontab_with_substitutions prep-shim-$version $task
@@ -140,17 +140,17 @@ done
140140
chmod 644 $crontab
141141

142142
# create the lock directory that the cron entries will use
143-
lockdir=$(pbench-config lock-dir pbench-server)
143+
lockdir=$(pbench-server-config lock-dir pbench-server)
144144
mkdir -p ${lockdir}
145145
chmod 755 ${lockdir}
146146

147-
user=$(pbench-config user pbench-server)
147+
user=$(pbench-server-config user pbench-server)
148148
if [ -z "$user" ] ;then
149149
echo "user is undefined in section \"pbench-server\" of config file."
150150
exit 5
151151
fi
152152

153-
group=$(pbench-config group pbench-server)
153+
group=$(pbench-server-config group pbench-server)
154154
if [ -z "$group" ] ;then
155155
echo "group is undefined in section \"pbench-server\" of config file."
156156
exit 5

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ console_scripts =
2727
pbench-cleanup = pbench.cli.agent.commands.cleanup:main
2828
pbench-clear-results = pbench.cli.agent.commands.results.clear:main
2929
pbench-clear-tools = pbench.cli.agent.commands.tools.clear:main
30-
pbench-config = pbench.common.conf:main
30+
pbench-config = pbench.cli.agent.commands.conf:main
3131
pbench-tree-manage = pbench.cli.server.tree_manage:tree_manage
3232
pbench-generate-token = pbench.cli.agent.commands.generate_token:main
3333
pbench-is-local = pbench.cli.agent.commands.is_local:main
@@ -37,6 +37,7 @@ console_scripts =
3737
pbench-results-move = pbench.cli.agent.commands.results.move:main
3838
pbench-results-push = pbench.cli.agent.commands.results.push:main
3939
pbench-server = pbench.cli.server.shell:main
40+
pbench-server-config = pbench.cli.server.conf:main
4041
pbench-tools-kill = pbench.cli.agent.commands.tools.kill:main
4142
pbench-user-create = pbench.cli.server.user_management:user_create
4243
pbench-user-delete = pbench.cli.server.user_management:user_delete

0 commit comments

Comments
 (0)