Skip to content

Commit

Permalink
Permit to have ser2net on a different worker
Browse files Browse the repository at this point in the history
ser2net could be on a different host than where lava-worker ran.
So add a worker: option to permit to specify where it is.

Signed-off-by: Corentin LABBE <[email protected]>
  • Loading branch information
montjoie committed Nov 17, 2023
1 parent 54e5bd9 commit d4167d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ boards:
devpath: the UDEV devpath to this uart for UART without serial number
interfacenum: (optional) The interfacenumber of the serial. (Used with two serial in one device)
use_ser2net: True/False (Deprecated, ser2net is the default uart handler)
worker: (optional) an host/IP where ser2net is running
ser2net_keepopen: True/False (optional) Use the recent ser2net keepopen
ser2net_options: (optional) A list of ser2net options to add
- option1
Expand Down
43 changes: 34 additions & 9 deletions lavalab-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
""")

template_device_ser2net = string.Template("""
{% set connection_command = 'telnet 127.0.0.1 ${port}' %}
{% set connection_command = 'telnet ${telnet_host} ${port}' %}
""")

ser2net_dict = {}
Expand Down Expand Up @@ -740,16 +740,41 @@ def main():
if not use_ser2net and not "connection_command" in board:
use_ser2net = True
if use_ser2net:
if not worker_name in ser2net_ports:
ser2net_ports[worker_name] = ser2net_port_start
fp = open("%s/ser2net.yaml" % workerdir, "a")
if "worker" in uart:
worker_ser2net = uart["worker"]
telnet_host = worker_ser2net
else:
worker_ser2net = worker_name
telnet_host = "127.0.0.1"
ser2netdir = "output/%s/%s" % (host, worker_ser2net)
if not os.path.isdir(ser2netdir):
os.mkdir(ser2netdir)
if (not "bind_dev" in slave or not slave["bind_dev"]) and worker_ser2net == worker_name:
dockcomp_add_device(dockcomp, worker_name, "/dev/%s:/dev/%s" % (board_name, board_name))
udev_line = 'SUBSYSTEM=="tty", ATTRS{idVendor}=="%04x", ATTRS{idProduct}=="%04x",' % (idvendor, idproduct)
if "serial" in uart:
udev_line += 'ATTRS{serial}=="%s", ' % board["uart"]["serial"]
if "devpath" in uart:
udev_line += 'ATTRS{devpath}=="%s", ' % board["uart"]["devpath"]
if "interfacenum" in uart:
udev_line += 'ENV{ID_USB_INTERFACE_NUM}=="%s", ' % board["uart"]["interfacenum"]
udev_line += 'MODE="0664", OWNER="uucp", SYMLINK+="%s"\n' % board_name
udevdir = "output/%s/%s/udev" % (host, worker_ser2net)
if not os.path.isdir(udevdir):
os.mkdir(udevdir)
fp = open("%s/99-lavaworker-udev.rules" % udevdir, "a")
fp.write(udev_line)
fp.close()
if not worker_ser2net in ser2net_ports:
ser2net_ports[worker_ser2net] = ser2net_port_start
fp = open("%s/ser2net.yaml" % ser2netdir, "a")
fp.write("%YAML 1.1\n---\n")
fp.close()
device_line += template_device_ser2net.substitute(port=ser2net_ports[worker_name])
device_line += template_device_ser2net.substitute(port=ser2net_ports[worker_ser2net], telnet_host=telnet_host)
# YAML version
fp = open("%s/ser2net.yaml" % workerdir, "a")
fp.write("connection: &con%d\n" % ser2net_ports[worker_name])
fp.write(" accepter: telnet(rfc2217),tcp,%d\n" % ser2net_ports[worker_name])
fp = open("%s/ser2net.yaml" % ser2netdir, "a")
fp.write("connection: &con%d\n" % ser2net_ports[worker_ser2net])
fp.write(" accepter: telnet(rfc2217),tcp,%d\n" % ser2net_ports[worker_ser2net])
fp.write(" enable: on\n")
if ser2net_keepopen:
ser2net_yaml_line= " connector: keepopen(retry-time=2000,discard-badwrites),serialdev,/dev/%s,%dn81,local" % (board_name, baud)
Expand All @@ -762,7 +787,7 @@ def main():
fp.write(ser2net_yaml_line)
fp.write(" options:\n")
fp.write(" max-connections: 10\n")
ser2net_ports[worker_name] += 1
ser2net_ports[worker_ser2net] += 1
fp.close()
if "connection_command" in board:
connection_command = board["connection_command"]
Expand Down

0 comments on commit d4167d9

Please sign in to comment.