tdb_util: Fix whitespace
[Samba.git] / script / autobuild.py
blob41ba8a4b16ff4c4f0b56a7fdb01a64f6d38e048e
1 #!/usr/bin/env python
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
9 import smtplib
10 from email.mime.text import MIMEText
11 from distutils.sysconfig import get_python_lib
13 # This speeds up testing remarkably.
14 os.environ['TDB_NO_FSYNC'] = '1'
16 cleanup_list = []
18 builddirs = {
19 "ctdb" : "ctdb",
20 "samba" : ".",
21 "samba-ctdb" : ".",
22 "samba-libs" : ".",
23 "ldb" : "lib/ldb",
24 "tdb" : "lib/tdb",
25 "ntdb" : "lib/ntdb",
26 "talloc" : "lib/talloc",
27 "replace" : "lib/replace",
28 "tevent" : "lib/tevent",
29 "pidl" : "pidl",
30 "pass" : ".",
31 "fail" : ".",
32 "retry" : "."
35 defaulttasks = [ "ctdb", "samba", "samba-ctdb", "samba-libs", "ldb", "tdb", "ntdb", "talloc", "replace", "tevent", "pidl" ]
37 tasks = {
38 "ctdb" : [ ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
39 ("autogen", "./autogen.sh", "text/plain"),
40 ("configure", "./configure ${PREFIX} --enable-socket-wrapper ", "text/plain"),
41 ("make", "make all", "text/plain"),
42 ("install", "make install", "text/plain"),
43 ("test", "make autotest", "text/plain"),
44 ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
45 ("clean", "make clean", "text/plain") ],
47 # We have 'test' before 'install' because, 'test' should work without 'install'
48 "samba" : [ ("configure", "./configure.developer ${PREFIX} --with-selftest-prefix=./bin/ab", "text/plain"),
49 ("make", "make -j", "text/plain"),
50 ("test", "make test FAIL_IMMEDIATELY=1", "text/plain"),
51 ("install", "make install", "text/plain"),
52 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
53 ("clean", "make clean", "text/plain") ],
55 "samba-ctdb" : [ ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
57 # make sure we have tdb around:
58 ("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"),
59 ("tdb-make", "cd lib/tdb && make", "text/plain"),
60 ("tdb-install", "cd lib/tdb && make install", "text/plain"),
62 # build and install ctdb:
63 ("ctdb-autogen", "cd ./ctdb && ./autogen.sh", "text/plain"),
64 ("ctdb-configure", "cd ./ctdb && ./configure ${PREFIX} --enable-socket-wrapper --with-included-tdb=no", "text/plain"),
65 ("ctdb-make", "cd ./ctdb && make all", "text/plain"),
66 ("ctdb-install", "cd ./ctdb && make install", "text/plain"),
67 ("ctdb-header-ls", "ls ${PREFIX_DIR}/include/ctdb.h", "text/plain"),
69 # build samba with cluster support against this ctdb:
70 ("samba-configure", "PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure.developer ${PREFIX} --with-selftest-prefix=./bin/ab --with-cluster-support --with-ctdb-dir=${PREFIX_DIR} --bundled-libraries=!tdb", "text/plain"),
71 ("samba-make", "make", "text/plain"),
72 ("samba-check", "./bin/smbd -b | grep CLUSTER_SUPPORT", "text/plain"),
73 ("samba-install", "make install", "text/plain"),
75 # clean up:
76 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
77 ("clean", "make clean", "text/plain"),
78 ("ctdb-clean", "cd ./ctdb && make clean", "text/plain") ],
80 "samba-libs" : [
81 ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
82 ("talloc-configure", "cd lib/talloc && 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"),
83 ("talloc-make", "cd lib/talloc && make", "text/plain"),
84 ("talloc-install", "cd lib/talloc && make install", "text/plain"),
86 ("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"),
87 ("tdb-make", "cd lib/tdb && make", "text/plain"),
88 ("tdb-install", "cd lib/tdb && make install", "text/plain"),
90 ("ntdb-configure", "cd lib/ntdb && 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"),
91 ("ntdb-make", "cd lib/ntdb && make", "text/plain"),
92 ("ntdb-install", "cd lib/ntdb && make install", "text/plain"),
94 ("tevent-configure", "cd lib/tevent && 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"),
95 ("tevent-make", "cd lib/tevent && make", "text/plain"),
96 ("tevent-install", "cd lib/tevent && make install", "text/plain"),
98 ("ldb-configure", "cd lib/ldb && 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"),
99 ("ldb-make", "cd lib/ldb && make", "text/plain"),
100 ("ldb-install", "cd lib/ldb && make install", "text/plain"),
102 ("configure", "PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=!talloc,!tdb,!pytdb,!ntdb,!pyntdb,!ldb,!pyldb,!tevent,!pytevent --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
103 ("make", "make", "text/plain"),
104 ("install", "make install", "text/plain")],
106 "ldb" : [
107 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
108 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
109 ("make", "make", "text/plain"),
110 ("install", "make install", "text/plain"),
111 ("test", "make test", "text/plain"),
112 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
113 ("distcheck", "make distcheck", "text/plain"),
114 ("clean", "make clean", "text/plain") ],
116 "tdb" : [
117 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
118 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
119 ("make", "make", "text/plain"),
120 ("install", "make install", "text/plain"),
121 ("test", "make test", "text/plain"),
122 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
123 ("distcheck", "make distcheck", "text/plain"),
124 ("clean", "make clean", "text/plain") ],
126 "ntdb" : [
127 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
128 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
129 ("make", "make", "text/plain"),
130 ("install", "make install", "text/plain"),
131 ("test", "make test", "text/plain"),
132 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
133 ("distcheck", "make distcheck", "text/plain"),
134 ("clean", "make clean", "text/plain") ],
136 "talloc" : [
137 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
138 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
139 ("make", "make", "text/plain"),
140 ("install", "make install", "text/plain"),
141 ("test", "make test", "text/plain"),
142 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
143 ("distcheck", "make distcheck", "text/plain"),
144 ("clean", "make clean", "text/plain") ],
146 "replace" : [
147 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
148 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
149 ("make", "make", "text/plain"),
150 ("install", "make install", "text/plain"),
151 ("test", "make test", "text/plain"),
152 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
153 ("distcheck", "make distcheck", "text/plain"),
154 ("clean", "make clean", "text/plain") ],
156 "tevent" : [
157 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
158 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
159 ("make", "make", "text/plain"),
160 ("install", "make install", "text/plain"),
161 ("test", "make test", "text/plain"),
162 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
163 ("distcheck", "make distcheck", "text/plain"),
164 ("clean", "make clean", "text/plain") ],
166 "pidl" : [
167 ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
168 ("configure", "perl Makefile.PL PREFIX=${PREFIX_DIR}", "text/plain"),
169 ("touch", "touch *.yp", "text/plain"),
170 ("make", "make", "text/plain"),
171 ("test", "make test", "text/plain"),
172 ("install", "make install", "text/plain"),
173 ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
174 ("clean", "make clean", "text/plain") ],
176 # these are useful for debugging autobuild
177 'pass' : [ ("pass", 'echo passing && /bin/true', "text/plain") ],
178 'fail' : [ ("fail", 'echo failing && /bin/false', "text/plain") ]
181 def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True):
182 if show is None:
183 show = options.verbose
184 if show:
185 print("Running: '%s' in '%s'" % (cmd, dir))
186 if output:
187 return Popen([cmd], shell=True, stdout=PIPE, cwd=dir).communicate()[0]
188 elif checkfail:
189 return check_call(cmd, shell=True, cwd=dir)
190 else:
191 return call(cmd, shell=True, cwd=dir)
194 class builder(object):
195 '''handle build of one directory'''
197 def __init__(self, name, sequence):
198 self.name = name
199 self.dir = builddirs[name]
201 self.tag = self.name.replace('/', '_')
202 self.sequence = sequence
203 self.next = 0
204 self.stdout_path = "%s/%s.stdout" % (gitroot, self.tag)
205 self.stderr_path = "%s/%s.stderr" % (gitroot, self.tag)
206 if options.verbose:
207 print("stdout for %s in %s" % (self.name, self.stdout_path))
208 print("stderr for %s in %s" % (self.name, self.stderr_path))
209 run_cmd("rm -f %s %s" % (self.stdout_path, self.stderr_path))
210 self.stdout = open(self.stdout_path, 'w')
211 self.stderr = open(self.stderr_path, 'w')
212 self.stdin = open("/dev/null", 'r')
213 self.sdir = "%s/%s" % (testbase, self.tag)
214 self.prefix = "%s/prefix/%s" % (testbase, self.tag)
215 run_cmd("rm -rf %s" % self.sdir)
216 cleanup_list.append(self.sdir)
217 cleanup_list.append(self.prefix)
218 os.makedirs(self.sdir)
219 run_cmd("rm -rf %s" % self.sdir)
220 run_cmd("git clone --shared %s %s" % (test_master, self.sdir), dir=test_master, show=True)
221 self.start_next()
223 def start_next(self):
224 if self.next == len(self.sequence):
225 print '%s: Completed OK' % self.name
226 self.done = True
227 return
228 (self.stage, self.cmd, self.output_mime_type) = self.sequence[self.next]
229 self.cmd = self.cmd.replace("${PYTHON_PREFIX}", get_python_lib(standard_lib=1, prefix=self.prefix))
230 self.cmd = self.cmd.replace("${PREFIX}", "--prefix=%s" % self.prefix)
231 self.cmd = self.cmd.replace("${PREFIX_DIR}", "%s" % self.prefix)
232 # if self.output_mime_type == "text/x-subunit":
233 # self.cmd += " | %s --immediate" % (os.path.join(os.path.dirname(__file__), "selftest/format-subunit"))
234 print '%s: [%s] Running %s' % (self.name, self.stage, self.cmd)
235 cwd = os.getcwd()
236 os.chdir("%s/%s" % (self.sdir, self.dir))
237 self.proc = Popen(self.cmd, shell=True,
238 stdout=self.stdout, stderr=self.stderr, stdin=self.stdin)
239 os.chdir(cwd)
240 self.next += 1
243 class buildlist(object):
244 '''handle build of multiple directories'''
246 def __init__(self, tasklist, tasknames, rebase_url, rebase_branch="master"):
247 global tasks
248 self.tlist = []
249 self.tail_proc = None
250 self.retry = None
251 if tasknames == []:
252 tasknames = defaulttasks
253 for n in tasknames:
254 b = builder(n, tasks[n])
255 self.tlist.append(b)
256 if options.retry:
257 rebase_remote = "rebaseon"
258 retry_task = [ ("retry",
259 '''set -e
260 git remote add -t %s %s %s
261 git fetch %s
262 while :; do
263 sleep 60
264 git describe %s/%s > old_remote_branch.desc
265 git fetch %s
266 git describe %s/%s > remote_branch.desc
267 diff old_remote_branch.desc remote_branch.desc
268 done
269 ''' % (
270 rebase_branch, rebase_remote, rebase_url,
271 rebase_remote,
272 rebase_remote, rebase_branch,
273 rebase_remote,
274 rebase_remote, rebase_branch
276 "test/plain" ) ]
278 self.retry = builder('retry', retry_task)
279 self.need_retry = False
281 def kill_kids(self):
282 if self.tail_proc is not None:
283 self.tail_proc.terminate()
284 self.tail_proc.wait()
285 self.tail_proc = None
286 if self.retry is not None:
287 self.retry.proc.terminate()
288 self.retry.proc.wait()
289 self.retry = None
290 for b in self.tlist:
291 if b.proc is not None:
292 run_cmd("killbysubdir %s > /dev/null 2>&1" % b.sdir, checkfail=False)
293 b.proc.terminate()
294 b.proc.wait()
295 b.proc = None
297 def wait_one(self):
298 while True:
299 none_running = True
300 for b in self.tlist:
301 if b.proc is None:
302 continue
303 none_running = False
304 b.status = b.proc.poll()
305 if b.status is None:
306 continue
307 b.proc = None
308 return b
309 if options.retry:
310 ret = self.retry.proc.poll()
311 if ret is not None:
312 self.need_retry = True
313 self.retry = None
314 return None
315 if none_running:
316 return None
317 time.sleep(0.1)
319 def run(self):
320 while True:
321 b = self.wait_one()
322 if options.retry and self.need_retry:
323 self.kill_kids()
324 print("retry needed")
325 return (0, None, None, None, "retry")
326 if b is None:
327 break
328 if os.WIFSIGNALED(b.status) or os.WEXITSTATUS(b.status) != 0:
329 self.kill_kids()
330 return (b.status, b.name, b.stage, b.tag, "%s: [%s] failed '%s' with status %d" % (b.name, b.stage, b.cmd, b.status))
331 b.start_next()
332 self.kill_kids()
333 return (0, None, None, None, "All OK")
335 def tarlogs(self, fname):
336 tar = tarfile.open(fname, "w:gz")
337 for b in self.tlist:
338 tar.add(b.stdout_path, arcname="%s.stdout" % b.tag)
339 tar.add(b.stderr_path, arcname="%s.stderr" % b.tag)
340 if os.path.exists("autobuild.log"):
341 tar.add("autobuild.log")
342 tar.close()
344 def remove_logs(self):
345 for b in self.tlist:
346 os.unlink(b.stdout_path)
347 os.unlink(b.stderr_path)
349 def start_tail(self):
350 cwd = os.getcwd()
351 cmd = "tail -f *.stdout *.stderr"
352 os.chdir(gitroot)
353 self.tail_proc = Popen(cmd, shell=True)
354 os.chdir(cwd)
357 def cleanup():
358 if options.nocleanup:
359 return
360 print("Cleaning up ....")
361 for d in cleanup_list:
362 run_cmd("rm -rf %s" % d)
365 def find_git_root():
366 '''get to the top of the git repo'''
367 p=os.getcwd()
368 while p != '/':
369 if os.path.isdir(os.path.join(p, ".git")):
370 return p
371 p = os.path.abspath(os.path.join(p, '..'))
372 return None
375 def daemonize(logfile):
376 pid = os.fork()
377 if pid == 0: # Parent
378 os.setsid()
379 pid = os.fork()
380 if pid != 0: # Actual daemon
381 os._exit(0)
382 else: # Grandparent
383 os._exit(0)
385 import resource # Resource usage information.
386 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
387 if maxfd == resource.RLIM_INFINITY:
388 maxfd = 1024 # Rough guess at maximum number of open file descriptors.
389 for fd in range(0, maxfd):
390 try:
391 os.close(fd)
392 except OSError:
393 pass
394 os.open(logfile, os.O_RDWR | os.O_CREAT)
395 os.dup2(0, 1)
396 os.dup2(0, 2)
398 def write_pidfile(fname):
399 '''write a pid file, cleanup on exit'''
400 f = open(fname, mode='w')
401 f.write("%u\n" % os.getpid())
402 f.close()
405 def rebase_tree(rebase_url, rebase_branch = "master"):
406 rebase_remote = "rebaseon"
407 print("Rebasing on %s" % rebase_url)
408 run_cmd("git describe HEAD", show=True, dir=test_master)
409 run_cmd("git remote add -t %s %s %s" %
410 (rebase_branch, rebase_remote, rebase_url),
411 show=True, dir=test_master)
412 run_cmd("git fetch %s" % rebase_remote, show=True, dir=test_master)
413 if options.fix_whitespace:
414 run_cmd("git rebase --whitespace=fix %s/%s" %
415 (rebase_remote, rebase_branch),
416 show=True, dir=test_master)
417 else:
418 run_cmd("git rebase %s/%s" %
419 (rebase_remote, rebase_branch),
420 show=True, dir=test_master)
421 diff = run_cmd("git --no-pager diff HEAD %s/%s" %
422 (rebase_remote, rebase_branch),
423 dir=test_master, output=True)
424 if diff == '':
425 print("No differences between HEAD and %s/%s - exiting" %
426 (rebase_remote, rebase_branch))
427 sys.exit(0)
428 run_cmd("git describe %s/%s" %
429 (rebase_remote, rebase_branch),
430 show=True, dir=test_master)
431 run_cmd("git describe HEAD", show=True, dir=test_master)
432 run_cmd("git --no-pager diff --stat HEAD %s/%s" %
433 (rebase_remote, rebase_branch),
434 show=True, dir=test_master)
436 def push_to(push_url, push_branch = "master"):
437 push_remote = "pushto"
438 print("Pushing to %s" % push_url)
439 if options.mark:
440 run_cmd("git config --replace-all core.editor script/commit_mark.sh", dir=test_master)
441 run_cmd("git commit --amend -c HEAD", dir=test_master)
442 # the notes method doesn't work yet, as metze hasn't allowed refs/notes/* in master
443 # run_cmd("EDITOR=script/commit_mark.sh git notes edit HEAD", dir=test_master)
444 run_cmd("git remote add -t %s %s %s" %
445 (push_branch, push_remote, push_url),
446 show=True, dir=test_master)
447 run_cmd("git push %s +HEAD:%s" %
448 (push_remote, push_branch),
449 show=True, dir=test_master)
451 def_testbase = os.getenv("AUTOBUILD_TESTBASE", "/memdisk/%s" % os.getenv('USER'))
453 gitroot = find_git_root()
454 if gitroot is None:
455 raise Exception("Failed to find git root")
457 parser = OptionParser()
458 parser.add_option("", "--tail", help="show output while running", default=False, action="store_true")
459 parser.add_option("", "--keeplogs", help="keep logs", default=False, action="store_true")
460 parser.add_option("", "--nocleanup", help="don't remove test tree", default=False, action="store_true")
461 parser.add_option("", "--testbase", help="base directory to run tests in (default %s)" % def_testbase,
462 default=def_testbase)
463 parser.add_option("", "--passcmd", help="command to run on success", default=None)
464 parser.add_option("", "--verbose", help="show all commands as they are run",
465 default=False, action="store_true")
466 parser.add_option("", "--rebase", help="rebase on the given tree before testing",
467 default=None, type='str')
468 parser.add_option("", "--pushto", help="push to a git url on success",
469 default=None, type='str')
470 parser.add_option("", "--mark", help="add a Tested-By signoff before pushing",
471 default=False, action="store_true")
472 parser.add_option("", "--fix-whitespace", help="fix whitespace on rebase",
473 default=False, action="store_true")
474 parser.add_option("", "--retry", help="automatically retry if master changes",
475 default=False, action="store_true")
476 parser.add_option("", "--email", help="send email to the given address on failure",
477 type='str', default=None)
478 parser.add_option("", "--always-email", help="always send email, even on success",
479 action="store_true")
480 parser.add_option("", "--daemon", help="daemonize after initial setup",
481 action="store_true")
482 parser.add_option("", "--branch", help="the branch to work on (default=master)",
483 default="master", type='str')
484 parser.add_option("", "--log-base", help="location where the logs can be found (default=cwd)",
485 default=gitroot, type='str')
487 def email_failure(status, failed_task, failed_stage, failed_tag, errstr, log_base=None):
488 '''send an email to options.email about the failure'''
489 user = os.getenv("USER")
490 if log_base is None:
491 log_base = gitroot
492 text = '''
493 Dear Developer,
495 Your autobuild failed when trying to test %s with the following error:
498 the autobuild has been abandoned. Please fix the error and resubmit.
500 A summary of the autobuild process is here:
502 %s/autobuild.log
503 ''' % (failed_task, errstr, log_base)
505 if failed_task != 'rebase':
506 text += '''
507 You can see logs of the failed task here:
509 %s/%s.stdout
510 %s/%s.stderr
512 or you can get full logs of all tasks in this job here:
514 %s/logs.tar.gz
516 The top commit for the tree that was built was:
520 ''' % (log_base, failed_tag, log_base, failed_tag, log_base, top_commit_msg)
521 msg = MIMEText(text)
522 msg['Subject'] = 'autobuild failure for task %s during %s' % (failed_task, failed_stage)
523 msg['From'] = 'autobuild@samba.org'
524 msg['To'] = options.email
526 s = smtplib.SMTP()
527 s.connect()
528 s.sendmail(msg['From'], [msg['To']], msg.as_string())
529 s.quit()
531 def email_success(log_base=None):
532 '''send an email to options.email about a successful build'''
533 user = os.getenv("USER")
534 if log_base is None:
535 log_base = gitroot
536 text = '''
537 Dear Developer,
539 Your autobuild has succeeded.
543 if options.keeplogs:
544 text += '''
546 you can get full logs of all tasks in this job here:
548 %s/logs.tar.gz
550 ''' % log_base
552 text += '''
553 The top commit for the tree that was built was:
556 ''' % top_commit_msg
558 msg = MIMEText(text)
559 msg['Subject'] = 'autobuild success'
560 msg['From'] = 'autobuild@samba.org'
561 msg['To'] = options.email
563 s = smtplib.SMTP()
564 s.connect()
565 s.sendmail(msg['From'], [msg['To']], msg.as_string())
566 s.quit()
569 (options, args) = parser.parse_args()
571 if options.retry:
572 if options.rebase is None:
573 raise Exception('You can only use --retry if you also rebase')
575 testbase = "%s/b%u" % (options.testbase, os.getpid())
576 test_master = "%s/master" % testbase
578 # get the top commit message, for emails
579 top_commit_msg = run_cmd("git log -1", dir=gitroot, output=True)
581 try:
582 os.makedirs(testbase)
583 except Exception, reason:
584 raise Exception("Unable to create %s : %s" % (testbase, reason))
585 cleanup_list.append(testbase)
587 if options.daemon:
588 logfile = os.path.join(testbase, "log")
589 print "Forking into the background, writing progress to %s" % logfile
590 daemonize(logfile)
592 write_pidfile(gitroot + "/autobuild.pid")
594 while True:
595 try:
596 run_cmd("rm -rf %s" % test_master)
597 cleanup_list.append(test_master)
598 run_cmd("git clone --shared %s %s" % (gitroot, test_master), show=True, dir=gitroot)
599 except Exception:
600 cleanup()
601 raise
603 try:
604 try:
605 if options.rebase is not None:
606 rebase_tree(options.rebase, rebase_branch=options.branch)
607 except Exception:
608 cleanup_list.append(gitroot + "/autobuild.pid")
609 cleanup()
610 email_failure(-1, 'rebase', 'rebase', 'rebase',
611 'rebase on %s failed' % options.branch,
612 log_base=options.log_base)
613 sys.exit(1)
614 blist = buildlist(tasks, args, options.rebase, rebase_branch=options.branch)
615 if options.tail:
616 blist.start_tail()
617 (status, failed_task, failed_stage, failed_tag, errstr) = blist.run()
618 if status != 0 or errstr != "retry":
619 break
620 cleanup()
621 except Exception:
622 cleanup()
623 raise
625 cleanup_list.append(gitroot + "/autobuild.pid")
627 blist.kill_kids()
628 if options.tail:
629 print("waiting for tail to flush")
630 time.sleep(1)
632 if status == 0:
633 print errstr
634 if options.passcmd is not None:
635 print("Running passcmd: %s" % options.passcmd)
636 run_cmd(options.passcmd, dir=test_master)
637 if options.pushto is not None:
638 push_to(options.pushto, push_branch=options.branch)
639 if options.keeplogs:
640 blist.tarlogs("logs.tar.gz")
641 print("Logs in logs.tar.gz")
642 if options.always_email:
643 email_success(log_base=options.log_base)
644 blist.remove_logs()
645 cleanup()
646 print(errstr)
647 sys.exit(0)
649 # something failed, gather a tar of the logs
650 blist.tarlogs("logs.tar.gz")
652 if options.email is not None:
653 email_failure(status, failed_task, failed_stage, failed_tag, errstr, log_base=options.log_base)
655 cleanup()
656 print(errstr)
657 print("Logs in logs.tar.gz")
658 sys.exit(status)