diff options
author | Arthur She <arthur.she@linaro.org> | 2015-10-21 22:26:34 -0700 |
---|---|---|
committer | Arthur She <arthur.she@linaro.org> | 2015-10-21 22:26:34 -0700 |
commit | b9c144c1e6c105071671dd622305e312ece1ac3b (patch) | |
tree | d276ad7e291cab2fd8a8a10fd088c6f203330ab2 | |
parent | df9f3409c1f233948f73a504d7d26f70d9b2ab53 (diff) |
1. Once there're some errors, uncompleted test job or test job parse
error, the report will not be generated.
2. Add option '-f' to force generate report even there're some errors.
modified: report_automation.py
-rwxr-xr-x | report_automation.py | 79 |
1 files changed, 58 insertions, 21 deletions
diff --git a/report_automation.py b/report_automation.py index dedce1d..4e84c47 100755 --- a/report_automation.py +++ b/report_automation.py @@ -22,6 +22,14 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) #logger.setLevel(logging.INFO) +class TestJobParseError(Exception): + def __init__(self, job_id): + self.job_type = job_id + + def __str__(self): + return repr(self.job_id) + + class LinaroAndroidBuildSystem(object): def __init__(self, base_url, build_job, username=None, password=None): @@ -34,14 +42,14 @@ class LinaroAndroidBuildSystem(object): self.jenkins = Jenkins(self.base_url, self.username, self.password) self.project = self.jenkins[self.build_job] except Exception as e: - logger.exception("Can not get Jenkins job: %s" % project) + logger.warning("Can not get Jenkins job: %s" % project) def get_build(self, build_no): try: build = self.project.get_build(build_no) return build except Exception as e: - logger.exception("Can not get build: #%d" % build_no) + logger.warning("Can not get build: #%d" % build_no) def get_test_job_ids(self, build_no): logger.info("Querying build #%d test job ids from Jenkins build job: %s" % @@ -52,6 +60,7 @@ class LinaroAndroidBuildSystem(object): return job_id_list + class LAVA(object): def __init__(self, username, token, lava_server="https://validation.linaro.org/"): try: @@ -61,7 +70,7 @@ class LAVA(object): server_url = "https://%s:%s@%sRPC2/" % (self.username, self.token, self.lava_server.split("//")[1]) self.server = xmlrpclib.ServerProxy(server_url) except: - logger.exception("Can not connect to LAVA server: %s" % lava_server) + logger.warning("Can not connect to LAVA server: %s" % lava_server) exit(-1) def get_job_info(self, job_no): @@ -69,10 +78,10 @@ class LAVA(object): try: job_status = self.server.scheduler.job_status(job_no) except Exception as e: - logger.exception("Can not get any information for test job: %s" % job_no) + logger.warning("Can not get any information for test job: %s" % job_no) if job_status['job_status'] != 'Complete': - logger.warning("!!Job #%s is not a complete job.\n\tJob status: %s!! " % (job_no, job_status['job_status'])) + logger.warning("!!Job #%s is not completed.\n\tJob status: %s!! " % (job_no, job_status['job_status'])) else: job_detail = self.server.scheduler.job_details(job_no) job_info['job_no'] = job_no @@ -119,7 +128,10 @@ class Report(object): # } # ] # } - self.lava_tests = {} + self.lava_tests = { + "result_link": "", + "test_cases": [] + } # self.lava_tests = { # "result_link": "RESULT BUNDLE URL", # "test_cases": [ @@ -193,7 +205,9 @@ class Report(object): t['test_id'] == 'wa2-host-postprocessing').next() src = (s for s in test_run['software_context']['sources'] if 'test_params' in s).next() except Exception as e: - logger.exception("\tJob %s seems not be a completed job." % job_info['job_no']) + logger.warning("\tJob %s seems not be a completed job." % job_info['job_no']) + raise TestJobParseError(job_info['job_no']) + if test_run['test_id'] == 'lava-android-benchmark-host': benchmark_test['test_id'] = ast.literal_eval(src['test_params'])['TEST_NAME'] else: @@ -225,7 +239,8 @@ class Report(object): attachment = (a for a in test_run['attachments'] if a['pathname'].startswith('android-cts')).next() except Exception as e: - logger.exception("\tJob %s seems not be a completed job." % job_info['job_no']) + logger.warning("\tJob %s seems not be a completed job." % job_info['job_no']) + raise TestJobParseError(job_info['job_no']) if attachment is not None: try: @@ -235,7 +250,7 @@ class Report(object): compressed = zipfile.ZipFile(outfile) compressed.extractall() except Exception as e: - logger.exception("\tCan not extract attachment: %s" % attachment['pathname']) + logger.warning("\tCan not extract attachment: %s" % attachment['pathname']) CTS_TEST_RESULT_DIR = "./%s" % attachment['pathname'].split('/')[-1].split('.zip')[0] CTS_RESULT_FILE = "%s/%s" % (CTS_TEST_RESULT_DIR, CTS_RESULT_FILE_NAME) tree = ET.parse(CTS_RESULT_FILE) @@ -282,7 +297,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description="""This script will collect all data and make a report. -The authentication credential for LAVA server should be put in ~/.netrc +The authentication credential for LAVA/Jenkins server should be put in ~/.netrc e.g. machine validation.linaro.org login USERNAME @@ -301,9 +316,12 @@ e.g. help="Specify the report template. This is optional.\nDefault: %s" % REPORT_TEMPLATE) parser.add_argument("-o", "--output", dest="output_file", default=REPORT_OUTPUT, help="Specify the output file name. This is optional.\nDefault: %s" % REPORT_OUTPUT) + parser.add_argument("-f", "--force-report", dest="force_report", + help="Generate report even there're some errors", action="store_true") args = parser.parse_args() + generate_report = True try: lava_login_info = netrc.netrc().authenticators("validation.linaro.org") except: @@ -336,18 +354,37 @@ e.g. logger.info(test_job_ids) logger.info("Going to parse these test jobs!!") + uncompleted_job = [] + parse_error_job = [] for job in test_job_ids: job_info = {} job_info = lava_server.get_job_info(job) if job_info: - if job_info['type'] == 'lava_test': - rep_obj.parse_lava_test(job_info) - elif job_info['type'] == 'benchmark': - rep_obj.parse_benchmark_test(job_info) - elif job_info['type'] == 'cts': - rep_obj.parse_cts(job_info) - - logger.info("Prepare for the report!!") - data = rep_obj.to_dict() - t.render(data) - logger.info("Done, the output report is \"%s\"" % REPORT_OUTPUT) + try: + if job_info['type'] == 'lava_test': + rep_obj.parse_lava_test(job_info) + elif job_info['type'] == 'benchmark': + rep_obj.parse_benchmark_test(job_info) + elif job_info['type'] == 'cts': + rep_obj.parse_cts(job_info) + except TestJobParseError as e: + parse_error_job.append(job) + else: + uncompleted_job.append(job) + + print("------------------------------------------------------") + if uncompleted_job or parse_error_job: + if args.force_report: + generate_report = True + else: + generate_report = False + logger.info("Something wrong, the report will not be generated!!") + logger.info("%d uncompleted test jobs: %s" % (len(uncompleted_job), ', '.join(uncompleted_job))) + logger.info("%d test jobs parse error: %s" % (len(parse_error_job), ', '.join(parse_error_job))) + + if generate_report: + logger.info("Prepare for the report!!") + data = rep_obj.to_dict() + t.render(data) + logger.info("Done, the output report is \"%s\"" % REPORT_OUTPUT) + |