Skip to content

Commit

Permalink
Separate pbench-config and pbench-server-config
Browse files Browse the repository at this point in the history
  • Loading branch information
portante committed Mar 14, 2023
1 parent 87d739a commit 761445c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 40 deletions.
12 changes: 12 additions & 0 deletions lib/pbench/cli/agent/commands/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import sys

from pbench.common.conf import common_main


def main():
sys.exit(common_main(os.path.basename(sys.argv[0]), "_PBENCH_AGENT_CONFIG"))


if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions lib/pbench/cli/server/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import sys

from pbench.common.conf import common_main


def main():
sys.exit(common_main(os.path.basename(sys.argv[0]), "_PBENCH_SERVER_CONFIG"))


if __name__ == "__main__":
main()
32 changes: 10 additions & 22 deletions lib/pbench/common/conf.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import os
import sys

from pbench.common import configtools


def get_pbench_config():
"""Determine if we are using agent or server."""
agent_cfg = os.environ.get("_PBENCH_AGENT_CONFIG")
server_cfg = os.environ.get("_PBENCH_SERVER_CONFIG")
if agent_cfg:
return "_PBENCH_AGENT_CONFIG"
elif server_cfg:
return "_PBENCH_SERVER_CONFIG"
else:
return sys.exit(1)
def common_main(prog: str, env: str):
"""Common entry point for agent and server pbench-config commands.
Args:
prog : invocation program name to use in Usage message
env : environment variable for configuration file
def main():
prog = os.path.basename(sys.argv[0])
Returns:
Pass through of return code from `configtools.main`
"""
opts, args = configtools.parse_args(
configtools.options,
usage=f"Usage: {prog} [options] <item>|-a <section> [<section> ...]",
)
conf, files = configtools.init(opts, get_pbench_config())
status = configtools.main(conf, args, opts, files)
sys.exit(status)


if __name__ == "__main__":
main()
conf, files = configtools.init(opts, env)
return configtools.main(conf, args, opts, files)
2 changes: 1 addition & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install-python3-setup: install-bin install-lib
mkdir -p ${DESTDIR}/python3
${COPY} requirements.txt ${DESTDIR}
(cd ..; /usr/bin/python3 -m pip install --prefix=${DESTDIR}/python3 -e .)
${COPY} $(addprefix ${DESTDIR}/python3/bin/, pbench-config pbench-server ${click-scripts}) ${BINDIR}/
${COPY} $(addprefix ${DESTDIR}/python3/bin/, pbench-server-config pbench-server ${click-scripts}) ${BINDIR}/
${RM} -r ${DESTDIR}/python3
${COPY} ../lib/pbench ${LIBDIR}/
${RM} -r $$(find ${LIBDIR} -name __pycache__) ${LIBDIR}/pbench/test ${LIBDIR}/pbench/agent ${LIBDIR}/pbench/cli/agent
Expand Down
32 changes: 16 additions & 16 deletions server/bin/pbench-create-crontab
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ if [ ! -f "$_PBENCH_SERVER_CONFIG" ] ;then
exit 2
fi

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

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

function crontab_header() {
local mailfrom mailto

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

mailto=$(pbench-config mailto pbench-server)
mailto=$(pbench-server-config mailto pbench-server)
if [ -z "$mailto" ] ;then
echo "No 'mailto' specified in [pbench-server] section of the config file $_PBENCH_SERVER_CONFIG"
else
echo "MAILTO=$mailto" >> $crontab
fi
mailfrom=$(pbench-config mailfrom pbench-server)
mailfrom=$(pbench-server-config mailfrom pbench-server)
if [ -z "$mailfrom" ] ;then
echo "No 'mailfrom' specified in [pbench-server] section of the config file $_PBENCH_SERVER_CONFIG"
else
Expand All @@ -76,12 +76,12 @@ function crontab_header() {
function crontab_normal() {
local role=$1

tasks=$(pbench-config -l tasks $role)
tasks=$(pbench-server-config -l tasks $role)
if [ -z "$tasks" ] ;then
echo "No 'tasks' specified in [$role] section of the config file $_PBENCH_SERVER_CONFIG"
else
for task in $tasks ;do
crontabline=$(pbench-config crontab $task)
crontabline=$(pbench-server-config crontab $task)
if [ -z "$tasks" ] ;then
echo "No 'crontab' specified in [$task] section of the config file $_PBENCH_SERVER_CONFIG"
else
Expand All @@ -99,12 +99,12 @@ function crontab_with_substitutions() {
local section=$1
local task=$2

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

Expand All @@ -113,7 +113,7 @@ crontab_header

for role in $roles ;do

host=$(pbench-config host $role)
host=$(pbench-server-config host $role)
# Sanity test: either host or realhost (from the config file)
# *must* match the hostname of the host where this is being
# installed, otherwise this role is irrelevant for this host
Expand All @@ -123,8 +123,8 @@ for role in $roles ;do
fi
case $role in
pbench-prep)
versions=$(pbench-config -l pbench-move-results-receive-versions pbench-server)
tasks=$(pbench-config -l tasks $role)
versions=$(pbench-server-config -l pbench-move-results-receive-versions pbench-server)
tasks=$(pbench-server-config -l tasks $role)
for version in $versions ;do
for task in $tasks; do
crontab_with_substitutions prep-shim-$version $task
Expand All @@ -140,17 +140,17 @@ done
chmod 644 $crontab

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

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

group=$(pbench-config group pbench-server)
group=$(pbench-server-config group pbench-server)
if [ -z "$group" ] ;then
echo "group is undefined in section \"pbench-server\" of config file."
exit 5
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ console_scripts =
pbench-cleanup = pbench.cli.agent.commands.cleanup:main
pbench-clear-results = pbench.cli.agent.commands.results.clear:main
pbench-clear-tools = pbench.cli.agent.commands.tools.clear:main
pbench-config = pbench.common.conf:main
pbench-config = pbench.cli.agent.commands.conf:main
pbench-tree-manage = pbench.cli.server.tree_manage:tree_manage
pbench-generate-token = pbench.cli.agent.commands.generate_token:main
pbench-is-local = pbench.cli.agent.commands.is_local:main
Expand All @@ -37,6 +37,7 @@ console_scripts =
pbench-results-move = pbench.cli.agent.commands.results.move:main
pbench-results-push = pbench.cli.agent.commands.results.push:main
pbench-server = pbench.cli.server.shell:main
pbench-server-config = pbench.cli.server.conf:main
pbench-tools-kill = pbench.cli.agent.commands.tools.kill:main
pbench-user-create = pbench.cli.server.user_management:user_create
pbench-user-delete = pbench.cli.server.user_management:user_delete
Expand Down

0 comments on commit 761445c

Please sign in to comment.