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.
This commit is contained in:
Mattias Walström
2024-09-17 08:27:23 +02:00
parent be6554f327
commit 35a909edf0
4 changed files with 12 additions and 9 deletions
+9 -5
View File
@@ -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)
+1 -1
View File
@@ -92,8 +92,8 @@ class NccGetSchemaReply:
class Location:
interface: str
host: str
username: str
password: str
username: str = "admin"
port: int = 830
+1 -1
View File
@@ -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):
+1 -2
View File
@@ -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: