From d340ba74072e4eda897e06c8a47b34b90df0d074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Tue, 18 Jun 2024 13:46:21 +0200 Subject: [PATCH] infamy: Wait for NETCONF and RESTCONF Also remove some code duplication. --- test/case/meta/wait.py | 9 +++++++-- test/infamy/restconf.py | 17 +++++++++++++++++ test/infamy/topology.py | 3 ++- test/infamy/util.py | 3 +++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/test/case/meta/wait.py b/test/case/meta/wait.py index 538fe372..493fbd1e 100755 --- a/test/case/meta/wait.py +++ b/test/case/meta/wait.py @@ -2,8 +2,12 @@ import socket import time - +import requests import infamy, infamy.neigh +import infamy.restconf as restconf +import infamy.netconf as netconf + +from requests.auth import HTTPBasicAuth def ll6ping(node): neigh = None @@ -44,7 +48,8 @@ with infamy.Test() as test: retry = [] for node in infixen: neigh = ll6ping(node) - if neigh and netconf_syn(neigh): + password = env.ptop.get_password(node) + if neigh and netconf.netconf_syn(neigh) and restconf.restconf_reachable(neigh, password): continue retry.append(node) diff --git a/test/infamy/restconf.py b/test/infamy/restconf.py index 420e7e3a..79fde442 100644 --- a/test/infamy/restconf.py +++ b/test/infamy/restconf.py @@ -23,6 +23,23 @@ class Location: username: str = "admin" port: int = 443 + +def restconf_reachable(neigh, password): + try: + headers={ + 'Content-Type': 'application/yang-data+json', + 'Accept': 'application/yang-data+json' + } + url=f"https://[{neigh}]/restconf/data/ietf-system:system/hostname" + auth=HTTPBasicAuth("admin", password) + response=requests.get(url, headers=headers, auth=auth, verify=False) + print(f"{neigh} answers to TCP connections on port 443 (RESTCONF)") + if response.status_code==200: + return True + except: + return False + + return False class Device(Transport): def __init__(self, location: Location, diff --git a/test/infamy/topology.py b/test/infamy/topology.py index a94e9a98..076effb0 100644 --- a/test/infamy/topology.py +++ b/test/infamy/topology.py @@ -122,7 +122,8 @@ class Topology: n = self.dotg.get_node(node) b = n[0] if n else {} password=b.get("password") - return qstrip(password) if password is not None else None + + return qstrip(password) if password is not None else "admin" def get_link(self, src, dst, flt=lambda _: True): es = self.g.get_edge_data(src, dst) diff --git a/test/infamy/util.py b/test/infamy/util.py index 3e8316ea..6aeef2c2 100644 --- a/test/infamy/util.py +++ b/test/infamy/util.py @@ -2,6 +2,7 @@ import time import threading import infamy.neigh import infamy.netconf as netconf +import infamy.restconf as restconf class ParallelFn(threading.Thread): def __init__(self, group=None, target=None, name=None, @@ -50,4 +51,6 @@ def wait_boot(target): if not neigh: return False until(lambda: netconf.netconf_syn(neigh) == True, attempts = 300) + until(lambda: restconf.restconf_reachable(neigh, target.location.password) == True, attempts = 300) + return True