Exemplo n.º 1
0
def compare_results(issue_key, new_xray, master_xray, tests_json, first_xray):
	print("Starting to compare autotest results")
	try:
		results = uploader_common.read_json(tests_json)
	except FileNotFoundError:
		new_res = uploader_common.read_json(new_xray)
		new_tests = new_res['tests']
		results = {}
		results["cases"] = []
		for new_test in new_tests:
			new_test_key = new_test["testKey"]
			results[new_test_key] = []
			results["cases"].append(new_test_key)
			results[new_test_key].append(new_test['status'])
			results["runs"] = 0

	#If there is no master xray_report, the current test result can be just copied
	if not os.path.isfile(master_xray):
		master_res =_compare_results_new_task(master_xray, new_xray, first_xray)

	#otherwise the master_xray_report and newly created report have to be compared and master_xray_report is modified
	#according to specifications of which results overwrite which.
	else:
		master_res = uploader_common.read_json(master_xray)
		new_res = uploader_common.read_json(new_xray)
		results = _compare_two_xrays(master_res, new_res, results)
	print(results)
	results['runs'] += 1
	master_res['testExecutionKey'] = issue_key
	uploader_common.dump_to_file(master_xray, master_res)
	uploader_common.dump_to_file(tests_json, results)
Exemplo n.º 2
0
def import_xray(jira, issue_key, testfolder_path):
    #Append the new issue_key into the test result xray_report.json
    xray_file = os.path.join(testfolder_path, "xray_report.json")
    data = uploader_common.read_json(xray_file)
    data["testExecutionKey"] = issue_key
    uploader_common.dump_to_file(xray_file, data)
    jira.import_xray(issue_key, xray_file)
Exemplo n.º 3
0
def update_jira_attachments(jira, fm, master_path, issue_key, conf_file):
	attachments = os.path.join(master_path, "attachments.json")
	if os.path.exists(attachments):
		delete_attachment(jira, attachments)
	conf = uploader_common.read_json(conf_file)
	image_names = conf["graphs"]
	for image in image_names:
		fm.add_file(os.path.join(master_path, image))
	result_attachments = jira.upload_files(issue_key, fm)
	uploader_common.dump_to_file(attachments, result_attachments)
Exemplo n.º 4
0
def compare_and_upload(sut_name, test_id, conf_file=DEFAULT_CONF_FILE, key=None):
	try:
		auth = uploader_common.get_jira_auth()
	except (FileNotFoundError, json.decoder.JSONDecodeError, KeyError) as e:
		print("Error when reading auth from config:", file=sys.stderr)
		uploader_common.print_exc(e, f=sys.stderr)
		return 1

	new_task = False

	jira_url = global_config.get_conf("urls", "jira")
	jira = jiralib.JIRA(jira_url, auth)

	argotestroot = uploader_common.get_path_from_conf("argotest", conf_file)
	sutfolder_path = os.path.join(argotestroot, "TestReports_" + sut_name)
	testfolder_path = os.path.join(sutfolder_path, test_id)

	if not os.path.isdir(testfolder_path):
		print("Unable to find testfolder", testfolder_path, "\nExiting...")
		return 1

	last_installed_zip_url = uploader_common.read_file(os.path.join(sutfolder_path, \
							"last_installed_zip.txt")).strip()
	last_installed_zip = os.path.basename(last_installed_zip_url)
	master_path = os.path.join(argotestroot, "nightly_issue_keys", last_installed_zip)
	zip_key_file = os.path.join(master_path, last_installed_zip + "_key.json")

	if not key:
		if os.path.exists(zip_key_file) == False:
			print("No issue key for this image")
			os.makedirs(master_path, exist_ok=True)
			issue_key_json = create_key(jira, last_installed_zip_url, \
							argotestroot, \
							uploader_path, sut_name)
			uploader_common.dump_to_file(zip_key_file, issue_key_json)
			shutil.copyfile(os.path.join(testfolder_path, "report.jsonl.zlib"), \
						os.path.join(master_path, "master_report.jsonl.zlib"))
			new_task = True

		key = uploader_common.get_issue_key(zip_key_file)
	#Now we have the key, lets start comparing the current xray_report to the master_xray_report

	#If the test run does not contain the xray_report file, something has gone wrong, but the
	#test results are imported to the issue as empty
	if not os.path.isfile(os.path.join(testfolder_path, "xray_report.json")):
		#send a comment to issue that something has gone wrong
		jira.upload_comment(key, \
			"Unable to run autotests. Check logs for more information")
	else:
		on_test_success(key, master_path, testfolder_path, jira, \
			test_id, sut_name, new_task)

	if new_task:
		on_new_task(testfolder_path, master_path, sut_name, test_id, key, argotestroot,\
				jira, last_installed_zip)
Exemplo n.º 5
0
def upload_attachments(jira, issue_key, testfolder_path, sut_name, test_id,
                       conf_file):
    attachments = os.path.join(testfolder_path, "attachments.json")
    with jiralib.MultipleFileManager() as fm:
        fm.add_file(
            os.path.join(testfolder_path,
                         sut_name + "-" + test_id + "-cron.log"))
        fm.add_file(
            os.path.join(testfolder_path,
                         sut_name + "-" + test_id + "-log_TestRun.txt"))
        conf = uploader_common.read_json(conf_file)
        graphs = conf["graphs"]
        for graph in graphs:
            fm.add_file(os.path.join(testfolder_path, graph))
        result_attachments = jira.upload_files(issue_key, fm)
        uploader_common.dump_to_file(attachments, result_attachments)
Exemplo n.º 6
0
def create_issue(sut_name, jira, sutfolder_path, testfolder_path):

    issue_data = modify_template(sut_name, sutfolder_path, testfolder_path)
    print("Creating JIRA issue")
    #Creates a issue_key.json file in the testfolder. If already exists, writes over
    try:
        retjson = jira.create_issue(issue_data)
    except jiralib.JIRAException as e:
        raise JiraException("Could not create JIRA issue:", e)
    try:
        issue_key = retjson["key"]
        key_file = os.path.join(testfolder_path, "issue_key.json")
        uploader_common.dump_to_file(key_file, retjson)

    except KeyError as e:
        raise JiraException("Key %s missing from JIRA issue create response" %
                            e)

    return issue_key