[buildbot] phase1: cleanup ini accessors

LEDE Commits lede-commits at lists.infradead.org
Mon May 15 08:38:53 PDT 2023


ynezz pushed a commit to buildbot.git, branch master:
https://git.openwrt.org/a9dbffef274a8af33757165f3e65cbf2536606c5

commit a9dbffef274a8af33757165f3e65cbf2536606c5
Author: Thibaut VARÈNE <hacks at slashdirt.org>
AuthorDate: Wed Oct 19 19:13:43 2022 +0200

    phase1: cleanup ini accessors
    
    Signed-off-by: Thibaut VARÈNE <hacks at slashdirt.org>
---
 phase1/master.cfg | 119 ++++++++++++++++++++++--------------------------------
 1 file changed, 48 insertions(+), 71 deletions(-)

diff --git a/phase1/master.cfg b/phase1/master.cfg
index 3dd62cc..56d0a1f 100644
--- a/phase1/master.cfg
+++ b/phase1/master.cfg
@@ -51,6 +51,11 @@ if not os.path.exists("twistd.pid"):
 ini = configparser.ConfigParser()
 ini.read(os.getenv("BUILDMASTER_CONFIG", "./config.ini"))
 
+if "general" not in ini or "phase1" not in ini or "rsync" not in ini:
+	raise ValueError("Fix your configuration")
+
+inip1 = ini['phase1']
+
 # This is the dictionary that the buildmaster pays attention to. We also use
 # a shorter alias to save typing.
 c = BuildmasterConfig = {}
@@ -61,8 +66,8 @@ c = BuildmasterConfig = {}
 # installation's html.WebStatus home page (linked to the
 # 'titleURL') and is embedded in the title of the waterfall HTML page.
 
-c['title'] = ini.get("general", "title")
-c['titleURL'] = ini.get("general", "title_url")
+c['title'] = ini['general'].get("title")
+c['titleURL'] = ini['general'].get("title_url")
 
 # the 'buildbotURL' string should point to the location where the buildbot's
 # internal web server (usually the html.WebStatus page) is visible. This
@@ -70,7 +75,7 @@ c['titleURL'] = ini.get("general", "title_url")
 # with an externally-visible host name which the buildbot cannot figure out
 # without some help.
 
-c['buildbotURL'] = ini.get("phase1", "buildbot_url")
+c['buildbotURL'] = inip1.get("buildbot_url")
 
 ####### BUILDWORKERS
 
@@ -78,11 +83,6 @@ c['buildbotURL'] = ini.get("phase1", "buildbot_url")
 # a Worker object, specifying a unique worker name and password.  The same
 # worker name and password must be configured on the worker.
 
-worker_port = 9989
-
-if ini.has_option("phase1", "port"):
-	worker_port = ini.get("phase1", "port")
-
 c['workers'] = []
 NetLocks = dict()
 
@@ -118,10 +118,9 @@ for section in ini.sections():
 					raise ValueError('max_builds must be 1 with shared workdir!')
 			c['workers'].append(Worker(name, password, max_builds = max_builds, properties = sl_props))
 
-# 'workerPortnum' defines the TCP port to listen on for connections from workers.
-# This must match the value configured into the buildworkers (with their
-# --master option)
-c['protocols'] = {'pb': {'port': worker_port}}
+# PB port can be either a numeric port or a connection string
+pb_port = inip1.get("port") or 9989
+c['protocols'] = {'pb': {'port': pb_port}}
 
 # coalesce builds
 c['collapseRequests'] = True
@@ -211,58 +210,40 @@ c['prioritizeBuilders'] = prioritizeBuilders
 
 ####### CHANGESOURCES
 
-work_dir = os.path.abspath(ini.get("general", "workdir") or ".")
+work_dir = os.path.abspath(ini['general'].get("workdir", "."))
 scripts_dir = os.path.abspath("../scripts")
-tree_expire = 0
 
 cc_command = "gcc"
 cxx_command = "g++"
 
-config_seed = ""
-
-if ini.has_option("phase1", "expire"):
-	tree_expire = ini.getint("phase1", "expire")
-
-if ini.has_option("phase1", "config_seed"):
-	config_seed = ini.get("phase1", "config_seed")
+tree_expire = inip1.getint("expire", 0)
+config_seed = inip1.get("config_seed", "")
 
-repo_url = ini.get("repo", "url")
-repo_branch = "master"
+repo_url = ini['repo'].get("url")
+repo_branch = ini['repo'].get("branch", "master")
 
-if ini.has_option("repo", "branch"):
-	repo_branch = ini.get("repo", "branch")
-
-rsync_bin_url = ini.get("rsync", "binary_url")
-rsync_bin_key = ini.get("rsync", "binary_password")
+rsync_bin_url = ini['rsync'].get("binary_url")
+rsync_bin_key = ini['rsync'].get("binary_password")
 rsync_bin_defopts = ["-v", "-4", "--timeout=120"]
 
 if rsync_bin_url.find("::") > 0 or rsync_bin_url.find("rsync://") == 0:
 	rsync_bin_defopts += ["--contimeout=20"]
 
-rsync_src_url = None
-rsync_src_key = None
+rsync_src_url = ini['rsync'].get("source_url")
+rsync_src_key = ini['rsync'].get("source_password")
 rsync_src_defopts = ["-v", "-4", "--timeout=120"]
 
-if ini.has_option("rsync", "source_url"):
-	rsync_src_url = ini.get("rsync", "source_url")
-	rsync_src_key = ini.get("rsync", "source_password")
-
-	if rsync_src_url.find("::") > 0 or rsync_src_url.find("rsync://") == 0:
-		rsync_src_defopts += ["--contimeout=20"]
+if rsync_src_url.find("::") > 0 or rsync_src_url.find("rsync://") == 0:
+	rsync_src_defopts += ["--contimeout=20"]
 
 usign_key = None
 usign_comment = "untrusted comment: " + repo_branch.replace("-", " ").title() + " key"
 
-if ini.has_option("usign", "key"):
-	usign_key = ini.get("usign", "key")
-
-if ini.has_option("usign", "comment"):
-	usign_comment = ini.get("usign", "comment")
+if ini.has_section("usign"):
+	usign_key = ini['usign'].get("key")
+	usign_comment = ini['usign'].get("comment", usign_comment)
 
-enable_kmod_archive = False
-
-if ini.has_option("phase1", "kmod_archive"):
-	enable_kmod_archive = ini.getboolean("phase1", "kmod_archive")
+enable_kmod_archive = inip1.getboolean("kmod_archive", False)
 
 
 # find targets
@@ -1362,9 +1343,9 @@ for target in targets:
 # pushed to these targets. buildbot/status/*.py has a variety to choose from,
 # including web pages, email senders, and IRC bots.
 
-if ini.has_option("phase1", "status_bind"):
+if "status_bind" in inip1:
 	c['www'] = {
-		'port': ini.get("phase1", "status_bind"),
+		'port': inip1.get("status_bind"),
 		'plugins': {
 			'waterfall_view': True,
 			'console_view': True,
@@ -1372,37 +1353,33 @@ if ini.has_option("phase1", "status_bind"):
 		}
 	}
 
-	if ini.has_option("phase1", "status_user") and ini.has_option("phase1", "status_password"):
+	if "status_user" in inip1 and "status_password" in inip1:
 		c['www']['auth'] = util.UserPasswordAuth([
-			(ini.get("phase1", "status_user"), ini.get("phase1", "status_password"))
+			(inip1.get("status_user"), inip1.get("status_password"))
 		])
 		c['www']['authz'] = util.Authz(
 			allowRules=[ util.AnyControlEndpointMatcher(role="admins") ],
-			roleMatchers=[ util.RolesFromUsername(roles=["admins"], usernames=[ini.get("phase1", "status_user")]) ]
+			roleMatchers=[ util.RolesFromUsername(roles=["admins"], usernames=[inip1.get("status_user")]) ]
 		)
 
 c['services'] = []
-if ini.has_option("irc", "host") and ini.has_option("irc", "nickname") and ini.has_option("irc", "channel"):
-	irc_host = ini.get("irc", "host")
-	irc_port = 6667
-	irc_chan = ini.get("irc", "channel")
-	irc_nick = ini.get("irc", "nickname")
-	irc_pass = None
-
-	if ini.has_option("irc", "port"):
-		irc_port = ini.getint("irc", "port")
-
-	if ini.has_option("irc", "password"):
-		irc_pass = ini.get("irc", "password")
-
-	irc = reporters.IRC(irc_host, irc_nick,
-		port = irc_port,
-		password = irc_pass,
-		channels = [ irc_chan ],
-		notify_events = [ 'exception', 'problem', 'recovery' ]
-	)
-
-	c['services'].append(irc)
+if ini.has_section("irc"):
+	iniirc = ini['irc']
+	irc_host = iniirc.get("host", None)
+	irc_port = iniirc.getint("port", 6667)
+	irc_chan = iniirc.get("channel", None)
+	irc_nick = iniirc.get("nickname", None)
+	irc_pass = iniirc.get("password", None)
+
+	if irc_host and irc_nick and irc_chan:
+		irc = reporters.IRC(irc_host, irc_nick,
+			port = irc_port,
+			password = irc_pass,
+			channels = [ irc_chan ],
+			notify_events = [ 'exception', 'problem', 'recovery' ]
+		)
+
+		c['services'].append(irc)
 
 c['revlink'] = util.RevlinkMatch([
 	r'https://git.openwrt.org/openwrt/(.*).git'




More information about the lede-commits mailing list