Content-Length: 3534 | pFad | http://github.com/postgrespro/testgres/pull/284.patch

thub.com From 078483f933c047bca702fdc81cc87fe0f5a81130 Mon Sep 17 00:00:00 2001 From: vshepard Date: Thu, 7 Aug 2025 01:41:15 +0200 Subject: [PATCH 1/2] Remove usage of not standard nc in remote_ops.py is_port_free --- testgres/operations/remote_ops.py | 33 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index 15d78b1..99f6278 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -10,6 +10,7 @@ import logging import typing import copy +import socket from ..exceptions import ExecUtilException from ..exceptions import InvalidOperationException @@ -681,22 +682,31 @@ def get_process_children(self, pid): def is_port_free(self, number: int) -> bool: assert type(number) == int # noqa: E721 - cmd = ["nc", "-w", "5", "-z", "-v", "localhost", str(number)] + # grep -q returns 0 if a listening socket on that port is found + port_hex = format(number, '04X') - exit_status, output, error = self.exec_command(cmd=cmd, encoding=get_default_encoding(), ignore_errors=True, verbose=True) + # Search /proc/net/tcp and tcp6 for any entry with this port + cmd = ['/bin/bash', '-lc', + f"grep -q ':{port_hex} ' /proc/net/tcp /proc/net/tcp6"] - assert type(output) == str # noqa: E721 - assert type(error) == str # noqa: E721 + exit_status, output, error = self.exec_command( + cmd=cmd, + encoding=get_default_encoding(), + ignore_errors=True, + verbose=True + ) + # grep exit 0 -> port is busy if exit_status == 0: - return __class__._is_port_free__process_0(error) + return False + # grep exit 1 -> port is free if exit_status == 1: - return __class__._is_port_free__process_1(error) - - errMsg = "nc returns an unknown result code: {0}".format(exit_status) + return True - RaiseError.CommandExecutionError( + # any other code is an unexpected error + errMsg = f"grep returned unexpected exit code: {exit_status}" + raise RaiseError.CommandExecutionError( cmd=cmd, exit_code=exit_status, message=errMsg, @@ -746,12 +756,7 @@ def _is_port_free__process_0(error: str) -> bool: @staticmethod def _is_port_free__process_1(error: str) -> bool: assert type(error) == str # noqa: E721 - # - # Example of error text: - # "nc: connect to localhost (127.0.0.1) port 1024 (tcp) failed: Connection refused\n" - # # May be here is needed to check error message? - # return True @staticmethod From cb0d9fb1c360ac8710e0c243c7b381bad4adc477 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Thu, 7 Aug 2025 08:21:59 +0300 Subject: [PATCH 2/2] Fix for flake8 checks [remote_ops.py] [del] import socket --- testgres/operations/remote_ops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index 99f6278..9805c9d 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -10,7 +10,6 @@ import logging import typing import copy -import socket from ..exceptions import ExecUtilException from ..exceptions import InvalidOperationException








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/testgres/pull/284.patch

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy