From 866fbb4ed9f7bcc86900ab48f400a29d59013fa9 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Mon, 7 Jan 2019 16:42:10 +0100 Subject: lavalab-gen.py: prevent duplication of device map If two qemu with KVM enabled are on the same node, the device map "/dev/kvm:/dev/kvm" will be present twice. This patch adds an helper for preventing this. This will also clean the code later which adds serial device. --- lavalab-gen.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lavalab-gen.py b/lavalab-gen.py index 1d91f23..e814e5e 100755 --- a/lavalab-gen.py +++ b/lavalab-gen.py @@ -66,6 +66,17 @@ template_settings_conf = string.Template(""" } """) +def dockcomp_add_device(dockcomp, worker_name, devicemap): + if "devices" in dockcomp["services"][worker_name]: + dc_devices = dockcomp["services"][worker_name]["devices"] + else: + dockcomp["services"][worker_name]["devices"] = [] + dc_devices = dockcomp["services"][worker_name]["devices"] + for dmap in dc_devices: + if dmap == devicemap: + return + dc_devices.append(devicemap) + def usage(): print("%s [boardsfile.yaml]" % sys.argv[0]) @@ -424,12 +435,7 @@ def main(): if "kvm" in board: use_kvm = board["kvm"] if use_kvm: - if "devices" in dockcomp["services"][worker_name]: - dc_devices = dockcomp["services"][worker_name]["devices"] - else: - dockcomp["services"][worker_name]["devices"] = [] - dc_devices = dockcomp["services"][worker_name]["devices"] - dc_devices.append("/dev/kvm:/dev/kvm") + dockcomp_add_device(dockcomp, worker_name, "/dev/kvm:/dev/kvm") # board specific hacks if devicetype == "qemu" and not use_kvm: device_line += "{% set no_kvm = True %}\n" @@ -457,13 +463,8 @@ def main(): fp = open("output/%s/udev/99-lavaworker-udev.rules" % host, "a") fp.write(udev_line) fp.close() - if "devices" in dockcomp["services"][worker_name]: - dc_devices = dockcomp["services"][worker_name]["devices"] - else: - dockcomp["services"][worker_name]["devices"] = [] - dc_devices = dockcomp["services"][worker_name]["devices"] if not "bind_dev" in slave: - dc_devices.append("/dev/%s:/dev/%s" % (board_name, board_name)) + dockcomp_add_device(dockcomp, worker_name, "/dev/%s:/dev/%s" % (board_name, board_name)) use_conmux = False use_ser2net = False use_screen = False -- cgit 1.2.3-korg