diff options
author | duerpei <duep.fnst@fujitsu.com> | 2023-03-08 13:48:03 +0800 |
---|---|---|
committer | duerpei <duep.fnst@fujitsu.com> | 2023-03-08 13:48:03 +0800 |
commit | 0124d938848301f8768d715b20dc1c4af486dd33 (patch) | |
tree | 70e8e75bf09e15fcdb05084f5c249fd0768fdcf5 /plugins/agl_test_report.py | |
parent | 9648099248359cb00aa0c31d5436b537b0571853 (diff) |
agl-test-framework: solve bugs in the test framework
Fixed problems:
1.When all the executed test suites are skipped, no new summary-
report is generated.
2.When there is test suite successfully executed, the generated
summary-report will contain the test suites which have logs
in the "/tmp-log" directory, rather than just the test suites
which has just executed.
Correction method:
1.Move the function in "conftest.py" to "agl_test_report.py"
and call it in the "agl-test" script to ensure that the
function will be executed.
2.Set the timestamp to record the information of each executed
test suite or skipped test suite to the file of
"test_list_timestamp". And generate a summar-report according
to the above file.
Bug-AGL: SPEC-4345
Signed-off-by: duerpei <duep.fnst@fujitsu.com>
Change-Id: I47bfd09706e37ce6bdc13f3f9f266bc62f74f777
Diffstat (limited to 'plugins/agl_test_report.py')
-rw-r--r-- | plugins/agl_test_report.py | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/plugins/agl_test_report.py b/plugins/agl_test_report.py index ad7b9e6..4376d35 100644 --- a/plugins/agl_test_report.py +++ b/plugins/agl_test_report.py @@ -1,6 +1,8 @@ import json import shutil +import zipfile import subprocess +from jinja2 import Environment,FileSystemLoader import plugins.agl_test_conf as conf @@ -178,3 +180,183 @@ def format_html_data(summary_data): summary_data["test_suite_status_html"] = status_html return summary_data + +def generate_total_summary_files(time_stamp): + #Get the summary data and write to report.json file + test_list = conf.TMP_LOGS_DIR + "test_list_" + str(time_stamp) + ".json" + summary_data = get_summary_data(test_list) + if(summary_data['summary']['summary_total'] == 0): + return 0 + summary_json = conf.TMP_LOGS_DIR + "/report.json" + with open(summary_json, 'w') as summary_file: + json.dump(summary_data,summary_file,indent=4,sort_keys=False) + summary_file.close() + + #Get zip file name + issue = subprocess.getoutput('cat /etc/issue') + version = issue[23:-7] + machine_name = subprocess.getoutput('uname -n') + zip_name = "agl-test-log-" + version + '-' + machine_name + '-' + time_stamp + + #Get summary_html_data + summary_html_data = format_total_summary_html_data(summary_data) + summary_html_data["log_zip_name"] = zip_name + + #Get current timestamp for total summary html report + date_F = subprocess.getoutput("date +%F") + summary_html_data["date_F"] = date_F + date_T = subprocess.getoutput("date +%T") + summary_html_data["date_T"] = date_T + + #Creat total summary report in html + env = Environment(loader=FileSystemLoader(conf.get_tpl_dir())) + template = env.get_template("all_test_suites_tpl.html") + html_path = conf.TMP_LOGS_DIR + "test-report/summary-report.html" + with open(html_path, "w") as html_file: + html_content = template.render(data=summary_html_data) + html_file.write(html_content) + html_file.close() + + #Copy total summary report file + source_file = conf.TMP_LOGS_DIR + "test-report/summary-report.html" + target_file = conf.REPORT_LOGS_DIR + "summary-report.html" + shutil.copyfile(source_file,target_file) + + #Package the test report + base_name = conf.REPORT_LOGS_DIR + zip_name + root_dir = conf.TMP_LOGS_DIR + "test-report" + make_zip_file(test_list, base_name, root_dir) + +def make_zip_file(test_list, base_name, root_dir): + with open(test_list, 'r') as f: + test_suites = json.load(f) + f.close() + zip_name = base_name + ".zip" + zipf = zipfile.ZipFile(zip_name, 'a') + summ_file = root_dir + "/" + "summary-report.html" + zipf.write(summ_file, "summary-report.html") + + for key in test_suites.keys(): + sub_dir = root_dir + "/" + key + "/" + zipf.write(sub_dir, key) + if(test_suites[key]["status"] == "run"): + zipf.write(sub_dir+"/log.zip", key+"/log.zip") + zipf.write(sub_dir+"/report.html", key+"/report.html") + zipf.close() + +#Summarize all reports.json file +def get_summary_data(test_list): + summary_data = {} + summary_total = summary_passed = summary_failed = summary_skipped = 0 + with open(test_list,'r') as f: + test_suites = json.load(f) + f.close() + + for key in test_suites.keys(): + if(test_suites[key]["status"] == "skip"): + this_summary = { + 'total': "null", + 'passed': "null", + 'xpassed': "null", + 'failed': "null", + 'xfailed': "null", + 'skipped': "null", + 'test_status': "skipped", + } + summary_data[key] = this_summary + + summary_total = summary_total + 1 + summary_skipped = summary_skipped + 1 + + if(test_suites[key]["status"] == "run"): + report = test_suites[key]["path"] + report_json = conf.TMP_LOGS_DIR + report + with open(report_json,'r') as f: + data = json.load(f) + f.close() + + total = passed = xpassed = failed = xfailed = skipped = 0 + total = data["collected"] + passed = data["passed"] + xpassed = data["xpassed"] + failed = data["failed"] + xfailed = data["xfailed"] + skipped = data["skipped"] + test_status = data["test_status"] + test_name = data["test_name"] + + this_summary = { + 'total': total, + 'passed': passed, + 'xpassed': xpassed, + 'failed': failed, + 'xfailed': xfailed, + 'skipped': skipped, + 'test_status': test_status, + } + summary_data[key] = this_summary + + summary_total = summary_total + 1 + if(test_status=="passed"): + summary_passed = summary_passed + 1 + elif(test_status=="failed"): + summary_failed = summary_failed + 1 + else: + summary_skipped = summary_skipped + 1 + + summary_data["summary"] = { + "summary_total": summary_total, + "summary_passed": summary_passed, + "summary_failed": summary_failed, + "summary_skipped": summary_skipped, + } + + status = "" + if (summary_data["summary"]["summary_total"] == summary_data["summary"]["summary_skipped"]): + status = "skipped" + elif (summary_data["summary"]["summary_failed"] == 0): + status = "passed" + else: + status = "failed" + summary_data["summary"]["status"] = status + + return summary_data + +def format_total_summary_html_data(summary_data): + html_data = "" + #init all rows + for key in summary_data: + if(key != "summary"): + html_data += "\t\t\t<tbody class=\"" + html_data += summary_data[key]["test_status"] + "\">\n" + html_data += "\t\t\t\t<tr>\n" + html_data += "\t\t\t\t<td class=\"col-result\">" + html_data += str.capitalize(summary_data[key]["test_status"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + key + "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["total"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["passed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["skipped"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["failed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["xfailed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["xpassed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t</tr>\n" + html_data += "\t\t\t</tbody>\n" + + summary_data["test_suite_table_html"] = html_data + + #Create summry status in html + summry_status_html = "" + summry_status_html += "\t\t<p>test suite status : <span class=\"" + summry_status_html += summary_data["summary"]["status"] + "\">" + summry_status_html += str.capitalize(summary_data["summary"]["status"]) + summry_status_html += "</span></p>" + summary_data["summry_status_html"] = summry_status_html + + return summary_data |