Merge pull request #1166 from kernelkit/infamy

Mix of test framework fixes and improvements
This commit is contained in:
Joachim Wiberg
2025-09-29 08:49:31 +02:00
committed by GitHub
3 changed files with 23 additions and 17 deletions
+9 -8
View File
@@ -117,13 +117,13 @@ class Env(object):
return self.ptop.get_password(node)
def is_reachable(self, node, port):
ip = neigh.ll6ping(port)
if not ip:
return False
ip = neigh.ll6ping(port)
if not ip:
return False
return util.is_reachable(ip, self, self.get_password(node))
return util.is_reachable(ip, self, self.get_password(node))
def attach(self, node, port="mgmt", protocol=None, test_reset=True, username = None, password = None):
def attach(self, node, port="mgmt", protocol=None, test_reset=True, username=None, password=None):
"""Attach to node on port using protocol."""
name = node
@@ -133,7 +133,6 @@ class Env(object):
else:
mapping = None
# Precedence:
# 1. Caller specifies `protocol`
# 2. User specifies `-t` when executing test
@@ -159,8 +158,10 @@ class Env(object):
if protocol == "netconf":
dev = netconf.Device(name,
location=netconf.Location(cport, mgmtip,
username,password),
location=netconf.Location(cport,
mgmtip,
username,
password),
mapping=mapping,
yangdir=self.args.yangdir)
if test_reset:
+2 -4
View File
@@ -26,16 +26,14 @@ class Location:
def xpath_to_uri(xpath, extra=None):
"""Convert xpath to HTTP URI"""
# If the xpath has a
pattern = r'\[(.*?)=["\'](.*?)["\']\]'
matches = re.findall(pattern, xpath)
uri_path = xpath
if matches:
for key, value in matches:
# replace [key=value] with =value
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', xpath)
else:
uri_path = xpath
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', uri_path)
# Append extra if provided
if extra is not None:
+12 -5
View File
@@ -30,7 +30,7 @@ class Test:
self.out.flush()
return self
def __exit__(self, _, e, __):
def __exit__(self, t, e, tb):
now = datetime.datetime.now().strftime("%F %T")
self.out.write(f"# Exiting ({now})\n")
self.out.flush()
@@ -40,12 +40,16 @@ class Test:
if not e:
self._not_ok("Missing explicit test result\n")
else:
if type(e) in (TestPass, TestSkip):
if t in (TestPass, TestSkip):
self.out.write(f"{self.steps}..{self.steps}\n")
self.out.flush()
raise SystemExit(0)
traceback.print_exception(e, file=self.commenter)
if t is AssertionError:
traceback.print_tb(tb, file=self.commenter)
self.out.write(f"{str(e)}\n")
self.out.flush()
else:
traceback.print_exception(e, file=self.commenter)
if type(e) is subprocess.CalledProcessError:
print("Failing subprocess stdout:\n", e.stdout)
@@ -95,7 +99,10 @@ class Test:
def skip(self):
raise TestSkip()
def fail(self):
def fail(self, message=None):
if message:
self.out.write(f"# {message}\n")
self.out.flush()
raise TestFail()