From 4e69f800de2a43dbea676f40e7005ccc1fad63d3 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Wed, 14 Jun 2023 16:54:38 +0200 Subject: [PATCH] test/case: Add meta/wait to wait for nodes to boot up When running in the cloud, without KVM emulation, together with many other tenants, it can take a very long time to boot the instances. Therefore, add a meta test that will wait for all devices in the physical topology to come up before exiting. This means that the actual test cases that follow can assume that devices will answer NETCONF requests. --- test/case/all.yaml | 2 ++ test/case/meta/wait.py | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 test/case/meta/wait.py diff --git a/test/case/all.yaml b/test/case/all.yaml index 83e9630d..0aed385d 100644 --- a/test/case/all.yaml +++ b/test/case/all.yaml @@ -1,4 +1,6 @@ --- +- case: meta/wait.py + - name: ietf-system suite: ietf_system/all.yaml diff --git a/test/case/meta/wait.py b/test/case/meta/wait.py new file mode 100755 index 00000000..a8a035ed --- /dev/null +++ b/test/case/meta/wait.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import socket +import time + +import infamy, infamy.neigh + +def ll6ping(node): + neigh = None + + for (_, cport), (_, nport) in env.ptop.get_paths(ctrl, node): + neigh = infamy.neigh.ll6ping(cport, flags=["-w1", "-c1", "-L", "-n"]) + if neigh: + print(f"Found {neigh} on {cport} (connected to {node}:{nport})") + break + + return neigh + +def netconf_syn(neigh): + try: + ai = socket.getaddrinfo(neigh, 830, 0, 0, socket.SOL_TCP) + sock = socket.socket(ai[0][0], ai[0][1], 0) + sock.connect(ai[0][4]) + sock.close() + print(f"{neigh} answers to TCP connections on port 830 (NETCONF)") + return True + except: + return False + +with infamy.Test() as test: + with test.step("Initialize"): + env = infamy.Env() + + ctrl = env.ptop.get_ctrl() + infixen = env.ptop.get_infixen() + + with test.step(f"Reach {infixen}"): + timeout = time.time() + 300 + + print(f"Waiting a maximum of 5min for {infixen} to come up") + + while infixen and time.time() < timeout: + time.sleep(1) + retry = [] + for node in infixen: + neigh = ll6ping(node) + if neigh and netconf_syn(neigh): + continue + + retry.append(node) + + infixen = retry + + if infixen: + print(f"Unable to reach {infixen}") + test.fail() + + test.succeed()