osmith submitted this change.
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(-)
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 change 41420. To unsubscribe, or for help writing mail filters, visit settings.