First stab at the remctl script to handle new build queue submission
authorEvan Broder <broder@mit.edu>
Thu, 26 Nov 2009 04:43:12 +0000 (23:43 -0500)
committerEvan Broder <broder@mit.edu>
Thu, 26 Nov 2009 04:43:12 +0000 (23:43 -0500)
for the Invirtibuilder.

svn path=/trunk/packages/invirt-dev/; revision=2563

invirt-submit-build [new file with mode: 0755]

diff --git a/invirt-submit-build b/invirt-submit-build
new file mode 100755 (executable)
index 0000000..caa949f
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+"""Validate and add a new item to the Invirt build queue.
+
+This script, intended to be invoked by remctl, first validates the
+build submitted parameters, and then adds a new item to the
+Invirtibuilder build queue, triggering the Invirtibuilder to start the
+build.
+
+The expected arguments are
+
+  pocket package commit
+
+This script will also automatically extract the Kerberos principal
+used to submit the job, and include that in the queue file for records
+keeping.
+"""
+
+
+import datetime
+import os
+import sys
+import tempfile
+import uuid
+
+import invirt.builder as b
+
+
+def main():
+    pocket, package, commit = sys.argv[1:4]
+    principal = os.environ['REMOTE_USER']
+    request_time = datetime.datetime.utcnow()
+    q_path = os.path.join(b._QUEUE_DIR,
+                          '%s_%s' % (request_time.strftime('%Y%m%d%H%M%S'),
+                                     uuid.uuid4()))
+
+    try:
+        validateBuild(pocket, package, commit)
+    except b.InvalidBuild, e:
+        print >>sys.stderr, "E: %s" % e
+        sys.exit(1)
+
+    # To keep from triggering the Invirtibuilder before we've actually
+    # written the file out, first write the queue entry to a temporary
+    # file, and then move it into the queue directory.
+    q = tempfile.NamedTemporaryFile(delete=False)
+    print >>q, "%s %s %s %s" % (pocket, package, commit, principal)
+    os.rename(q.name, q_path)
+
+
+if __name__ == '__main__':
+    main()