Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
RemoteOperations::is_port_free uses a regexp, tcp6 is removed
We will use a more clever analyzer for content of /proc/net/tcp.

I deleted a support of TCP/IP v6 because:
- LocalOperations does not support it
- We do not have the tests for TCP/IP v6

We should add the support of TCP/IP v6 separately and completely.
  • Loading branch information
dmitry-lipetsk committed Aug 15, 2025
commit 7654478125042da2ba002aab15c004150e15204d
18 changes: 15 additions & 3 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import typing
import copy
import re

from ..exceptions import ExecUtilException
from ..exceptions import InvalidOperationException
Expand Down Expand Up @@ -684,9 +685,20 @@ def is_port_free(self, number: int) -> bool:
# grep -q returns 0 if a listening socket on that port is found
port_hex = format(number, '04X')

# Search /proc/net/tcp and tcp6 for any entry with this port
cmd = ['/bin/bash', '-c',
f"grep -q ':{port_hex} ' /proc/net/tcp /proc/net/tcp6"]
# sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt ...
# 137: 0A01A8C0:EC08 1DA2A959:01BB 01 00000000:00000000 02:00000000 00000000 ...
C_REGEXP = r"^\s*[0-9]+:\s*[0-9a-fA-F]{8}:" + re.escape(port_hex) + r"\s+[0-9a-fA-F]{8}:[0-9a-fA-F]{4}\s+"

# Search /proc/net/tcp for any entry with this port
# NOTE: grep requires quote string with regular expression
# TODO: added a support for tcp/ip v6
grep_cmd_s = "grep -q -E \"" + C_REGEXP + "\" /proc/net/tcp"

cmd = [
"/bin/bash",
"-c",
grep_cmd_s,
]

exit_status, output, error = self.exec_command(
cmd=cmd,
Expand Down