osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41420?usp=email ) Change subject: testenv: wait_for_port: add --protocol=sctp ...................................................................... testenv: wait_for_port: add --protocol=sctp Prepare to use the script in a follow up patch to check if the diameter port of PyHSS is ready. Change-Id: I6e75728b2e9b67c85d1ea2ae5ab15890074db272 --- M _testenv/data/scripts/wait_for_port.py 1 file changed, 34 insertions(+), 2 deletions(-) Approvals: Jenkins Builder: Verified osmith: Looks good to me, approved diff --git a/_testenv/data/scripts/wait_for_port.py b/_testenv/data/scripts/wait_for_port.py index 2a85319..8d5c3f5 100755 --- a/_testenv/data/scripts/wait_for_port.py +++ b/_testenv/data/scripts/wait_for_port.py @@ -10,7 +10,7 @@ args = None -def wait_for_port(): +def wait_for_port_tcp(): start_time = time.time() while True: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: @@ -25,6 +25,28 @@ time.sleep(0.1) +def wait_for_port_sctp(): + try: + import sctp + except ImportError: + print("python module sctp is not installed, sleeping 3s instead...") + time.sleep(3) + return + + start_time = time.time() + while True: + try: + sk = sctp.sctpsocket_tcp(socket.AF_INET) + sk.connect((args.hostname, args.port)) + sk.close() + sys.exit(0) + except ConnectionRefusedError: + if time.time() - start_time >= args.timeout: + print(f"ERROR: {args.hostname}:{args.port} did not become available within {args.timeout}s!") + sys.exit(1) + time.sleep(0.1) + + def parse_args(): global args @@ -48,9 +70,19 @@ default=5, help="timeout in seconds (default: 5).", ) + parser.add_argument( + "-P", + "--protocol", + choices=["tcp", "sctp"], + default="tcp", + ) args = parser.parse_args() if __name__ == "__main__": parse_args() - wait_for_port() + match args.protocol: + case "tcp": + wait_for_port_tcp() + case "sctp": + wait_for_port_sctp() -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41420?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I6e75728b2e9b67c85d1ea2ae5ab15890074db272 Gerrit-Change-Number: 41420 Gerrit-PatchSet: 3 Gerrit-Owner: osmith <osmith@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> Gerrit-Reviewer: osmith <osmith@sysmocom.de> Gerrit-Reviewer: pespin <pespin@sysmocom.de>