diff --git a/cts/support/Makefile.am b/cts/support/Makefile.am index 207de05511..bfce1bd495 100644 --- a/cts/support/Makefile.am +++ b/cts/support/Makefile.am @@ -1,28 +1,28 @@ # # Copyright 2021 the Pacemaker project contributors # # The version control history for this file may have further details. # # This source code is licensed under the GNU General Public License version 2 # or later (GPLv2+) WITHOUT ANY WARRANTY. # include $(top_srcdir)/mk/python.mk MAINTAINERCLEANFILES = Makefile.in # Commands intended to be run only via other commands halibdir = $(CRM_DAEMON_DIR) dist_halib_SCRIPTS = cts-support ctsdir = $(datadir)/$(PACKAGE)/tests/cts cts_DATA = pacemaker-cts-dummyd@.service dist_cts_DATA = cts.conf if BUILD_UPSTART dist_cts_DATA += pacemaker-cts-dummyd.conf endif cts_SCRIPTS = fence_dummy \ LSBDummy \ pacemaker-cts-dummyd -PYCHECKFILES ?= cts-support +PYCHECKFILES ?= cts-support pacemaker-cts-dummyd diff --git a/cts/support/pacemaker-cts-dummyd.in b/cts/support/pacemaker-cts-dummyd.in index 453a644673..53512484fd 100644 --- a/cts/support/pacemaker-cts-dummyd.in +++ b/cts/support/pacemaker-cts-dummyd.in @@ -1,55 +1,62 @@ #!@PYTHON@ -""" Slow-starting idle daemon that notifies systemd when it starts -""" +"""Slow-starting idle daemon that notifies systemd when it starts.""" -__copyright__ = "Copyright 2014-2020 the Pacemaker project contributors" +# pylint doesn't like the module name "pacemaker-cts-dummyd" which is an invalid complaint +# for this file but probably something we want to continue warning about elsewhere +# pylint: disable=invalid-name + +__copyright__ = "Copyright 2014-2024 the Pacemaker project contributors" __license__ = "GNU General Public License version 2 or later (GPLv2+) WITHOUT ANY WARRANTY" -import sys -import time +from functools import partial import signal import subprocess +import sys +import time + have_systemd_daemon = True try: import systemd.daemon except ImportError: have_systemd_daemon = False -delay = None def parse_args(): - global delay + """Return the delay given on the command line, if any.""" + delay = None # Lone argument is a number of seconds to delay start and stop if len(sys.argv) > 0: try: delay = float(sys.argv[1]) except ValueError: delay = None + return delay -def twiddle(): - global delay +def twiddle(delay): + """Sleep the given number of seconds.""" if delay is not None: time.sleep(delay) -def bye(signum, frame): - twiddle() +def bye(_signum, _frame, delay=None): + """SIGTERM signal handler.""" + twiddle(delay) sys.exit(0) if __name__ == "__main__": + d = parse_args() + signal.signal(signal.SIGTERM, partial(bye, delay=d)) + twiddle(d) - parse_args() - signal.signal(signal.SIGTERM, bye) - twiddle() if have_systemd_daemon: systemd.daemon.notify("READY=1") else: subprocess.call(["systemd-notify", "READY=1"]) # This isn't a "proper" daemon, but that would be overkill for testing purposes while True: time.sleep(600.0)