From 35a909edf0df893474adbfdc1181495435c65e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Wed, 11 Sep 2024 20:36:07 +0200 Subject: [PATCH] test: infamy: Make possible to override username and password This is now possible for SSH/RESTCONF/NETCONF, most useful with SSH and adding/modify users. --- test/infamy/env.py | 14 +++++++++----- test/infamy/netconf.py | 2 +- test/infamy/restconf.py | 2 +- test/infamy/ssh.py | 3 +-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/test/infamy/env.py b/test/infamy/env.py index 72c6e5a4..e8a50caa 100644 --- a/test/infamy/env.py +++ b/test/infamy/env.py @@ -74,7 +74,7 @@ class Env(object): def get_password(self, node): return self.ptop.get_password(node) - def attach(self, node, port, protocol=None, test_reset=True): + def attach(self, node, port, protocol=None, test_reset=True, username = None, password = None): """Attach to node on port using protocol.""" name = node @@ -94,7 +94,11 @@ class Env(object): random.seed(f"{sys.argv[0]}-{hseed}") protocol = random.choice(["netconf", "restconf"]) - password = self.get_password(node) + if password is None: + password = self.get_password(node) + if username is None: + username = "admin" + ctrl = self.ptop.get_ctrl() cport, _ = self.ptop.get_mgmt_link(ctrl, node) @@ -103,11 +107,10 @@ class Env(object): if not mgmtip: raise Exception(f"Failed, cannot find mgmt IP for {node}") - password = self.get_password(node) if protocol == "netconf": dev = netconf.Device(name, location=netconf.Location(cport, mgmtip, - password), + username,password), mapping=mapping, yangdir=self.args.yangdir) if test_reset: @@ -115,12 +118,13 @@ class Env(object): return dev if protocol == "ssh": - return ssh.Device(name, ssh.Location(mgmtip, password)) + return ssh.Device(name, ssh.Location(mgmtip, username, password)) if protocol == "restconf": dev = restconf.Device(name, location=restconf.Location(cport, mgmtip, + username, password), mapping=mapping, yangdir=self.args.yangdir) diff --git a/test/infamy/netconf.py b/test/infamy/netconf.py index c3d11ada..7bf5908b 100644 --- a/test/infamy/netconf.py +++ b/test/infamy/netconf.py @@ -92,8 +92,8 @@ class NccGetSchemaReply: class Location: interface: str host: str + username: str password: str - username: str = "admin" port: int = 830 diff --git a/test/infamy/restconf.py b/test/infamy/restconf.py index 0e1d7f0b..32eed443 100644 --- a/test/infamy/restconf.py +++ b/test/infamy/restconf.py @@ -20,8 +20,8 @@ warnings.simplefilter('ignore', InsecureRequestWarning) class Location: interface: str host: str + username: str password: str - username: str = "admin" port: int = 443 def xpath_to_uri(xpath, extra=None): diff --git a/test/infamy/ssh.py b/test/infamy/ssh.py index b7ae5a16..59bd4290 100644 --- a/test/infamy/ssh.py +++ b/test/infamy/ssh.py @@ -7,8 +7,8 @@ from . import env @dataclass class Location: host: str + username: str password: str - username: str = "admin" port: int = 22 @@ -16,7 +16,6 @@ class Device(object): def __init__(self, name: str, location: Location): self.name = name self.location = location - def __str__(self): nm = f"{self.name}" if env.ENV.ltop: