aboutsummaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorPaul Sokolovsky <paul.sokolovsky@linaro.org>2012-04-20 17:29:45 +0300
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2012-04-20 17:29:45 +0300
commit59b2c46e72e8457d80853d0ac9b98f7679c06673 (patch)
treee86654b824ae4a84b678bcd1e43c1cffc0f8cb6f /node
parent76a6c463850597cadf5176bda7f08f810e09e8c9 (diff)
Add a python script to validate build config and environment.
Diffstat (limited to 'node')
-rwxr-xr-xnode/prepare_build_config.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/node/prepare_build_config.py b/node/prepare_build_config.py
new file mode 100755
index 0000000..7188a10
--- /dev/null
+++ b/node/prepare_build_config.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+import sys
+import os
+import base64
+import re
+import pipes
+
+
+SLAVE_TYPE_FILE = "/var/run/build-tools/slave-type"
+SLAVE_TYPE_RESTRICTED = "Natty Release 64bit Instance Store - private builds"
+
+class BuildConfigMismatchException(Exception):
+ pass
+
+def shell_unquote(s):
+ # Primitive implementation, we should
+ if s[0] == '"' and s[-1] == '"':
+ return s[1:-1]
+ if s[0] == "'" and s[-1] == "'":
+ return s[1:-1]
+ return s
+
+def get_slave_type():
+ slave_type = ""
+ try:
+ slave_type = open(SLAVE_TYPE_FILE).read()
+ except:
+ pass
+ return slave_type
+
+def validate_config(config, slave_type):
+ """Validate various constraints on the config params and overall
+ environment."""
+ full_job_name = os.environ.get("JOB_NAME")
+ owner, job_subname = full_job_name.split("_", 1)
+
+ # Deduce parameter "categories" which we can directly match against each other
+ if slave_type == SLAVE_TYPE_RESTRICTED:
+ slave_type_cat = "restricted"
+ else:
+ slave_type_cat = "normal"
+
+ if owner in ["linaro-android-private", "linaro-android-restricted"]:
+ owner_cat = "restricted"
+ else:
+ owner_cat = "normal"
+
+ if config.get("BUILD_TYPE", "build-android") in ["build-android-private", "build-android-restricted"]:
+ build_type_cat = "restricted"
+ else:
+ build_type_cat = "normal"
+
+ # Now, process few most expected mismatches in adhox way, to provide better error messages
+ if slave_type_cat == "restricted" and owner_cat != "restricted":
+ raise BuildConfigMismatchException("Only jobs owned by ~linaro-android-restricted may run on this build slave type")
+
+ if owner_cat == "restricted" and build_type_cat != "restricted":
+ raise BuildConfigMismatchException("Jobs owned by ~linaro-android-restricted must use BUILD_TYPE=build-android-restricted")
+
+ # Finally, generic mismatch detection
+ if slave_type_cat != owner_cat or slave_type_cat != build_type_cat:
+ raise BuildConfigMismatchException("Incompatible slave type, job owner and build type")
+
+
+def convert_config_to_shell(config_text):
+ config = {}
+ out = open("build_config", "w")
+
+ for l in cfg.split("\n"):
+ l = l.strip()
+ if not l or l[0] == "#":
+ continue
+ if not re.match(r"[A-Za-z][A-Za-z0-9_]*=", l):
+ print "Invalid build config syntax: " + l
+ sys.exit(1)
+ var, val = l.split("=", 1)
+ val = shell_unquote(val)
+ config[var] = val
+ print "%s=%s" % (var, pipes.quote(val))
+
+
+if __name__ == "__main__":
+ config_text = base64.b64decode(sys.argv[1])
+ config = convert_config_to_shell(config_text, get_slave_type())
+ try:
+ validate_config(config)
+ except BuildConfigMismatchException, e:
+ print str(e)
+ sys.exit(1)