From 935b2a9aab2699c6ea62d72c09e7f719fd20040f Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 26 Aug 2024 13:23:09 +0200 Subject: [PATCH 1/2] Ignore errors during teardown --- testgres/node.py | 2 +- testgres/operations/local_ops.py | 5 +++-- testgres/operations/remote_ops.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index 8b30476f..d3f08e09 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -360,7 +360,7 @@ def _try_shutdown(self, max_attempts, with_force=False): pass # Check that node stopped - p_status_output = self.os_ops.exec_command(f'ps -p {node_pid}', shell=True, expect_error=True).decode('utf-8') + p_status_output = self.os_ops.exec_command(f'ps -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8') if p_status_output and str(node_pid) in p_status_output: eprint(f'Failed to stop node {self.name}.') else: diff --git a/testgres/operations/local_ops.py b/testgres/operations/local_ops.py index 3d9e490e..a0a9926d 100644 --- a/testgres/operations/local_ops.py +++ b/testgres/operations/local_ops.py @@ -107,14 +107,15 @@ def _run_command(self, cmd, shell, input, stdin, stdout, stderr, get_process, ti raise ExecUtilException("Command timed out after {} seconds.".format(timeout)) def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False, encoding=None, shell=False, - text=False, input=None, stdin=None, stdout=None, stderr=None, get_process=False, timeout=None): + text=False, input=None, stdin=None, stdout=None, stderr=None, get_process=False, timeout=None, + ignore_errors=False): """ Execute a command in a subprocess and handle the output based on the provided parameters. """ process, output, error = self._run_command(cmd, shell, input, stdin, stdout, stderr, get_process, timeout, encoding) if get_process: return process - if (process.returncode != 0 or has_errors(output=output, error=error)) and not expect_error: + if not ignore_errors and ((process.returncode != 0 or has_errors(output=output, error=error)) and not expect_error): self._raise_exec_exception('Utility exited with non-zero code. Error `{}`', cmd, process.returncode, error or output) if verbose: diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index f85490ef..20095051 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -60,7 +60,7 @@ def __enter__(self): def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False, encoding=None, shell=True, text=False, input=None, stdin=None, stdout=None, - stderr=None, get_process=None, timeout=None): + stderr=None, get_process=None, timeout=None, ignore_errors=False): """ Execute a command in the SSH session. Args: @@ -98,7 +98,7 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False, marker in error for marker in ['error', 'Permission denied', 'fatal', 'No such file or directory'] ) - if error_found: + if not ignore_errors and error_found: if isinstance(error, bytes): message = b"Utility exited with non-zero code. Error: " + error else: From 6c86d46f351c0c92ad6f0b3348664983bd059aae Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 26 Aug 2024 13:40:05 +0200 Subject: [PATCH 2/2] Tests Ignore errors during node tear down --- testgres/node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index d3f08e09..1404f9cc 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -359,8 +359,8 @@ def _try_shutdown(self, max_attempts, with_force=False): # The node has already stopped pass - # Check that node stopped - p_status_output = self.os_ops.exec_command(f'ps -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8') + # Check that node stopped - print only column pid without headers + p_status_output = self.os_ops.exec_command(f'ps -o pid= -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8') if p_status_output and str(node_pid) in p_status_output: eprint(f'Failed to stop node {self.name}.') else: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy