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.build import (
18 from buildfarm import BuildFarm
19 from buildfarm.web import build_uri
20 from email.mime.text import MIMEText
25 parser = optparse.OptionParser("import-and-analyse [options]")
26 parser.add_option("--dry-run", help="Will cause the script to send output to stdout instead of to sendmail.", action="store_true")
27 parser.add_option("--verbose", help="Be verbose", action="count")
29 (opts, args) = parser.parse_args()
31 resource.setrlimit(resource.RLIMIT_RSS, (300000, 300000))
32 resource.setrlimit(resource.RLIMIT_DATA, (300000, 300000))
34 buildfarm = BuildFarm(timeout=40.0)
39 def check_and_send_mails(cur, old):
41 if cur.tree is "waf-svn":
42 # no point sending emails, as the email addresses are invalid
46 if cur.tree is "samba_3_waf":
47 # no emails for this until it stabilises a bit
50 t = buildfarm.trees[cur.tree]
51 diff = BuildDiff(t, old, cur)
53 if not diff.is_regression():
55 print "... hasn't regressed since %s: %s" % (diff.old_rev, diff.old_status)
61 for rev in diff.revisions():
62 recipients.add(rev.author)
63 recipients.add(rev.committer)
70 """ % (rev.revision, rev.author, rev.committer, rev.message)
73 Broken build for tree %(tree)s on host %(host)s with compiler %(compiler)s
75 Tree %(tree)s is %(scm)s branch %(branch)s.
77 Build status for new revision %(cur_rev)s is %(cur_status)s
78 Build status for old revision %(old_rev)s was %(old_status)s
82 The build may have been broken by one of the following commits:
86 "tree": cur.tree, "host": cur.host, "compiler": cur.compiler,
87 "change_log": change_log,
90 "cur_rev": diff.new_rev,
91 "old_rev": diff.old_rev,
92 "cur_status": diff.new_status,
93 "old_status": diff.old_status,
94 "build_link": build_uri("http://build.samba.org/build.cgi", cur)
98 msg["Subject"] = "BUILD of %s:%s BROKEN on %s with %s AT REVISION %s" % (cur.tree, t.branch, cur.host, cur.compiler, diff.new_rev)
99 msg["From"] = "\"Build Farm\" <build@samba.org>"
100 msg["To"] = ",".join(recipients)
102 smtp.sendmail(msg["From"], [msg["To"]], msg.as_string())
104 print msg.as_string()
107 for build in buildfarm.get_new_builds():
108 if build in buildfarm.builds:
114 build = buildfarm.builds.upload_build(old_build)
115 except MissingRevisionInfo:
116 print "No revision info in %r, skipping" % build
120 rev = build.revision_details()
121 except MissingRevisionInfo:
122 print "No revision info in %r, skipping" % build
125 if opts.verbose >= 2:
126 print "%s... " % build,
127 print str(build.status())
131 # Perhaps this is a dry run and rev is not in the database yet?
132 prev_build = buildfarm.builds.get_latest_build(build.tree, build.host, build.compiler)
134 prev_build = buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, rev)
135 except NoSuchBuildError:
136 if opts.verbose >= 1:
137 print "Unable to find previous build for %s,%s,%s" % (build.tree, build.host, build.compiler)
138 # Can't send a nastygram until there are 2 builds..
140 check_and_send_mails(build, prev_build)