phase1: refactor worker parsing
authorThibaut VARÈNE <hacks@slashdirt.org>
Thu, 27 Oct 2022 12:32:30 +0000 (14:32 +0200)
committerPetr Štetiar <ynezz@true.cz>
Mon, 15 May 2023 15:36:01 +0000 (17:36 +0200)
Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
phase1/master.cfg

index fdbb2cdc6bd95969fac2e9fb6c76b24c3e684439..53d20986a3b69b9c8c7b5b09abf6f055ab83691b 100644 (file)
@@ -131,27 +131,39 @@ c['buildbotURL'] = inip1.get("buildbot_url")
 c['workers'] = []
 NetLocks = dict()
 
+def ini_parse_workers(section):
+       name = section.get("name")
+       password = section.get("password")
+       phase = section.getint("phase")
+
+       if not name or not password or not phase == 1:
+               log.msg("invalid worker configuration ignored: {}".format(repr(section)))
+               return
+
+       sl_props = { 'dl_lock':None, 'ul_lock':None }
+       if "dl_lock" in section:
+               lockname = section.get("dl_lock")
+               sl_props['dl_lock'] = lockname
+               if lockname not in NetLocks:
+                       NetLocks[lockname] = locks.MasterLock(lockname)
+       if "ul_lock" in section:
+               lockname = section.get("ul_lock")
+               sl_props['ul_lock'] = lockname
+               if lockname not in NetLocks:
+                       NetLocks[lockname] = locks.MasterLock(lockname)
+
+       log.msg("Configured worker: {}".format(name))
+       c['workers'].append(Worker(name, password, max_builds = 1, properties = sl_props))
+
+
 for section in ini.sections():
        if section.startswith("branch "):
                ini_parse_branch(ini[section])
 
        if section.startswith("worker "):
-               if ini.has_option(section, "name") and ini.has_option(section, "password") and \
-                  (not ini.has_option(section, "phase") or ini.getint(section, "phase") == 1):
-                       sl_props = { 'dl_lock':None, 'ul_lock':None }
-                       name = ini.get(section, "name")
-                       password = ini.get(section, "password")
-                       if ini.has_option(section, "dl_lock"):
-                               lockname = ini.get(section, "dl_lock")
-                               sl_props['dl_lock'] = lockname
-                               if lockname not in NetLocks:
-                                       NetLocks[lockname] = locks.MasterLock(lockname)
-                       if ini.has_option(section, "ul_lock"):
-                               lockname = ini.get(section, "ul_lock")
-                               sl_props['ul_lock'] = lockname
-                               if lockname not in NetLocks:
-                                       NetLocks[lockname] = locks.MasterLock(lockname)
-                       c['workers'].append(Worker(name, password, max_builds = 1, properties = sl_props))
+               ini_parse_workers(ini[section])
+
+branchNames = [branches[b]["name"] for b in branches]
 
 c['protocols'] = {'pb': {'port': pb_port}}
 
@@ -255,8 +267,6 @@ c['prioritizeBuilders'] = prioritizeBuilders
 
 ####### CHANGESOURCES
 
-branchNames = [branches[b]["name"] for b in branches]
-
 # find targets
 targets = set()