2 # run tests on all Samba subprojects and push to a git tree on success
3 # Copyright Andrew Tridgell 2010
4 # released under GNU GPL v3 or later
6 from subprocess import call, check_call,Popen, PIPE
7 import os, tarfile, sys, time
8 from optparse import OptionParser
11 from email.mime.text import MIMEText
12 from email.mime.base import MIMEBase
13 from email.mime.application import MIMEApplication
14 from email.mime.multipart import MIMEMultipart
15 from distutils.sysconfig import get_python_lib
18 os.environ["PYTHONUNBUFFERED"] = "1"
20 # This speeds up testing remarkably.
21 os.environ['TDB_NO_FSYNC'] = '1'
33 "samba-test-only" : ".",
34 "samba-systemkrb5" : ".",
37 "talloc" : "lib/talloc",
38 "replace" : "lib/replace",
39 "tevent" : "lib/tevent",
46 defaulttasks = [ "ctdb", "samba", "samba-xc", "samba-o3", "samba-ctdb", "samba-libs", "samba-static", "samba-systemkrb5", "ldb", "tdb", "talloc", "replace", "tevent", "pidl" ]
48 if os.environ.get("AUTOBUILD_SKIP_SAMBA_O3", "0") == "1":
49 defaulttasks.remove("samba-o3")
51 ctdb_configure_params = " --enable-developer --picky-developer ${PREFIX}"
52 samba_configure_params = " --picky-developer ${PREFIX} ${EXTRA_PYTHON} --with-profiling-data"
54 samba_libs_envvars = "PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH"
55 samba_libs_envvars += " PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig"
56 samba_libs_envvars += " ADDITIONAL_CFLAGS='-Wmissing-prototypes'"
57 samba_libs_configure_base = samba_libs_envvars + " ./configure --abi-check --enable-debug --picky-developer -C ${PREFIX} ${EXTRA_PYTHON}"
58 samba_libs_configure_libs = samba_libs_configure_base + " --bundled-libraries=NONE"
59 samba_libs_configure_samba = samba_libs_configure_base + " --bundled-libraries=!talloc,!pytalloc-util,!tdb,!pytdb,!ldb,!pyldb,!pyldb-util,!tevent,!pytevent"
61 if os.environ.get("AUTOBUILD_NO_EXTRA_PYTHON", "0") == "1":
64 extra_python = "--extra-python=/usr/bin/python3"
67 "ctdb" : [ ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
68 ("configure", "./configure " + ctdb_configure_params, "text/plain"),
69 ("make", "make all", "text/plain"),
70 ("install", "make install", "text/plain"),
71 ("test", "make autotest", "text/plain"),
72 ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
73 ("clean", "make clean", "text/plain") ],
75 # We have 'test' before 'install' because, 'test' should work without 'install'
76 "samba" : [ ("configure", "./configure.developer --with-selftest-prefix=./bin/ab" + samba_configure_params, "text/plain"),
77 ("make", "make -j", "text/plain"),
78 ("test", "make test FAIL_IMMEDIATELY=1", "text/plain"),
79 ("install", "make install", "text/plain"),
80 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
81 ("clean", "make clean", "text/plain") ],
83 "samba-test-only" : [ ("configure", "./configure.developer --with-selftest-prefix=./bin/ab --abi-check-disable" + samba_configure_params, "text/plain"),
84 ("make", "make -j", "text/plain"),
85 ("test", "make test FAIL_IMMEDIATELY=1 TESTS=${TESTS}", "text/plain") ],
87 # Test cross-compile infrastructure
88 "samba-xc" : [ ("configure-native", "./configure.developer --with-selftest-prefix=./bin/ab" + samba_configure_params, "text/plain"),
89 ("configure-cross-execute", "./configure.developer -b ./bin-xe --cross-compile --cross-execute=script/identity_cc.sh" \
90 " --cross-answers=./bin-xe/cross-answers.txt --with-selftest-prefix=./bin-xe/ab" + samba_configure_params, "text/plain"),
91 ("configure-cross-answers", "./configure.developer -b ./bin-xa --cross-compile" \
92 " --cross-answers=./bin-xe/cross-answers.txt --with-selftest-prefix=./bin-xa/ab" + samba_configure_params, "text/plain"),
93 ("compare-results", "script/compare_cc_results.py ./bin/c4che/default.cache.py ./bin-xe/c4che/default.cache.py ./bin-xa/c4che/default.cache.py", "text/plain")],
95 # test build with -O3 -- catches extra warnings and bugs
96 "samba-o3" : [ ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
97 ("configure", "ADDITIONAL_CFLAGS='-O3' ./configure.developer --with-selftest-prefix=./bin/ab --abi-check-disable" + samba_configure_params, "text/plain"),
98 ("make", "make -j", "text/plain"),
99 ("test", "make quicktest FAIL_IMMEDIATELY=1 TESTS='\(ad_dc\)'", "text/plain"),
100 ("install", "make install", "text/plain"),
101 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
102 ("clean", "make clean", "text/plain") ],
104 "samba-ctdb" : [ ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
106 # make sure we have tdb around:
107 ("tdb-configure", "cd lib/tdb && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
108 ("tdb-make", "cd lib/tdb && make", "text/plain"),
109 ("tdb-install", "cd lib/tdb && make install", "text/plain"),
112 # build samba with cluster support (also building ctdb):
113 ("samba-configure", "PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH} ./configure.developer --picky-developer ${PREFIX} --with-selftest-prefix=./bin/ab --with-cluster-support --bundled-libraries=!tdb", "text/plain"),
114 ("samba-make", "make", "text/plain"),
115 ("samba-check", "./bin/smbd -b | grep CLUSTER_SUPPORT", "text/plain"),
116 ("samba-install", "make install", "text/plain"),
117 ("ctdb-check", "test -e ${PREFIX_DIR}/sbin/ctdbd", "text/plain"),
120 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
121 ("clean", "make clean", "text/plain"),
122 ("ctdb-clean", "cd ./ctdb && make clean", "text/plain") ],
125 ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
126 ("talloc-configure", "cd lib/talloc && " + samba_libs_configure_libs, "text/plain"),
127 ("talloc-make", "cd lib/talloc && make", "text/plain"),
128 ("talloc-install", "cd lib/talloc && make install", "text/plain"),
130 ("tdb-configure", "cd lib/tdb && " + samba_libs_configure_libs, "text/plain"),
131 ("tdb-make", "cd lib/tdb && make", "text/plain"),
132 ("tdb-install", "cd lib/tdb && make install", "text/plain"),
134 ("tevent-configure", "cd lib/tevent && " + samba_libs_configure_libs, "text/plain"),
135 ("tevent-make", "cd lib/tevent && make", "text/plain"),
136 ("tevent-install", "cd lib/tevent && make install", "text/plain"),
138 ("ldb-configure", "cd lib/ldb && " + samba_libs_configure_libs, "text/plain"),
139 ("ldb-make", "cd lib/ldb && make", "text/plain"),
140 ("ldb-install", "cd lib/ldb && make install", "text/plain"),
142 ("nondevel-configure", "./configure ${PREFIX}", "text/plain"),
143 ("nondevel-make", "make -j", "text/plain"),
144 ("nondevel-check", "./bin/smbd -b | grep WITH_NTVFS_FILESERVER && exit 1; exit 0", "text/plain"),
145 ("nondevel-install", "make install", "text/plain"),
146 ("nondevel-dist", "make dist", "text/plain"),
148 # retry with all modules shared
149 ("allshared-distclean", "make distclean", "text/plain"),
150 ("allshared-configure", samba_libs_configure_samba + " --with-shared-modules=ALL", "text/plain"),
151 ("allshared-make", "make -j", "text/plain")],
154 ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
155 # build with all modules static
156 ("allstatic-configure", "./configure.developer " + samba_configure_params + " --with-static-modules=ALL", "text/plain"),
157 ("allstatic-make", "make -j", "text/plain"),
159 # retry without any required modules
160 ("none-distclean", "make distclean", "text/plain"),
161 ("none-configure", "./configure.developer " + samba_configure_params + " --with-static-modules=!FORCED,!DEFAULT --with-shared-modules=!FORCED,!DEFAULT", "text/plain"),
162 ("none-make", "make -j", "text/plain"),
164 # retry with nonshared smbd and smbtorture
165 ("nonshared-distclean", "make distclean", "text/plain"),
166 ("nonshared-configure", "./configure.developer " + samba_configure_params + " --bundled-libraries=talloc,tdb,pytdb,ldb,pyldb,tevent,pytevent --with-static-modules=ALL --nonshared-binary=smbtorture,smbd/smbd", "text/plain"),
167 ("nonshared-make", "make -j", "text/plain")],
169 "samba-systemkrb5" : [
170 ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
171 ("configure", "./configure.developer " + samba_configure_params + " --with-system-mitkrb5 --without-ad-dc", "text/plain"),
172 ("make", "make -j", "text/plain"),
173 # we currently cannot run a full make test, a limited list of tests could be run
174 # via "make test TESTS=sometests"
175 ("test", "make test FAIL_IMMEDIATELY=1 TESTS='samba3.*ktest'", "text/plain"),
176 ("install", "make install", "text/plain"),
177 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
178 ("clean", "make clean", "text/plain")
184 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
185 ("configure", "./configure --enable-developer -C ${PREFIX} ${EXTRA_PYTHON}", "text/plain"),
186 ("make", "make", "text/plain"),
187 ("install", "make install", "text/plain"),
188 ("test", "make test", "text/plain"),
189 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
190 ("distcheck", "make distcheck", "text/plain"),
191 ("clean", "make clean", "text/plain") ],
194 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
195 ("configure", "./configure --enable-developer -C ${PREFIX} ${EXTRA_PYTHON}", "text/plain"),
196 ("make", "make", "text/plain"),
197 ("install", "make install", "text/plain"),
198 ("test", "make test", "text/plain"),
199 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
200 ("distcheck", "make distcheck", "text/plain"),
201 ("clean", "make clean", "text/plain") ],
204 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
205 ("configure", "./configure --enable-developer -C ${PREFIX} ${EXTRA_PYTHON}", "text/plain"),
206 ("make", "make", "text/plain"),
207 ("install", "make install", "text/plain"),
208 ("test", "make test", "text/plain"),
209 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
210 ("distcheck", "make distcheck", "text/plain"),
211 ("clean", "make clean", "text/plain") ],
214 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
215 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
216 ("make", "make", "text/plain"),
217 ("install", "make install", "text/plain"),
218 ("test", "make test", "text/plain"),
219 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
220 ("distcheck", "make distcheck", "text/plain"),
221 ("clean", "make clean", "text/plain") ],
224 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
225 ("configure", "./configure --enable-developer -C ${PREFIX} ${EXTRA_PYTHON}", "text/plain"),
226 ("make", "make", "text/plain"),
227 ("install", "make install", "text/plain"),
228 ("test", "make test", "text/plain"),
229 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
230 ("distcheck", "make distcheck", "text/plain"),
231 ("clean", "make clean", "text/plain") ],
234 ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
235 ("configure", "perl Makefile.PL PREFIX=${PREFIX_DIR}", "text/plain"),
236 ("touch", "touch *.yp", "text/plain"),
237 ("make", "make", "text/plain"),
238 ("test", "make test", "text/plain"),
239 ("install", "make install", "text/plain"),
240 ("checkout-yapp-generated", "git checkout lib/Parse/Pidl/IDL.pm lib/Parse/Pidl/Expr.pm", "text/plain"),
241 ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
242 ("clean", "make clean", "text/plain") ],
244 # these are useful for debugging autobuild
245 'pass' : [ ("pass", 'echo passing && /bin/true', "text/plain") ],
246 'fail' : [ ("fail", 'echo failing && /bin/false', "text/plain") ]
249 def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True):
251 show = options.verbose
253 print("Running: '%s' in '%s'" % (cmd, dir))
255 return Popen([cmd], shell=True, stdout=PIPE, cwd=dir).communicate()[0]
257 return check_call(cmd, shell=True, cwd=dir)
259 return call(cmd, shell=True, cwd=dir)
262 class builder(object):
263 '''handle build of one directory'''
265 def __init__(self, name, sequence, cp=True):
267 self.dir = builddirs[name]
269 self.tag = self.name.replace('/', '_')
270 self.sequence = sequence
272 self.stdout_path = "%s/%s.stdout" % (gitroot, self.tag)
273 self.stderr_path = "%s/%s.stderr" % (gitroot, self.tag)
275 print("stdout for %s in %s" % (self.name, self.stdout_path))
276 print("stderr for %s in %s" % (self.name, self.stderr_path))
277 run_cmd("rm -f %s %s" % (self.stdout_path, self.stderr_path))
278 self.stdout = open(self.stdout_path, 'w')
279 self.stderr = open(self.stderr_path, 'w')
280 self.stdin = open("/dev/null", 'r')
281 self.sdir = "%s/%s" % (testbase, self.tag)
282 self.prefix = "%s/%s" % (test_prefix, self.tag)
283 run_cmd("rm -rf %s" % self.sdir)
284 run_cmd("rm -rf %s" % self.prefix)
286 run_cmd("cp --recursive --link --archive %s %s" % (test_master, self.sdir), dir=test_master, show=True)
288 run_cmd("git clone --recursive --shared %s %s" % (test_master, self.sdir), dir=test_master, show=True)
291 def start_next(self):
292 if self.next == len(self.sequence):
293 if not options.nocleanup:
294 run_cmd("rm -rf %s" % self.sdir)
295 run_cmd("rm -rf %s" % self.prefix)
296 print '%s: Completed OK' % self.name
299 (self.stage, self.cmd, self.output_mime_type) = self.sequence[self.next]
300 self.cmd = self.cmd.replace("${PYTHON_PREFIX}", get_python_lib(standard_lib=1, prefix=self.prefix))
301 self.cmd = self.cmd.replace("${PREFIX}", "--prefix=%s" % self.prefix)
302 self.cmd = self.cmd.replace("${EXTRA_PYTHON}", "%s" % extra_python)
303 self.cmd = self.cmd.replace("${PREFIX_DIR}", "%s" % self.prefix)
304 self.cmd = self.cmd.replace("${TESTS}", options.restrict_tests)
305 # if self.output_mime_type == "text/x-subunit":
306 # self.cmd += " | %s --immediate" % (os.path.join(os.path.dirname(__file__), "selftest/format-subunit"))
307 print '%s: [%s] Running %s' % (self.name, self.stage, self.cmd)
309 os.chdir("%s/%s" % (self.sdir, self.dir))
310 self.proc = Popen(self.cmd, shell=True,
311 stdout=self.stdout, stderr=self.stderr, stdin=self.stdin)
316 class buildlist(object):
317 '''handle build of multiple directories'''
319 def __init__(self, tasknames, rebase_url, rebase_branch="master"):
322 self.tail_proc = None
325 if options.restrict_tests:
326 tasknames = ["samba-test-only"]
328 tasknames = defaulttasks
330 # If we are only running one test,
331 # do not sleep randomly to wait for it to start
332 os.environ['AUTOBUILD_RANDOM_SLEEP_OVERRIDE'] = '1'
335 b = builder(n, tasks[n], cp=n is not "pidl")
338 rebase_remote = "rebaseon"
339 retry_task = [ ("retry",
341 git remote add -t %s %s %s
345 git describe %s/%s > old_remote_branch.desc
347 git describe %s/%s > remote_branch.desc
348 diff old_remote_branch.desc remote_branch.desc
351 rebase_branch, rebase_remote, rebase_url,
353 rebase_remote, rebase_branch,
355 rebase_remote, rebase_branch
359 self.retry = builder('retry', retry_task, cp=False)
360 self.need_retry = False
363 if self.tail_proc is not None:
364 self.tail_proc.terminate()
365 self.tail_proc.wait()
366 self.tail_proc = None
367 if self.retry is not None:
368 self.retry.proc.terminate()
369 self.retry.proc.wait()
372 if b.proc is not None:
373 run_cmd("killbysubdir %s > /dev/null 2>&1" % b.sdir, checkfail=False)
385 b.status = b.proc.poll()
391 ret = self.retry.proc.poll()
393 self.need_retry = True
403 if options.retry and self.need_retry:
405 print("retry needed")
406 return (0, None, None, None, "retry")
409 if os.WIFSIGNALED(b.status) or os.WEXITSTATUS(b.status) != 0:
411 return (b.status, b.name, b.stage, b.tag, "%s: [%s] failed '%s' with status %d" % (b.name, b.stage, b.cmd, b.status))
414 return (0, None, None, None, "All OK")
416 def write_system_info(self):
417 filename = 'system-info.txt'
418 f = open(filename, 'w')
419 for cmd in ['uname -a', 'free', 'cat /proc/cpuinfo']:
420 print >>f, '### %s' % cmd
421 print >>f, run_cmd(cmd, output=True, checkfail=False)
426 def tarlogs(self, fname):
427 tar = tarfile.open(fname, "w:gz")
429 tar.add(b.stdout_path, arcname="%s.stdout" % b.tag)
430 tar.add(b.stderr_path, arcname="%s.stderr" % b.tag)
431 if os.path.exists("autobuild.log"):
432 tar.add("autobuild.log")
433 sys_info = self.write_system_info()
437 def remove_logs(self):
439 os.unlink(b.stdout_path)
440 os.unlink(b.stderr_path)
442 def start_tail(self):
444 cmd = "tail -f *.stdout *.stderr"
446 self.tail_proc = Popen(cmd, shell=True)
451 if options.nocleanup:
453 print("Cleaning up ....")
454 for d in cleanup_list:
455 run_cmd("rm -rf %s" % d)
459 '''get to the top of the git repo'''
462 if os.path.isdir(os.path.join(p, ".git")):
464 p = os.path.abspath(os.path.join(p, '..'))
468 def daemonize(logfile):
470 if pid == 0: # Parent
473 if pid != 0: # Actual daemon
478 import resource # Resource usage information.
479 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
480 if maxfd == resource.RLIM_INFINITY:
481 maxfd = 1024 # Rough guess at maximum number of open file descriptors.
482 for fd in range(0, maxfd):
487 os.open(logfile, os.O_RDWR | os.O_CREAT)
491 def write_pidfile(fname):
492 '''write a pid file, cleanup on exit'''
493 f = open(fname, mode='w')
494 f.write("%u\n" % os.getpid())
498 def rebase_tree(rebase_url, rebase_branch = "master"):
499 rebase_remote = "rebaseon"
500 print("Rebasing on %s" % rebase_url)
501 run_cmd("git describe HEAD", show=True, dir=test_master)
502 run_cmd("git remote add -t %s %s %s" %
503 (rebase_branch, rebase_remote, rebase_url),
504 show=True, dir=test_master)
505 run_cmd("git fetch %s" % rebase_remote, show=True, dir=test_master)
506 if options.fix_whitespace:
507 run_cmd("git rebase --force-rebase --whitespace=fix %s/%s" %
508 (rebase_remote, rebase_branch),
509 show=True, dir=test_master)
511 run_cmd("git rebase --force-rebase %s/%s" %
512 (rebase_remote, rebase_branch),
513 show=True, dir=test_master)
514 diff = run_cmd("git --no-pager diff HEAD %s/%s" %
515 (rebase_remote, rebase_branch),
516 dir=test_master, output=True)
518 print("No differences between HEAD and %s/%s - exiting" %
519 (rebase_remote, rebase_branch))
521 run_cmd("git describe %s/%s" %
522 (rebase_remote, rebase_branch),
523 show=True, dir=test_master)
524 run_cmd("git describe HEAD", show=True, dir=test_master)
525 run_cmd("git --no-pager diff --stat HEAD %s/%s" %
526 (rebase_remote, rebase_branch),
527 show=True, dir=test_master)
529 def push_to(push_url, push_branch = "master"):
530 push_remote = "pushto"
531 print("Pushing to %s" % push_url)
533 run_cmd("git config --replace-all core.editor script/commit_mark.sh", dir=test_master)
534 run_cmd("git commit --amend -c HEAD", dir=test_master)
535 # the notes method doesn't work yet, as metze hasn't allowed refs/notes/* in master
536 # run_cmd("EDITOR=script/commit_mark.sh git notes edit HEAD", dir=test_master)
537 run_cmd("git remote add -t %s %s %s" %
538 (push_branch, push_remote, push_url),
539 show=True, dir=test_master)
540 run_cmd("git push %s +HEAD:%s" %
541 (push_remote, push_branch),
542 show=True, dir=test_master)
544 def_testbase = os.getenv("AUTOBUILD_TESTBASE", "/memdisk/%s" % os.getenv('USER'))
546 gitroot = find_git_root()
548 raise Exception("Failed to find git root")
550 parser = OptionParser()
551 parser.add_option("", "--tail", help="show output while running", default=False, action="store_true")
552 parser.add_option("", "--keeplogs", help="keep logs", default=False, action="store_true")
553 parser.add_option("", "--nocleanup", help="don't remove test tree", default=False, action="store_true")
554 parser.add_option("", "--testbase", help="base directory to run tests in (default %s)" % def_testbase,
555 default=def_testbase)
556 parser.add_option("", "--passcmd", help="command to run on success", default=None)
557 parser.add_option("", "--verbose", help="show all commands as they are run",
558 default=False, action="store_true")
559 parser.add_option("", "--rebase", help="rebase on the given tree before testing",
560 default=None, type='str')
561 parser.add_option("", "--pushto", help="push to a git url on success",
562 default=None, type='str')
563 parser.add_option("", "--mark", help="add a Tested-By signoff before pushing",
564 default=False, action="store_true")
565 parser.add_option("", "--fix-whitespace", help="fix whitespace on rebase",
566 default=False, action="store_true")
567 parser.add_option("", "--retry", help="automatically retry if master changes",
568 default=False, action="store_true")
569 parser.add_option("", "--email", help="send email to the given address on failure",
570 type='str', default=None)
571 parser.add_option("", "--email-from", help="send email from the given address",
572 type='str', default="autobuild@samba.org")
573 parser.add_option("", "--email-server", help="send email via the given server",
574 type='str', default='localhost')
575 parser.add_option("", "--always-email", help="always send email, even on success",
577 parser.add_option("", "--daemon", help="daemonize after initial setup",
579 parser.add_option("", "--branch", help="the branch to work on (default=master)",
580 default="master", type='str')
581 parser.add_option("", "--log-base", help="location where the logs can be found (default=cwd)",
582 default=gitroot, type='str')
583 parser.add_option("", "--attach-logs", help="Attach logs to mails sent on success/failure?",
584 default=False, action="store_true")
585 parser.add_option("", "--restrict-tests", help="run as make test with this TESTS= regex",
588 def send_email(subject, text, log_tar):
589 outer = MIMEMultipart()
590 outer['Subject'] = subject
591 outer['To'] = options.email
592 outer['From'] = options.email_from
593 outer['Date'] = email.utils.formatdate(localtime = True)
594 outer.preamble = 'Autobuild mails are now in MIME because we optionally attach the logs.\n'
595 outer.attach(MIMEText(text, 'plain'))
596 if options.attach_logs:
597 fp = open(log_tar, 'rb')
598 msg = MIMEApplication(fp.read(), 'gzip', email.encoders.encode_base64)
600 # Set the filename parameter
601 msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(log_tar))
603 content = outer.as_string()
604 s = smtplib.SMTP(options.email_server)
605 s.sendmail(options.email_from, [options.email], content)
609 def email_failure(status, failed_task, failed_stage, failed_tag, errstr,
610 elapsed_time, log_base=None, add_log_tail=True):
611 '''send an email to options.email about the failure'''
612 elapsed_minutes = elapsed_time / 60.0
613 user = os.getenv("USER")
619 Your autobuild on %s failed after %.1f minutes
620 when trying to test %s with the following error:
624 the autobuild has been abandoned. Please fix the error and resubmit.
626 A summary of the autobuild process is here:
629 ''' % (platform.node(), elapsed_minutes, failed_task, errstr, log_base)
631 if options.restrict_tests:
633 The build was restricted to tests matching %s\n""" % options.restrict_tests
635 if failed_task != 'rebase':
637 You can see logs of the failed task here:
642 or you can get full logs of all tasks in this job here:
646 The top commit for the tree that was built was:
650 ''' % (log_base, failed_tag, log_base, failed_tag, log_base, top_commit_msg)
653 f = open("%s/%s.stdout" % (gitroot, failed_tag), 'r')
654 lines = f.readlines()
655 log_tail = "".join(lines[-50:])
656 num_lines = len(lines)
658 # Also include stderr (compile failures) if < 50 lines of stdout
659 f = open("%s/%s.stderr" % (gitroot, failed_tag), 'r')
660 log_tail += "".join(f.readlines()[-(50-num_lines):])
663 The last 50 lines of log messages:
669 logs = os.path.join(gitroot, 'logs.tar.gz')
670 send_email('autobuild[%s] failure on %s for task %s during %s'
671 % (options.branch, platform.node(), failed_task, failed_stage),
674 def email_success(elapsed_time, log_base=None):
675 '''send an email to options.email about a successful build'''
676 user = os.getenv("USER")
682 Your autobuild on %s has succeeded after %.1f minutes.
684 ''' % (platform.node(), elapsed_time / 60.)
686 if options.restrict_tests:
688 The build was restricted to tests matching %s\n""" % options.restrict_tests
693 you can get full logs of all tasks in this job here:
700 The top commit for the tree that was built was:
705 logs = os.path.join(gitroot, 'logs.tar.gz')
706 send_email('autobuild[%s] success on %s' % (options.branch, platform.node()),
710 (options, args) = parser.parse_args()
713 if options.rebase is None:
714 raise Exception('You can only use --retry if you also rebase')
716 testbase = "%s/b%u" % (options.testbase, os.getpid())
717 test_master = "%s/master" % testbase
718 test_prefix = "%s/prefix" % testbase
719 test_tmpdir = "%s/tmp" % testbase
720 os.environ['TMPDIR'] = test_tmpdir
722 # get the top commit message, for emails
723 top_commit_msg = run_cmd("git log -1", dir=gitroot, output=True)
726 os.makedirs(testbase)
727 except Exception, reason:
728 raise Exception("Unable to create %s : %s" % (testbase, reason))
729 cleanup_list.append(testbase)
732 logfile = os.path.join(testbase, "log")
733 print "Forking into the background, writing progress to %s" % logfile
736 write_pidfile(gitroot + "/autobuild.pid")
738 start_time = time.time()
742 run_cmd("rm -rf %s" % test_master)
743 run_cmd("rm -rf %s" % test_prefix)
744 run_cmd("rm -rf %s" % test_tmpdir)
745 os.makedirs(test_tmpdir)
746 run_cmd("git clone --recursive --shared %s %s" % (gitroot, test_master), show=True, dir=gitroot)
753 if options.rebase is not None:
754 rebase_tree(options.rebase, rebase_branch=options.branch)
756 cleanup_list.append(gitroot + "/autobuild.pid")
758 elapsed_time = time.time() - start_time
759 email_failure(-1, 'rebase', 'rebase', 'rebase',
760 'rebase on %s failed' % options.branch,
761 elapsed_time, log_base=options.log_base)
763 blist = buildlist(args, options.rebase, rebase_branch=options.branch)
766 (status, failed_task, failed_stage, failed_tag, errstr) = blist.run()
767 if status != 0 or errstr != "retry":
774 cleanup_list.append(gitroot + "/autobuild.pid")
778 print("waiting for tail to flush")
781 elapsed_time = time.time() - start_time
784 if options.passcmd is not None:
785 print("Running passcmd: %s" % options.passcmd)
786 run_cmd(options.passcmd, dir=test_master)
787 if options.pushto is not None:
788 push_to(options.pushto, push_branch=options.branch)
789 if options.keeplogs or options.attach_logs:
790 blist.tarlogs("logs.tar.gz")
791 print("Logs in logs.tar.gz")
792 if options.always_email:
793 email_success(elapsed_time, log_base=options.log_base)
799 # something failed, gather a tar of the logs
800 blist.tarlogs("logs.tar.gz")
802 if options.email is not None:
803 email_failure(status, failed_task, failed_stage, failed_tag, errstr,
804 elapsed_time, log_base=options.log_base)
806 elapsed_minutes = elapsed_time / 60.0
809 ####################################################################
813 Your autobuild[%s] on %s failed after %.1f minutes
814 when trying to test %s with the following error:
818 the autobuild has been abandoned. Please fix the error and resubmit.
820 ####################################################################
822 ''' % (options.branch, platform.node(), elapsed_minutes, failed_task, errstr)
826 print("Logs in logs.tar.gz")