s3:smb2_read: make use of smbd_smb2_generate_outbody()
[Samba.git] / script / autobuild.py
blob4af70ee8211ad1edf3d8797df74d971a8d178637
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"),
105 ("dist", "make dist", "text/plain")],
107 "ldb" : [
108 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
109 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
110 ("make", "make", "text/plain"),
111 ("install", "make install", "text/plain"),
112 ("test", "make test", "text/plain"),
113 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
114 ("distcheck", "make distcheck", "text/plain"),
115 ("clean", "make clean", "text/plain") ],
117 "tdb" : [
118 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
119 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
120 ("make", "make", "text/plain"),
121 ("install", "make install", "text/plain"),
122 ("test", "make test", "text/plain"),
123 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
124 ("distcheck", "make distcheck", "text/plain"),
125 ("clean", "make clean", "text/plain") ],
127 "ntdb" : [
128 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
129 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
130 ("make", "make", "text/plain"),
131 ("install", "make install", "text/plain"),
132 ("test", "make test", "text/plain"),
133 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
134 ("distcheck", "make distcheck", "text/plain"),
135 ("clean", "make clean", "text/plain") ],
137 "talloc" : [
138 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
139 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
140 ("make", "make", "text/plain"),
141 ("install", "make install", "text/plain"),
142 ("test", "make test", "text/plain"),
143 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
144 ("distcheck", "make distcheck", "text/plain"),
145 ("clean", "make clean", "text/plain") ],
147 "replace" : [
148 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
149 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
150 ("make", "make", "text/plain"),
151 ("install", "make install", "text/plain"),
152 ("test", "make test", "text/plain"),
153 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
154 ("distcheck", "make distcheck", "text/plain"),
155 ("clean", "make clean", "text/plain") ],
157 "tevent" : [
158 ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
159 ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
160 ("make", "make", "text/plain"),
161 ("install", "make install", "text/plain"),
162 ("test", "make test", "text/plain"),
163 ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
164 ("distcheck", "make distcheck", "text/plain"),
165 ("clean", "make clean", "text/plain") ],
167 "pidl" : [
168 ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
169 ("configure", "perl Makefile.PL PREFIX=${PREFIX_DIR}", "text/plain"),
170 ("touch", "touch *.yp", "text/plain"),
171 ("make", "make", "text/plain"),
172 ("test", "make test", "text/plain"),
173 ("install", "make install", "text/plain"),
174 ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
175 ("clean", "make clean", "text/plain") ],
177 # these are useful for debugging autobuild
178 'pass' : [ ("pass", 'echo passing && /bin/true', "text/plain") ],
179 'fail' : [ ("fail", 'echo failing && /bin/false', "text/plain") ]
182 def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True):
183 if show is None:
184 show = options.verbose
185 if show:
186 print("Running: '%s' in '%s'" % (cmd, dir))
187 if output:
188 return Popen([cmd], shell=True, stdout=PIPE, cwd=dir).communicate()[0]
189 elif checkfail:
190 return check_call(cmd, shell=True, cwd=dir)
191 else:
192 return call(cmd, shell=True, cwd=dir)
195 class builder(object):
196 '''handle build of one directory'''
198 def __init__(self, name, sequence):
199 self.name = name
200 self.dir = builddirs[name]
202 self.tag = self.name.replace('/', '_')
203 self.sequence = sequence
204 self.next = 0
205 self.stdout_path = "%s/%s.stdout" % (gitroot, self.tag)
206 self.stderr_path = "%s/%s.stderr" % (gitroot, self.tag)
207 if options.verbose:
208 print("stdout for %s in %s" % (self.name, self.stdout_path))
209 print("stderr for %s in %s" % (self.name, self.stderr_path))
210 run_cmd("rm -f %s %s" % (self.stdout_path, self.stderr_path))
211 self.stdout = open(self.stdout_path, 'w')
212 self.stderr = open(self.stderr_path, 'w')
213 self.stdin = open("/dev/null", 'r')
214 self.sdir = "%s/%s" % (testbase, self.tag)
215 self.prefix = "%s/prefix/%s" % (testbase, self.tag)
216 run_cmd("rm -rf %s" % self.sdir)
217 cleanup_list.append(self.sdir)
218 cleanup_list.append(self.prefix)
219 os.makedirs(self.sdir)
220 run_cmd("rm -rf %s" % self.sdir)
221 run_cmd("git clone --shared %s %s" % (test_master, self.sdir), dir=test_master, show=True)
222 self.start_next()
224 def start_next(self):
225 if self.next == len(self.sequence):
226 print '%s: Completed OK' % self.name
227 self.done = True
228 return
229 (self.stage, self.cmd, self.output_mime_type) = self.sequence[self.next]
230 self.cmd = self.cmd.replace("${PYTHON_PREFIX}", get_python_lib(standard_lib=1, prefix=self.prefix))
231 self.cmd = self.cmd.replace("${PREFIX}", "--prefix=%s" % self.prefix)
232 self.cmd = self.cmd.replace("${PREFIX_DIR}", "%s" % self.prefix)
233 # if self.output_mime_type == "text/x-subunit":
234 # self.cmd += " | %s --immediate" % (os.path.join(os.path.dirname(__file__), "selftest/format-subunit"))
235 print '%s: [%s] Running %s' % (self.name, self.stage, self.cmd)
236 cwd = os.getcwd()
237 os.chdir("%s/%s" % (self.sdir, self.dir))
238 self.proc = Popen(self.cmd, shell=True,
239 stdout=self.stdout, stderr=self.stderr, stdin=self.stdin)
240 os.chdir(cwd)
241 self.next += 1
244 class buildlist(object):
245 '''handle build of multiple directories'''
247 def __init__(self, tasklist, tasknames, rebase_url, rebase_branch="master"):
248 global tasks
249 self.tlist = []
250 self.tail_proc = None
251 self.retry = None
252 if tasknames == []:
253 tasknames = defaulttasks
254 for n in tasknames:
255 b = builder(n, tasks[n])
256 self.tlist.append(b)
257 if options.retry:
258 rebase_remote = "rebaseon"
259 retry_task = [ ("retry",
260 '''set -e
261 git remote add -t %s %s %s
262 git fetch %s
263 while :; do
264 sleep 60
265 git describe %s/%s > old_remote_branch.desc
266 git fetch %s
267 git describe %s/%s > remote_branch.desc
268 diff old_remote_branch.desc remote_branch.desc
269 done
270 ''' % (
271 rebase_branch, rebase_remote, rebase_url,
272 rebase_remote,
273 rebase_remote, rebase_branch,
274 rebase_remote,
275 rebase_remote, rebase_branch
277 "test/plain" ) ]
279 self.retry = builder('retry', retry_task)
280 self.need_retry = False
282 def kill_kids(self):
283 if self.tail_proc is not None:
284 self.tail_proc.terminate()
285 self.tail_proc.wait()
286 self.tail_proc = None
287 if self.retry is not None:
288 self.retry.proc.terminate()
289 self.retry.proc.wait()
290 self.retry = None
291 for b in self.tlist:
292 if b.proc is not None:
293 run_cmd("killbysubdir %s > /dev/null 2>&1" % b.sdir, checkfail=False)
294 b.proc.terminate()
295 b.proc.wait()
296 b.proc = None
298 def wait_one(self):
299 while True:
300 none_running = True
301 for b in self.tlist:
302 if b.proc is None:
303 continue
304 none_running = False
305 b.status = b.proc.poll()
306 if b.status is None:
307 continue
308 b.proc = None
309 return b
310 if options.retry:
311 ret = self.retry.proc.poll()
312 if ret is not None:
313 self.need_retry = True
314 self.retry = None
315 return None
316 if none_running:
317 return None
318 time.sleep(0.1)
320 def run(self):
321 while True:
322 b = self.wait_one()
323 if options.retry and self.need_retry:
324 self.kill_kids()
325 print("retry needed")
326 return (0, None, None, None, "retry")
327 if b is None:
328 break
329 if os.WIFSIGNALED(b.status) or os.WEXITSTATUS(b.status) != 0:
330 self.kill_kids()
331 return (b.status, b.name, b.stage, b.tag, "%s: [%s] failed '%s' with status %d" % (b.name, b.stage, b.cmd, b.status))
332 b.start_next()
333 self.kill_kids()
334 return (0, None, None, None, "All OK")
336 def tarlogs(self, fname):
337 tar = tarfile.open(fname, "w:gz")
338 for b in self.tlist:
339 tar.add(b.stdout_path, arcname="%s.stdout" % b.tag)
340 tar.add(b.stderr_path, arcname="%s.stderr" % b.tag)
341 if os.path.exists("autobuild.log"):
342 tar.add("autobuild.log")
343 tar.close()
345 def remove_logs(self):
346 for b in self.tlist:
347 os.unlink(b.stdout_path)
348 os.unlink(b.stderr_path)
350 def start_tail(self):
351 cwd = os.getcwd()
352 cmd = "tail -f *.stdout *.stderr"
353 os.chdir(gitroot)
354 self.tail_proc = Popen(cmd, shell=True)
355 os.chdir(cwd)
358 def cleanup():
359 if options.nocleanup:
360 return
361 print("Cleaning up ....")
362 for d in cleanup_list:
363 run_cmd("rm -rf %s" % d)
366 def find_git_root():
367 '''get to the top of the git repo'''
368 p=os.getcwd()
369 while p != '/':
370 if os.path.isdir(os.path.join(p, ".git")):
371 return p
372 p = os.path.abspath(os.path.join(p, '..'))
373 return None
376 def daemonize(logfile):
377 pid = os.fork()
378 if pid == 0: # Parent
379 os.setsid()
380 pid = os.fork()
381 if pid != 0: # Actual daemon
382 os._exit(0)
383 else: # Grandparent
384 os._exit(0)
386 import resource # Resource usage information.
387 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
388 if maxfd == resource.RLIM_INFINITY:
389 maxfd = 1024 # Rough guess at maximum number of open file descriptors.
390 for fd in range(0, maxfd):
391 try:
392 os.close(fd)
393 except OSError:
394 pass
395 os.open(logfile, os.O_RDWR | os.O_CREAT)
396 os.dup2(0, 1)
397 os.dup2(0, 2)
399 def write_pidfile(fname):
400 '''write a pid file, cleanup on exit'''
401 f = open(fname, mode='w')
402 f.write("%u\n" % os.getpid())
403 f.close()
406 def rebase_tree(rebase_url, rebase_branch = "master"):
407 rebase_remote = "rebaseon"
408 print("Rebasing on %s" % rebase_url)
409 run_cmd("git describe HEAD", show=True, dir=test_master)
410 run_cmd("git remote add -t %s %s %s" %
411 (rebase_branch, rebase_remote, rebase_url),
412 show=True, dir=test_master)
413 run_cmd("git fetch %s" % rebase_remote, show=True, dir=test_master)
414 if options.fix_whitespace:
415 run_cmd("git rebase --whitespace=fix %s/%s" %
416 (rebase_remote, rebase_branch),
417 show=True, dir=test_master)
418 else:
419 run_cmd("git rebase %s/%s" %
420 (rebase_remote, rebase_branch),
421 show=True, dir=test_master)
422 diff = run_cmd("git --no-pager diff HEAD %s/%s" %
423 (rebase_remote, rebase_branch),
424 dir=test_master, output=True)
425 if diff == '':
426 print("No differences between HEAD and %s/%s - exiting" %
427 (rebase_remote, rebase_branch))
428 sys.exit(0)
429 run_cmd("git describe %s/%s" %
430 (rebase_remote, rebase_branch),
431 show=True, dir=test_master)
432 run_cmd("git describe HEAD", show=True, dir=test_master)
433 run_cmd("git --no-pager diff --stat HEAD %s/%s" %
434 (rebase_remote, rebase_branch),
435 show=True, dir=test_master)
437 def push_to(push_url, push_branch = "master"):
438 push_remote = "pushto"
439 print("Pushing to %s" % push_url)
440 if options.mark:
441 run_cmd("git config --replace-all core.editor script/commit_mark.sh", dir=test_master)
442 run_cmd("git commit --amend -c HEAD", dir=test_master)
443 # the notes method doesn't work yet, as metze hasn't allowed refs/notes/* in master
444 # run_cmd("EDITOR=script/commit_mark.sh git notes edit HEAD", dir=test_master)
445 run_cmd("git remote add -t %s %s %s" %
446 (push_branch, push_remote, push_url),
447 show=True, dir=test_master)
448 run_cmd("git push %s +HEAD:%s" %
449 (push_remote, push_branch),
450 show=True, dir=test_master)
452 def_testbase = os.getenv("AUTOBUILD_TESTBASE", "/memdisk/%s" % os.getenv('USER'))
454 gitroot = find_git_root()
455 if gitroot is None:
456 raise Exception("Failed to find git root")
458 parser = OptionParser()
459 parser.add_option("", "--tail", help="show output while running", default=False, action="store_true")
460 parser.add_option("", "--keeplogs", help="keep logs", default=False, action="store_true")
461 parser.add_option("", "--nocleanup", help="don't remove test tree", default=False, action="store_true")
462 parser.add_option("", "--testbase", help="base directory to run tests in (default %s)" % def_testbase,
463 default=def_testbase)
464 parser.add_option("", "--passcmd", help="command to run on success", default=None)
465 parser.add_option("", "--verbose", help="show all commands as they are run",
466 default=False, action="store_true")
467 parser.add_option("", "--rebase", help="rebase on the given tree before testing",
468 default=None, type='str')
469 parser.add_option("", "--pushto", help="push to a git url on success",
470 default=None, type='str')
471 parser.add_option("", "--mark", help="add a Tested-By signoff before pushing",
472 default=False, action="store_true")
473 parser.add_option("", "--fix-whitespace", help="fix whitespace on rebase",
474 default=False, action="store_true")
475 parser.add_option("", "--retry", help="automatically retry if master changes",
476 default=False, action="store_true")
477 parser.add_option("", "--email", help="send email to the given address on failure",
478 type='str', default=None)
479 parser.add_option("", "--always-email", help="always send email, even on success",
480 action="store_true")
481 parser.add_option("", "--daemon", help="daemonize after initial setup",
482 action="store_true")
483 parser.add_option("", "--branch", help="the branch to work on (default=master)",
484 default="master", type='str')
485 parser.add_option("", "--log-base", help="location where the logs can be found (default=cwd)",
486 default=gitroot, type='str')
488 def email_failure(status, failed_task, failed_stage, failed_tag, errstr, log_base=None):
489 '''send an email to options.email about the failure'''
490 user = os.getenv("USER")
491 if log_base is None:
492 log_base = gitroot
493 text = '''
494 Dear Developer,
496 Your autobuild failed when trying to test %s with the following error:
499 the autobuild has been abandoned. Please fix the error and resubmit.
501 A summary of the autobuild process is here:
503 %s/autobuild.log
504 ''' % (failed_task, errstr, log_base)
506 if failed_task != 'rebase':
507 text += '''
508 You can see logs of the failed task here:
510 %s/%s.stdout
511 %s/%s.stderr
513 or you can get full logs of all tasks in this job here:
515 %s/logs.tar.gz
517 The top commit for the tree that was built was:
521 ''' % (log_base, failed_tag, log_base, failed_tag, log_base, top_commit_msg)
522 msg = MIMEText(text)
523 msg['Subject'] = 'autobuild failure for task %s during %s' % (failed_task, failed_stage)
524 msg['From'] = 'autobuild@samba.org'
525 msg['To'] = options.email
527 s = smtplib.SMTP()
528 s.connect()
529 s.sendmail(msg['From'], [msg['To']], msg.as_string())
530 s.quit()
532 def email_success(log_base=None):
533 '''send an email to options.email about a successful build'''
534 user = os.getenv("USER")
535 if log_base is None:
536 log_base = gitroot
537 text = '''
538 Dear Developer,
540 Your autobuild has succeeded.
544 if options.keeplogs:
545 text += '''
547 you can get full logs of all tasks in this job here:
549 %s/logs.tar.gz
551 ''' % log_base
553 text += '''
554 The top commit for the tree that was built was:
557 ''' % top_commit_msg
559 msg = MIMEText(text)
560 msg['Subject'] = 'autobuild success'
561 msg['From'] = 'autobuild@samba.org'
562 msg['To'] = options.email
564 s = smtplib.SMTP()
565 s.connect()
566 s.sendmail(msg['From'], [msg['To']], msg.as_string())
567 s.quit()
570 (options, args) = parser.parse_args()
572 if options.retry:
573 if options.rebase is None:
574 raise Exception('You can only use --retry if you also rebase')
576 testbase = "%s/b%u" % (options.testbase, os.getpid())
577 test_master = "%s/master" % testbase
579 # get the top commit message, for emails
580 top_commit_msg = run_cmd("git log -1", dir=gitroot, output=True)
582 try:
583 os.makedirs(testbase)
584 except Exception, reason:
585 raise Exception("Unable to create %s : %s" % (testbase, reason))
586 cleanup_list.append(testbase)
588 if options.daemon:
589 logfile = os.path.join(testbase, "log")
590 print "Forking into the background, writing progress to %s" % logfile
591 daemonize(logfile)
593 write_pidfile(gitroot + "/autobuild.pid")
595 while True:
596 try:
597 run_cmd("rm -rf %s" % test_master)
598 cleanup_list.append(test_master)
599 run_cmd("git clone --shared %s %s" % (gitroot, test_master), show=True, dir=gitroot)
600 except Exception:
601 cleanup()
602 raise
604 try:
605 try:
606 if options.rebase is not None:
607 rebase_tree(options.rebase, rebase_branch=options.branch)
608 except Exception:
609 cleanup_list.append(gitroot + "/autobuild.pid")
610 cleanup()
611 email_failure(-1, 'rebase', 'rebase', 'rebase',
612 'rebase on %s failed' % options.branch,
613 log_base=options.log_base)
614 sys.exit(1)
615 blist = buildlist(tasks, args, options.rebase, rebase_branch=options.branch)
616 if options.tail:
617 blist.start_tail()
618 (status, failed_task, failed_stage, failed_tag, errstr) = blist.run()
619 if status != 0 or errstr != "retry":
620 break
621 cleanup()
622 except Exception:
623 cleanup()
624 raise
626 cleanup_list.append(gitroot + "/autobuild.pid")
628 blist.kill_kids()
629 if options.tail:
630 print("waiting for tail to flush")
631 time.sleep(1)
633 if status == 0:
634 print errstr
635 if options.passcmd is not None:
636 print("Running passcmd: %s" % options.passcmd)
637 run_cmd(options.passcmd, dir=test_master)
638 if options.pushto is not None:
639 push_to(options.pushto, push_branch=options.branch)
640 if options.keeplogs:
641 blist.tarlogs("logs.tar.gz")
642 print("Logs in logs.tar.gz")
643 if options.always_email:
644 email_success(log_base=options.log_base)
645 blist.remove_logs()
646 cleanup()
647 print(errstr)
648 sys.exit(0)
650 # something failed, gather a tar of the logs
651 blist.tarlogs("logs.tar.gz")
653 if options.email is not None:
654 email_failure(status, failed_task, failed_stage, failed_tag, errstr, log_base=options.log_base)
656 cleanup()
657 print(errstr)
658 print("Logs in logs.tar.gz")
659 sys.exit(status)