def read_auth(): try: jira_auth = global_config.get_conf("auth", "jira") return (jira_auth["username"], jira_auth["password"]) except KeyError as e: raise ComparerException("No key %s in global config" % repr(e))
def upload(sut_name, test_id, conf_file): try: jira_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) sys.exit(1) jira_url = global_config.get_conf("urls", "jira") jira = jiralib.JIRA(jira_url, jira_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) print("Initiating JIRA uploader...") try: check_xray_report(testfolder_path) issue_key = create_issue(sut_name, jira, sutfolder_path, testfolder_path) import_xray(jira, issue_key, testfolder_path) upload_attachments(jira, issue_key, testfolder_path, sut_name, test_id, conf_file) except (JiraException, FileException) as err: print("error:", err) print("Aborting JIRA upload") return 1 print("Jira upload done") return 0
def boot_time_upload(sut_name, test_id, test_type, skip, conf_file=DEFAULT_CONF_FILE): print("Starting Boot Time Upload for", sut_name) try: auth = uploader_common.get_jira_auth() jira_url = global_config.get_conf("urls", "jira") except (IOError, PermissionError, ArgumentError, FileNotFoundError, json.decoder.JSONDecodeError, KeyError) as e: print("Error when reading auth from config:", file=sys.stderr) uploader_common.print_exc(e) sys.exit(1) test_props = get_test_properties(test_type) try: 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) image_url = uploader_common.read_file(os.path.join( sutfolder_path, \ "last_installed_zip.txt")).strip() image = os.path.basename(image_url) project = image.split("-")[2] measurement = get_image_measurement(project, conf_file) try: issues_path = os.path.join(argotestroot, test_props["issues_dir"]) except TypeError as e: print("Bad image_type:", e) sys.exit(1) except KeyError as e: print("No issues_dir key for image type " + test_type, e) sys.exit(1) master_folder = os.path.join(issues_path, image) os.makedirs(master_folder, exist_ok=True) shutil.copyfile(os.path.join(sutfolder_path, test_id, "boots.csv"), \ os.path.join(master_folder, "boots.csv")) #Fetch information how many images are drawn into the graph images_to_draw = uploader_common.read_json(conf_file)["num_images_boot_time"] #Fetch information about the previous images images_to_draw = get_previous_images(image, issues_path, images_to_draw) key = get_jira_key(os.path.join(master_folder, image + "_key.json")) #Use sufu_csv2graph to draw some lines output_filename = test_type + "-" + project + "-BootTime.png" result_image_path = os.path.join(master_folder, output_filename) draw_graph(images_to_draw, issues_path, result_image_path, measurement) if key and not skip: upload_graph_to_jira(jira, result_image_path, key) dav_url = uploader_common.get_url_from_conf("dav", conf_file) upload_graph_to_dav(dav_url, result_image_path, auth) if (test_props.get("release", False)): shutil.copyfile(path.join(master_folder, output_filename), path.join(sutfolder_path, test_id, output_filename)) except BootUploadError as e: print("BootUploadError:", e) return 1 return 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)
def get_jira_auth(): jira_auth = global_config.get_conf("auth", "jira") return (jira_auth["username"], jira_auth["password"])