From ab46d3ac4c5c1609d6f46baad83de11d6f0357c0 Mon Sep 17 00:00:00 2001 From: Ken Giusti Date: Mon, 23 Sep 2024 07:47:23 -0400 Subject: [PATCH] Fix python-checker errors flagged by pylint update (#1612) (cherry picked from commit c4b704aed786a56778452db4708c0b0d5e5adc36) --- scripts/auto_mesh.py | 3 ++- scripts/gha_purge_successful_test_logs.py | 4 ++-- scripts/sigforwarder.py | 9 +++++---- tests/pylintrc | 1 + tools/scraper/log_splitter.py | 2 +- tools/scraper/parser.py | 24 ++++++++++++----------- tools/scraper/seq-diag-gen.py | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/scripts/auto_mesh.py b/scripts/auto_mesh.py index f43091ff3..c907a9772 100644 --- a/scripts/auto_mesh.py +++ b/scripts/auto_mesh.py @@ -259,10 +259,11 @@ def get_inter_router_properties(self): return {"port": "55672"} def append_connectors(self, connectors): + mode = os.environ.get("QDROUTERD_AUTO_MESH_DISCOVERY", "") properties = self.get_inter_router_properties() with open(self.filename, "a") as f: print("", file=f) - print("# generated by auto-mesh %s" % mode, file=f) + print("# generated by auto-mesh %s" % mode.upper(), file=f) for c in connectors: c.update(properties) c.update(generate_connector_name(c)) diff --git a/scripts/gha_purge_successful_test_logs.py b/scripts/gha_purge_successful_test_logs.py index d01c9181d..9016793bb 100755 --- a/scripts/gha_purge_successful_test_logs.py +++ b/scripts/gha_purge_successful_test_logs.py @@ -44,13 +44,13 @@ def main() -> int: log_file = pathlib.Path(build_dir, 'Testing', 'Temporary', 'LastTestsFailed.log') if not log_file.exists(): - logging.info(f"File {log_file} does not exist - nothing to do") + logging.info("File %s does not exist - nothing to do", log_file) return 0 with log_file.open('rt') as f: failed_tests = gha_tools.parse_last_tests_failed_log(f) failed_test_names = {test[1] for test in failed_tests} - logging.debug(f"Failed tests: {failed_test_names}") + logging.debug("Failed tests: %s", failed_test_names) system_tests_dir = pathlib.Path(build_dir, 'tests', 'system_test.dir', 'tests') if not system_tests_dir.exists(): diff --git a/scripts/sigforwarder.py b/scripts/sigforwarder.py index 9a2afcec7..57c2962eb 100755 --- a/scripts/sigforwarder.py +++ b/scripts/sigforwarder.py @@ -98,7 +98,7 @@ def pre_exec() -> int: def handle_signal(sig_number: int, stackframe): """Forward the signal we got to the grandchildren""" del stackframe # unused - logging.debug(f"Sigforwarder got signal: {sig_number}") + logging.debug("Sigforwarder got signal: %s", sig_number) if not P: return @@ -106,13 +106,14 @@ def handle_signal(sig_number: int, stackframe): for prc in psutil.process_iter(attrs=('pid', 'ppid')): if prc.ppid() == P.pid: - logging.debug(f"Grandchild pid: {prc.pid}, sending signal: {sig_number} to it") + logging.debug("Grandchild pid: %s, sending signal: %s to it", prc.pid, sig_number) os.kill(prc.pid, sig_number) def sigforwarder(program: str, program_args: List[str]) -> int: global P + # pylint: disable=subprocess-popen-preexec-fn P = subprocess.Popen( args=(program, *program_args), preexec_fn=pre_exec @@ -124,7 +125,7 @@ def sigforwarder(program: str, program_args: List[str]) -> int: signal.signal(s, handle_signal) # rr will propagate exit code from skrouterd, so we only need to propagate from rr - logging.debug(f"Sigforwarder running {program}, waiting for status") + logging.debug("Sigforwarder running %s, waiting for status", program) return P.wait() @@ -161,7 +162,7 @@ def test_run_child_process_grandchild_gets_the_kill(self): def main(): if len(sys.argv) < 2: - RuntimeError("At least one argument is required") + raise RuntimeError("At least one argument is required") argv0, program, *program_args = sys.argv diff --git a/tests/pylintrc b/tests/pylintrc index 5640fa9dd..e975056be 100644 --- a/tests/pylintrc +++ b/tests/pylintrc @@ -74,6 +74,7 @@ disable = super-with-arguments, too-few-public-methods, too-many-arguments, + too-many-positional-arguments, too-many-branches, too-many-instance-attributes, too-many-lines, diff --git a/tools/scraper/log_splitter.py b/tools/scraper/log_splitter.py index 4fe1c3747..2e09f0e82 100755 --- a/tools/scraper/log_splitter.py +++ b/tools/scraper/log_splitter.py @@ -473,7 +473,7 @@ def write_subfiles(self): os.makedirs(odir) for i in range(1, self.hist_max): - nrange = ("10e%d" % (i)) + nrange = "10e%d" % (i) ndir = os.path.join(odir, nrange) os.makedirs(ndir) odirs.append(ndir) diff --git a/tools/scraper/parser.py b/tools/scraper/parser.py index 31afc0f05..bee318ce2 100755 --- a/tools/scraper/parser.py +++ b/tools/scraper/parser.py @@ -32,7 +32,9 @@ import test_data as td import common import text -import router +from router import Router +from router import RestartRecord +from router import which_router_tod SEQUENCE_TRANSFER_SIZE = 50 """ @@ -954,7 +956,7 @@ def __init__(self, _log_index, _instance, _lineno, _line, _comn, _router, opaque self.line = self.line.lstrip() # cover for traces that don't get any better - self.data.web_show_str = ("%s" % self.line) + self.data.web_show_str = "%s" % self.line # policy lines have no direction and described type fields if self.data.is_policy_trace or self.data.is_server_info: @@ -964,7 +966,7 @@ def __init__(self, _log_index, _instance, _lineno, _line, _comn, _router, opaque if self.line.startswith('<') or self.line.startswith('-'): self.data.direction = self.line[:2] self.line = self.line[3:] - self.data.web_show_str = ("%s" % self.line) + self.data.web_show_str = "%s" % self.line # The log line is now reduced to a described type: # @describedtypename(num) [key=val [, key=val ...]] @@ -1032,10 +1034,10 @@ def parse_log_file(fn, log_index, comn): # Any key or AMQP line indicates a router in-progress if any(s in line for s in keys) or ("[" in line and "]" in line): assert rtr is None - rtr = router.Router(fn, log_index, instance) + rtr = Router(fn, log_index, instance) rtrs.append(rtr) search_for_in_progress = False - rtr.restart_rec = router.RestartRecord(rtr, line, lineno + 1) + rtr.restart_rec = RestartRecord(rtr, line, lineno + 1) lineno += 1 verbatim_module = None if len(comn.verbatim_include_list) > 0: @@ -1047,9 +1049,9 @@ def parse_log_file(fn, log_index, comn): # This line closes the current router, if any, and opens a new one if rtr is not None: instance += 1 - rtr = router.Router(fn, log_index, instance) + rtr = Router(fn, log_index, instance) rtrs.append(rtr) - rtr.restart_rec = router.RestartRecord(rtr, line, lineno) + rtr.restart_rec = RestartRecord(rtr, line, lineno) search_for_in_progress = False rtr.container_name = line[(line.find(key2) + len(key2)):].strip().split()[0] elif key3 in line: @@ -1154,13 +1156,13 @@ class dummy_args(): t_in_1 = datetime.strptime('2018-10-15 10:59:07.584498', '%Y-%m-%d %H:%M:%S.%f') t_af_1 = datetime.strptime('2019-10-15 10:59:07.584498', '%Y-%m-%d %H:%M:%S.%f') - rtr, idx = router.which_router_tod(routers, t_b4_0) + rtr, idx = which_router_tod(routers, t_b4_0) assert rtr is routers[0] and idx == 0 - rtr, idx = router.which_router_tod(routers, t_in_0) + rtr, idx = which_router_tod(routers, t_in_0) assert rtr is routers[0] and idx == 0 - rtr, idx = router.which_router_tod(routers, t_in_1) + rtr, idx = which_router_tod(routers, t_in_1) assert rtr is routers[1] and idx == 1 - rtr, idx = router.which_router_tod(routers, t_af_1) + rtr, idx = which_router_tod(routers, t_af_1) assert rtr is routers[1] and idx == 1 pass diff --git a/tools/scraper/seq-diag-gen.py b/tools/scraper/seq-diag-gen.py index 1857d0d34..66e048a95 100755 --- a/tools/scraper/seq-diag-gen.py +++ b/tools/scraper/seq-diag-gen.py @@ -52,7 +52,7 @@ def __init__(self, index, line): self.performative = perf.strip() self.router_line = router_line.strip() # diag self.peer_log_rec = None - dir_out = (direction == '->') # name_left -> name_right + dir_out = direction == '->' # name_left -> name_right self.sentby = name_left.strip() if dir_out else name_right.strip() self.rcvdby = name_right.strip() if dir_out else name_left.strip()