From db25224d7365f724221eabe7ad2c248be2ae4fe9 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Thu, 27 Jul 2023 06:44:02 -0400 Subject: [PATCH 1/2] avocado/core/task/statemachine.py: improve docstring This improves the _send_finished_tasks_message() docstring with missing parameter info and a more complete description of its purpose and behavior. Signed-off-by: Cleber Rosa --- avocado/core/task/statemachine.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/avocado/core/task/statemachine.py b/avocado/core/task/statemachine.py index afe772e063..08b74d0b01 100644 --- a/avocado/core/task/statemachine.py +++ b/avocado/core/task/statemachine.py @@ -182,13 +182,24 @@ def __repr__(self): ) async def _send_finished_tasks_message(self, terminate_tasks, reason): - """Sends messages related to timeout to status repository. - When the task is terminated, it is necessary to send a finish message to status - repository to close logging. This method will send log message with timeout - information and finish message with right fail reason. + """Sends messages related to tasks being terminated to status repository. - :param terminate_tasks: runtime_tasks which were terminated + On normal conditions, the "avocado-runner-*" will produce messages + finishing each task. But, under some conditions (such as timeouts, + interruptions requested by users, etc), it's necessary to do this on + the runner's behalf. + + When a task is terminated, it is necessary to send a "finish" message + with the correct fail reason to the status repository, which will close + logging. This method will also send a "log" message with the reason + (timeout, user interruption, etc). + + :param terminate_tasks: runtime_tasks which were terminated and need + to have messages sent on their behalf :type terminate_tasks: list + :param reason: a description of what caused the task interruption (timeout, user + requested interruption, etc). + :type reason: str """ for terminated_task in terminate_tasks: task_id = str(terminated_task.task.identifier) From e2f70c62fc18bcd81be5b5cd8ea8723e1efbc8dd Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Thu, 27 Jul 2023 06:44:02 -0400 Subject: [PATCH 2/2] avocado/utils/process.py: fix duplicate int conversion Commit 3362a30dfb erronously added a second identical conversion of the signal and process ID integers to the formatting string. This removes the duplication. Signed-off-by: Cleber Rosa --- avocado/utils/process.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/avocado/utils/process.py b/avocado/utils/process.py index 90999dcba7..b052ad6def 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -154,7 +154,7 @@ def safe_kill(pid, signal): # pylint: disable=W0621 :param signal: Signal number. """ if get_owner_id(int(pid)) == 0: - kill_cmd = f"kill -{int(int(signal))} {int(int(pid))}" + kill_cmd = f"kill -{int(signal)} {int(pid)}" try: run(kill_cmd, sudo=True) return True @@ -304,7 +304,7 @@ def process_in_ptree_is_defunct(ppid): except CmdError: # Process doesn't exist return True for pid in pids: - cmd = f"ps --no-headers -o cmd {int(int(pid))}" + cmd = f"ps --no-headers -o cmd {int(pid)}" proc_name = system_output(cmd, ignore_status=True, verbose=False) if "" in proc_name: defunct = True @@ -795,7 +795,7 @@ def send_signal(self, sig): pids = get_children_pids(self.get_pid()) pids.append(self.get_pid()) for pid in pids: - kill_cmd = f"kill -{int(int(sig))} {int(pid)}" + kill_cmd = f"kill -{int(sig)} {int(pid)}" with contextlib.suppress(Exception): run(kill_cmd, sudo=True) else: