예제 #1
0
파일: FlowCfg.py 프로젝트: islengxw/ibex
    def publish_results_summary(self):
        '''Public facing API for publishing md format results to the opentitan web server.
        '''
        results_html_file = "summary_" + self.timestamp + ".html"
        results_page_url = self.results_summary_server_page.replace(
            self.results_server_prefix, self.results_server_url_prefix)

        # Publish the results page.
        # First, write the results html file temporarily to the scratch area.
        f = open(results_html_file, 'w')
        f.write(
            md_results_to_html(self.results_title, self.css_file,
                               self.results_summary_md))
        f.close()
        rm_cmd = "/bin/rm -rf " + results_html_file + "; "

        log.info("Publishing results summary to %s", results_page_url)
        cmd = (self.results_server_cmd + " cp " + results_html_file + " " +
               self.results_summary_server_page + "; " + rm_cmd)
        log.log(VERBOSE, cmd)
        try:
            cmd_output = subprocess.run(args=cmd,
                                        shell=True,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
            log.log(VERBOSE, cmd_output.stdout.decode("utf-8"))
        except Exception as e:
            log.error("%s: Failed to publish results:\n\"%s\"", e, str(cmd))
예제 #2
0
파일: FlowCfg.py 프로젝트: zachjs/opentitan
    def write_results_html(self):
        # Prepare workspace to generate reports.
        # Keep up to 2 weeks results.
        clean_odirs(odir=self.results_path, max_odirs=14)
        mk_path(self.results_path)

        # Write results to the report area.
        if self.is_primary_cfg:
            results_html = md_results_to_html(self.results_title,
                                              self.css_file,
                                              self.results_summary_md)
            result_path = os.path.join(self.results_path, "summary.html")
        else:
            results_html = md_results_to_html(self.results_title,
                                              self.css_file, self.results_md)
            result_path = os.path.join(self.results_path, "results.html")
        with open(result_path, "w") as results_file:
            results_file.write(results_html)
        log.log(VERBOSE, "[results page]: [%s][%s], self.name, results_path")
예제 #3
0
 def gen_email_html_summary(self):
     if self.is_master_cfg:
         gen_results = self.results_summary_md
     else:
         gen_results = self.results_md
     results_html = md_results_to_html(self.results_title, self.results_server_css_path,
                                       gen_results)
     results_html_file = self.scratch_root + "/email.html"
     f = open(results_html_file, 'w')
     f.write(results_html)
     f.close()
     log.info("[results summary]: %s [%s]", "generated for email purpose", results_html_file)
예제 #4
0
 def gen_email_html_summary(self):
     if self.is_primary_cfg:
         # user can customize email content by using email_summary_md,
         # otherwise default to send out results_summary_md
         gen_results = self.email_summary_md or self.results_summary_md
     else:
         gen_results = self.email_results_md or self.results_md
     results_html = md_results_to_html(self.results_title, self.css_file, gen_results)
     results_html_file = self.scratch_root + "/email.html"
     f = open(results_html_file, 'w')
     f.write(results_html)
     f.close()
     log.info("[results summary]: %s [%s]", "generated for email purpose", results_html_file)
예제 #5
0
    def write_results_html(self, filename, text_md):
        '''Convert given text_md to html format and write it to file with given filename.
        '''
        # Prepare workspace to generate reports.
        # Keep up to 2 weeks results.
        # If path exists, skip clean_odirs and directly update the files in the existing path.
        if not (os.path.exists(self.results_path)):
            clean_odirs(odir=self.results_path, max_odirs=14)
        mk_path(self.results_path)
        mk_path(self.symlink_path)

        # Prepare results and paths.
        text_html = md_results_to_html(self.results_title, self.css_file, text_md)
        result_path = os.path.join(self.results_path, filename)
        symlink_path = os.path.join(self.symlink_path, filename)

        # Write results to the report area.
        with open(result_path, "w") as results_file:
            results_file.write(text_html)
        log.log(VERBOSE, "[results page]: [%s][%s], self.name, results_path")

        # Link the `/latest` folder with the latest reports.
        mk_symlink(result_path, symlink_path)
예제 #6
0
파일: FlowCfg.py 프로젝트: islengxw/ibex
    def _publish_results(self):
        '''Publish results to the opentitan web server.
        Results are uploaded to {results_server_path}/latest/results.
        If the 'latest' directory exists, then it is renamed to its 'timestamp' directory.
        If the list of directories in this area is > 14, then the oldest entry is removed.
        Links to the last 7 regression results are appended at the end if the results page.
        '''
        if which('gsutil') is None or which('gcloud') is None:
            log.error(
                "Google cloud SDK not installed! Cannot access the results server"
            )
            return

        # Construct the paths
        results_page_url = self.results_server_page.replace(
            self.results_server_prefix, self.results_server_url_prefix)

        # Timeformat for moving the dir
        tf = "%Y.%m.%d_%H.%M.%S"

        # Extract the timestamp of the existing self.results_server_page
        cmd = self.results_server_cmd + " ls -L " + self.results_server_page + \
            " | grep \'Creation time:\'"

        log.log(VERBOSE, cmd)
        cmd_output = subprocess.run(cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.DEVNULL)
        log.log(VERBOSE, cmd_output.stdout.decode("utf-8"))
        old_results_ts = cmd_output.stdout.decode("utf-8")
        old_results_ts = old_results_ts.replace("Creation time:", "")
        old_results_ts = old_results_ts.strip()

        # Move the 'latest' to its timestamp directory if lookup succeeded
        if cmd_output.returncode == 0:
            try:
                if old_results_ts != "":
                    ts = datetime.datetime.strptime(
                        old_results_ts, "%a, %d %b %Y %H:%M:%S %Z")
                    old_results_ts = ts.strftime(tf)
            except ValueError as e:
                log.error(
                    "%s: \'%s\' Timestamp conversion value error raised!", e)
                old_results_ts = ""

            # If the timestamp conversion failed - then create a dummy one with
            # yesterday's date.
            if old_results_ts == "":
                log.log(VERBOSE,
                        "Creating dummy timestamp with yesterday's date")
                ts = datetime.datetime.now(
                    datetime.timezone.utc) - datetime.timedelta(days=1)
                old_results_ts = ts.strftime(tf)

            old_results_dir = self.results_server_path + "/" + old_results_ts
            cmd = (self.results_server_cmd + " mv " + self.results_server_dir +
                   " " + old_results_dir)
            log.log(VERBOSE, cmd)
            cmd_output = subprocess.run(cmd,
                                        shell=True,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            log.log(VERBOSE, cmd_output.stdout.decode("utf-8"))
            if cmd_output.returncode != 0:
                log.error("Failed to mv old results page \"%s\" to \"%s\"!",
                          self.results_server_dir, old_results_dir)

        # Do an ls in the results root dir to check what directories exist.
        results_dirs = []
        cmd = self.results_server_cmd + " ls " + self.results_server_path
        log.log(VERBOSE, cmd)
        cmd_output = subprocess.run(args=cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.DEVNULL)
        log.log(VERBOSE, cmd_output.stdout.decode("utf-8"))
        if cmd_output.returncode == 0:
            # Some directories exist. Check if 'latest' is one of them
            results_dirs = cmd_output.stdout.decode("utf-8").strip()
            results_dirs = results_dirs.split("\n")
        else:
            log.log(VERBOSE, "Failed to run \"%s\"!", cmd)

        # Start pruning
        log.log(VERBOSE, "Pruning %s area to limit last 7 results",
                self.results_server_path)

        rdirs = []
        for rdir in results_dirs:
            dirname = rdir.replace(self.results_server_path, '')
            dirname = dirname.replace('/', '')
            if dirname == "latest":
                continue
            rdirs.append(dirname)
        rdirs.sort(reverse=True)

        rm_cmd = ""
        history_txt = "\n## Past Results\n"
        history_txt += "- [Latest](" + results_page_url + ")\n"
        if len(rdirs) > 0:
            for i in range(len(rdirs)):
                if i < 7:
                    rdir_url = self.results_server_path + '/' + rdirs[
                        i] + "/" + self.results_server_html
                    rdir_url = rdir_url.replace(self.results_server_prefix,
                                                self.results_server_url_prefix)
                    history_txt += "- [{}]({})\n".format(rdirs[i], rdir_url)
                elif i > 14:
                    rm_cmd += self.results_server_path + '/' + rdirs[i] + " "

        if rm_cmd != "":
            rm_cmd = self.results_server_cmd + " -m rm -r " + rm_cmd + "; "

        # Append the history to the results.
        results_md = self.results_md + history_txt

        # Publish the results page.
        # First, write the results html file temporarily to the scratch area.
        results_html_file = self.scratch_path + "/results_" + self.timestamp + ".html"
        f = open(results_html_file, 'w')
        f.write(
            md_results_to_html(self.results_title, self.css_file, results_md))
        f.close()
        rm_cmd += "/bin/rm -rf " + results_html_file + "; "

        log.info("Publishing results to %s", results_page_url)
        cmd = (self.results_server_cmd + " cp " + results_html_file + " " +
               self.results_server_page + "; " + rm_cmd)
        log.log(VERBOSE, cmd)
        try:
            cmd_output = subprocess.run(args=cmd,
                                        shell=True,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
            log.log(VERBOSE, cmd_output.stdout.decode("utf-8"))
        except Exception as e:
            log.error("%s: Failed to publish results:\n\"%s\"", e, str(cmd))