Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8fd0539

Browse files
author
vshepard
committed
Remove usage of not standard nc in remote_ops.py is_port_free
1 parent79bc692 commit8fd0539

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

‎testgres/operations/remote_ops.py‎

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importlogging
1111
importtyping
1212
importcopy
13+
importsocket
1314

1415
from ..exceptionsimportExecUtilException
1516
from ..exceptionsimportInvalidOperationException
@@ -681,28 +682,24 @@ def get_process_children(self, pid):
681682
defis_port_free(self,number:int)->bool:
682683
asserttype(number)==int# noqa: E721
683684

684-
cmd= ["nc","-w","5","-z","-v","localhost",str(number)]
685+
host='localhost'
686+
port=number
687+
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
688+
sock.settimeout(5.0)
685689

686-
exit_status,output,error=self.exec_command(cmd=cmd,encoding=get_default_encoding(),ignore_errors=True,verbose=True)
687-
688-
asserttype(output)==str# noqa: E721
689-
asserttype(error)==str# noqa: E721
690-
691-
ifexit_status==0:
692-
return__class__._is_port_free__process_0(error)
693-
694-
ifexit_status==1:
695-
return__class__._is_port_free__process_1(error)
696-
697-
errMsg="nc returns an unknown result code: {0}".format(exit_status)
698-
699-
RaiseError.CommandExecutionError(
700-
cmd=cmd,
701-
exit_code=exit_status,
702-
message=errMsg,
703-
error=error,
704-
out=output
705-
)
690+
try:
691+
result=sock.connect_ex((host,port))
692+
returnresult!=0
693+
exceptExceptionase:
694+
raiseRaiseError.CommandExecutionError(
695+
cmd=['socket.connect_ex',host,str(port)],
696+
exit_code=getattr(e,'errno',None),
697+
message=f"Error checking port{port}:{e}",
698+
error=str(e),
699+
out=""
700+
)
701+
finally:
702+
sock.close()
706703

707704
defget_tempdir(self)->str:
708705
command= ["mktemp","-u","-d"]
@@ -746,12 +743,7 @@ def _is_port_free__process_0(error: str) -> bool:
746743
@staticmethod
747744
def_is_port_free__process_1(error:str)->bool:
748745
asserttype(error)==str# noqa: E721
749-
#
750-
# Example of error text:
751-
# "nc: connect to localhost (127.0.0.1) port 1024 (tcp) failed: Connection refused\n"
752-
#
753746
# May be here is needed to check error message?
754-
#
755747
returnTrue
756748

757749
@staticmethod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp