2 # Write sqlite entries for test reports in the build farm
3 # Copyright (C) 2007-2010 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2007-2010 Andrew Bartlett <abartlet@samba.org>
5 # Published under the GNU GPL
7 """Script to parse build farm log files from the data directory, import
8 them into the database, add links to the oldrevs/ directory and send
9 some mail chastising the possible culprits when the build fails, based
13 from buildfarm import data
14 from buildfarm.sqldb import StormCachingBuildFarm
15 from email.mime.text import MIMEText
20 parser = optparse.OptionParser("import-and-analyse [options]")
21 parser.add_option("--dry-run", help="Will cause the script to send output to stdout instead of to sendmail.", action="store_true")
22 parser.add_option("--verbose", help="Be verbose", action="count")
24 (opts, args) = parser.parse_args()
26 buildfarm = StormCachingBuildFarm()
31 def check_and_send_mails(tree, host, compiler, cur, old):
32 t = buildfarm.trees[tree]
34 (cur_rev, cur_rev_timestamp) = cur.revision_details()
35 cur_status = cur.status()
37 (old_rev, old_rev_timestamp) = old.revision_details()
38 old_status = old.status()
40 if not cur_status.regressed_since(old_status):
42 print "... hasn't regressed since %s: %s" % (old_rev, old_status)
48 for rev in t.get_branch().log(from_rev=cur.rev, exclude_revs=set([old.rev])):
49 recipients.add(rev.author)
50 recipients.add(rev.committer)
57 """ % (rev.revision, rev.author, rev.committer, rev.message)
60 Broken build for tree %(tree)s on host %(host)s with compiler %(compiler)s
62 Tree %(tree)s is %(scm)s branch %(branch)s.
64 Build status for new revision %(cur_rev)s is %(cur_status)s
65 Build status for old revision %(old_rev)s was %(old_status)s
67 See http://build.samba.org/?function=View+Build;host=%(host)s;tree=%(tree)s;compiler=%(compiler)s
69 The build may have been broken by one of the following commits:
72 """ % {"tree": tree, "host": host, "compiler": compiler, "change_log": change_log, "scm": t.scm, "branch": t.branch,
73 "cur_rev": cur_rev, "old_rev": old_rev, "cur_status": cur_status, "old_status": old_status }
76 msg["Subject"] = "BUILD of %s:%s BROKEN on %s with %s AT REVISION %s" % (tree, t.branch, host, compiler, cur_rev)
77 msg["From"] = "\"Build Farm\" <build@samba.org>"
78 msg["To"] = ",".join(recipients.keys())
80 smtp.send(msg["From"], [msg["To"]], msg.as_string())
85 for build in buildfarm.get_new_builds():
87 print "Processing %s..." % build,
90 buildfarm.builds.upload_build(build)
92 (rev, rev_timestamp) = build.revision_details()
95 print str(build.status())
99 # Perhaps this is a dry run and rev is not in the database yet?
100 prev_rev = buildfarm.builds.get_latest_revision(build.tree, build.host, build.compiler)
102 prev_rev = buildfarm.builds.get_previous_revision(build.tree, build.host, build.compiler, rev)
103 except data.NoSuchBuildError:
104 if opts.verbose >= 1:
105 print "Unable to find previous build for %s,%s,%s" % (build.tree, build.host, build.compiler)
106 # Can't send a nastygram until there are 2 builds..
109 prev_build = buildfarm.get_build(build.tree, build.host, build.compiler, prev_rev)
110 except data.NoSuchBuildError:
111 if opts.verbose >= 1:
112 print "Previous build %s has disappeared" % prev_build
114 check_and_send_mails(build.tree, build.host, build.compiler, build, prev_build)
117 # When the new web script is introduced, kill the build here: