Jenkins: Get error message from install-check FAIL Closes #124
Project: http://git-wip-us.apache.org/repos/asf/incubator-madlib/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-madlib/commit/8bd4947f Tree: http://git-wip-us.apache.org/repos/asf/incubator-madlib/tree/8bd4947f Diff: http://git-wip-us.apache.org/repos/asf/incubator-madlib/diff/8bd4947f Branch: refs/heads/latest_release Commit: 8bd4947fefb29a977f1239905472fda41fa76ae0 Parents: 3af18a9 Author: Rahul Iyer <ri...@apache.org> Authored: Thu Apr 20 18:01:05 2017 -0700 Committer: Rahul Iyer <ri...@apache.org> Committed: Wed Apr 26 14:17:06 2017 -0700 ---------------------------------------------------------------------- src/madpack/madpack.py | 9 +++++---- tool/jenkins/jenkins_build.sh | 4 +++- tool/jenkins/junit_export.py | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/8bd4947f/src/madpack/madpack.py ---------------------------------------------------------------------- diff --git a/src/madpack/madpack.py b/src/madpack/madpack.py index 049adf5..c5dd1f9 100755 --- a/src/madpack/madpack.py +++ b/src/madpack/madpack.py @@ -932,7 +932,7 @@ def _db_create_objects(schema, old_schema, upgrade=False, sc=None, testcase="", sc) # Check the exit status if retval != 0: - _error("Failed executing %s" % tmpfile, False) + _error("TEST CASE RESULTed executing %s" % tmpfile, False) _error("Check the log at %s" % logfile, False) raise Exception # ------------------------------------------------------------------------------ @@ -1489,8 +1489,6 @@ def main(argv): # Check the exit status if retval != 0: - _error("Failed executing %s" % tmpfile, False) - _error("Check the log at %s" % logfile, False) result = 'FAIL' keeplogs = True # Since every single statement in the test file gets logged, @@ -1501,11 +1499,14 @@ def main(argv): else: result = 'ERROR' - # Spit the line + # Output result print "TEST CASE RESULT|Module: " + module + \ "|" + os.path.basename(sqlfile) + "|" + result + \ "|Time: %d milliseconds" % (milliseconds) + if result == 'FAIL': + _error("Failed executing %s" % tmpfile, False) + _error("Check the log at %s" % logfile, False) # Cleanup test schema for the module _internal_run_query("DROP SCHEMA IF EXISTS %s CASCADE;" % (test_schema), True) http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/8bd4947f/tool/jenkins/jenkins_build.sh ---------------------------------------------------------------------- diff --git a/tool/jenkins/jenkins_build.sh b/tool/jenkins/jenkins_build.sh index f03bc78..d0f5510 100644 --- a/tool/jenkins/jenkins_build.sh +++ b/tool/jenkins/jenkins_build.sh @@ -64,7 +64,9 @@ echo "---------- Installing and running install-check --------------------" # Install MADlib and run install check cat <<EOF docker exec madlib /build/src/bin/madpack -p postgres -c postgres/postgres@localhost:5432/postgres install | tee $workdir/logs/madlib_install.log -docker exec madlib /build/src/bin/madpack -p postgres -c postgres/postgres@localhost:5432/postgres install-check | tee $workdir/logs/madlib_install_check.log + +mkdir -p $workdir/tmp +docker exec madlib /build/src/bin/madpack -p postgres -c postgres/postgres@localhost:5432/postgres -d $workdir/tmp install-check | tee $workdir/logs/madlib_install_check.log EOF docker exec madlib /build/src/bin/madpack -p postgres -c postgres/postgres@localhost:5432/postgres install | tee $workdir/logs/madlib_install.log docker exec madlib /build/src/bin/madpack -p postgres -c postgres/postgres@localhost:5432/postgres install-check | tee $workdir/logs/madlib_install_check.log http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/8bd4947f/tool/jenkins/junit_export.py ---------------------------------------------------------------------- diff --git a/tool/jenkins/junit_export.py b/tool/jenkins/junit_export.py index ce30320..1836ea4 100644 --- a/tool/jenkins/junit_export.py +++ b/tool/jenkins/junit_export.py @@ -19,6 +19,7 @@ import re import sys +import subprocess from collections import namedtuple """ Convert install-check results into a standardized JUnit XML format @@ -36,7 +37,7 @@ Example of JUnit output: """ -TestResult = namedtuple("TestResult", 'name suite status duration') +TestResult = namedtuple("TestResult", 'name suite status duration message') def _test_result_factory(install_check_log): @@ -48,11 +49,29 @@ def _test_result_factory(install_check_log): Next result of type test_result """ with open(install_check_log, 'r') as ic_log: - for line in ic_log: + line = ic_log.readline() + while line: m = re.match(r"^TEST CASE RESULT\|Module: (.*)\|(.*)\|(.*)\|Time: ([0-9]+)(.*)", line) if m: - yield TestResult(name=m.group(2), suite=m.group(1), - status=m.group(3), duration=m.group(4)) + suite, name, status, duration = [m.group(i) for i in range(1, 5)] + message = "" + if status == 'FAIL': + # get the tmp file and log file containing error + # these two lines are output after each failure + tmp_file_line = ic_log.readline() + log_file_line = ic_log.readline() + failure_m = re.match(r".* Check the log at (.*)", log_file_line) + if failure_m: + log_file = failure_m.group(1) + try: + message = subprocess.check_output(['tail', '-n 100', log_file], + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + message = e.output + yield TestResult(name=name, suite=suite, + status=status, duration=duration, + message=message) + line = ic_log.readline() # ---------------------------------------------------------------------- @@ -68,15 +87,17 @@ def _add_footer(out_log): def _add_test_case(out_log, test_results): - for res in test_results: + for t in test_results: try: # convert duration from milliseconds to seconds - duration = float(res.duration)/1000 + duration = float(t.duration)/1000 except TypeError: duration = 0.0 output = ['<testcase classname="{t.suite}" name="{t.name}" ' 'status="{t.status}" time="{d}">'. - format(t=res, d=duration)] + format(t=t, d=duration)] + if t.status == "FAIL": + output.append('<failure>{0}</failure>'.format(t.message)) output.append('</testcase>') out_log.write('\n'.join(output)) @@ -93,4 +114,6 @@ def main(install_check_log, test_output_log): if __name__ == "__main__": + # argv[1] = install check log + # argv[2] = output file to store xml main(sys.argv[1], sys.argv[2])