def test_result_update( sheet_number, row_number, data_list, analysis_file_update=False ): if analysis_file_update: result_file_path = ( os.path.abspath(".") + "/config/" + Common.get_config_value("analysis_input_file") ) else: result_file_path = ( os.path.abspath(".") + "/report/" + Common.get_config_value("analysis_output_file") ) xlsObj, wb_copy = Xlsparser.copy_xls(result_file_path, sheet_number) column_number = 0 for content in data_list: xlsObj.write( row_number, column_number, f"{content}", Xlsparser.cell_styles() ) column_number += 1 wb_copy.save(result_file_path) del xlsObj del wb_copy
def env_setup(): if not os.path.isfile( os.path.join(os.path.abspath("."), Common.get_config_value("data_location"))): os.mkdir( os.path.join(os.path.abspath("."), Common.get_config_value("data_location"))) return 0
def __enter__(self): self.jenkinsObj = Jenkins( Common.get_config_value("jenkins_base_url"), Common.decrypt(Common.get_config_value("jenkins_username")), Common.decrypt(Common.get_config_value("jenkins_password")), ssl_verify=False, ) return self.jenkinsObj
def index_pagination(job_name): """ This API is used to list the job based on their job name :param str job_name: Name of the Jenkins job :return: redirect the build history page """ fs = regex_data_retrieval(job_name=job_name) if fs.count() == 0: return render_template("404.html", title="404"), 404 try: pattern_type = re.search(r"\w*-\w*", job_name).group() except AttributeError: Common.logger.warn( f"index_pagination:failed to search the job name: {job_name}") pattern_type = job_name offset = {"page": 1, "per_page": Common.get_config_value("per_page")} page, per_page, offset = get_page_args(page_parameter="page", per_page_parameter="per_page", **offset) pagination_items = page_list(fs, per_page=per_page, offset=offset) pagination = Pagination(page=page, per_page=per_page, total=fs.count(), css_framework="bootstrap4") return render_template( "index_pagination.html", List=pagination_items, page=page, per_page=per_page, pagination=pagination, pattern_type=pattern_type, job_name=job_name, )
def download_the_logs(downloadlink, job_name): status = subprocess.call( [ "wget {} -P {}/{} --no-check-certificate".format( downloadlink, os.path.abspath("."), Common.get_config_value("data_location"), ) ], shell=True, ) if status == 0: rename_file_name = "{}_{}".format(job_name, random.randint(1, 10000)) os.rename( f"{os.path.abspath('.')}/{Common.get_config_value('data_location')}" "/consoleFull", f"{os.path.abspath('.')}/{Common.get_config_value('data_location')}/" f"{rename_file_name}", ) if os.path.isfile( f"{os.path.abspath('.')}/{Common.get_config_value('data_location')}" f"/consoleFull") else "Nothing" Common.logger.info(f"[download_the_logs] Downloaded logs renamed") return rename_file_name else: Common.logger.warn( f"[download_the_logs]: The job does not exist {job_name} " f"and downloadable link {downloadlink}") return False
def edit_observation(pattern_type, id): """ This API is used to edit the observation based on the available record. :param pattern_type: :param id: """ fs = accessing_data_via_id(build_id=f"{id}") if fs.count() == 0: return render_template("404.html", title="404"), 404 record = Common.collection_creation(fs)[0] form = ObservationUpdate(request.form) if request.method == "POST": Common.logger.info( f"edit_observation: Post API called against id {id} and pattern type" f" {pattern_type}") observations = ast.literal_eval(form.data["observation_data"]) try: Common.logger.info( f"edit_observation: The provided observation is {observations}" f" {pattern_type}") if pattern_type not in Common.get_config_value("test_map"): if type(observations) is dict: for observation in observations: db_update( observation_record_key=f"{observation}", observation_record_value="{}".format( observations[observation]), ) record["Validation"] = Common.record_updater( record["Validation"], observations) update_record(f"{id}", old_record=record) else: os.popen("touch problem_in_before_update") failed_test_details = { "test_details": record["Validation"]["Pre_Upgrade_test_Failure"] } updated_data = Common.record_updater(failed_test_details, observations) record["Validation"][ "Pre_Upgrade_test_Failure"] = updated_data["test_details"] update_record(f"{id}", old_record=record) except Exception as ex: Common.logger.warn( f"edit_observation: The provided dictionary is not in correct " f"format {ex}") flash( "Please provide the proper dictionary format {} of pattern {}". format(observations, pattern_type)) return render_template("observation.html", form=form, pattern_type=pattern_type, record=record) flash("Data Submitted Successfully") return render_template("observation.html", form=form, pattern_type=pattern_type, record=record)
def build_execution_time(job_name, build_no): job_url = (Common.get_config_value("jenkins_base_url") + f"/job/{job_name}/{build_no}/api/python?tree=timestamp") timestamp_response = requests.get(url=job_url, verify=False) if timestamp_response.status_code == 200: Common.logger.info( f"[build_execution_time] Build Execution time has collected " f"{timestamp_response.json()['timestamp']}") return timestamp_response.json()["timestamp"] else: Common.logger.warn( f"[build_execution_time]: Build execution time identification " f"failed get response {timestamp_response.status_code}") return timestamp_response.status_code
def ssh_object(machine_name): """ This method is used to create an ssh object and the machine status(ping or not) :param str machine_name: machine hostname. :return: ssh_object """ if os.system(f"ping -c1 {machine_name} 2>/dev/null 1>/dev/null") != 0: return False ssh_object = paramiko.SSHClient() ssh_object.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for password in Common.get_config_value("build_machine_password"): ssh_object = Common.ssh_connection_handling( ssh_object, machine_name, Common.get_config_value("build_machine_username"), password, ) if not ssh_object: continue else: break return ssh_object
def header_of_table(self): """ This method use to create the header data in report file. """ style = Xlsparser.font(True) result_file_path = (os.path.abspath(".") + "/report/" + Common.get_config_value("analysis_output_file")) if self.prop_obj.rows_no == 0: xls_report = Xlsparser(result_file_path, Xlsparser.MODEWRITE) xls_report.open_work_book(result_file_path) xls_report.write_row( 0, 0, [ "Job-Name", "Build Number" "Build Status", "Validation", "Build Time" ], style, ) xls_report.close_work_book() self.prop_obj.rows_no = self.prop_obj.rows_no + 1
def list_of_error(): """ This API is used to list down the errors and observations """ fs = accessing_observation_db() Common.logger.info( "list_of_error: GET method call for the list of the observations ") offset = {"page": 1, "per_page": Common.get_config_value("per_page")} page, per_page, offset = get_page_args(page_parameter="page", per_page_parameter="per_page", **offset) pagination_items = page_list(fs, per_page=per_page, offset=offset) pagination = Pagination(page=page, per_page=per_page, total=fs.count(), css_framework="bootstrap4") return render_template( "observation_error.html", List=pagination_items, page=page, per_page=per_page, pagination=pagination, )
def upgrade_report(): """ This API is used to pass the parameter tat helps to prepare the report and send it to recipient user. """ form = ReportForm(request.form) if request.method == "POST": Common.logger.info("upgrade_report:Post API called") job_type = "mail_report" job_category = (form.data["job_category"].strip()).split(",") job_name = (form.data["job_name"].strip()).split(",") build_number = (form.data["build_number"].strip()).split(",") bugzilla = (form.data["bugzilla"].strip()).split(",") recipient_list = form.data["recipient_list"].strip() component_version = form.data["component_version"].strip() message_body = form.data["message_details"] subject = form.data["subject_details"] bugzilla = list() if bugzilla == [""] else bugzilla common_report = Common.data_preparation_for_report( job_category, job_name, bugzilla, build_number) for data in common_report: try: job_details = extracting_build_info( job_name=common_report[data]["job_name"], build_number=int(common_report[data]["build_number"]), component_version=component_version, ) except ValueError: Common.logger.warn( f"upgrade_report:Value error happened while extracting the " f"build information for job:{common_report[data]['job_name']}" f" build number ={int(common_report[data]['build_number'])} " f"and component_version= {component_version}") return render_template("500.html", title="500"), 500 if job_details.count() == 0: Common.logger.warn(f"upgrade_report: the value for the job " f"{common_report[data]['job_name']}") return render_template("404.html", title="404"), 404 for job_detail in job_details: common_report[data]["Build_Status"] = job_detail[ "Build-Status"] common_report[data]["Build Url"] = (job_detail["Job Url"] if "Job Url" in job_detail else "unavailable") common_report[data]["Snap No"] = (job_detail["Snap-Version"] if "Snap-Version" in job_detail else "unavailable") try: pattern_type = re.search(r"\w*-\w*", job_detail["Job-Name"]).group() except AttributeError: pattern_type = job_detail["Job-Name"] if pattern_type in Common.get_config_value("test_map"): highlighted_data = job_detail["Validation"][ "Pre_Upgrade_test_Failure"] common_report[data][ "highlighted_information"] = highlighted_data else: highlighted_data = job_detail["Validation"][ "All_Commands_Execution_status"] common_report[data]["highlighted_information"] = ( highlighted_data["highlighted_content"] if "highlighted_content" in highlighted_data else "unavailable") common_report[data]["component_version"] = component_version if not message_body: common_report[ "body"] = "Please find the job execution details below" else: common_report["body"] = message_body common_report["subject"] = subject common_report["recipient"] = recipient_list Common.report_preparation(common_report) return render_template("data_processing.html", job_type=job_type) return render_template("report_mail.html", form=form)