Ejemplo n.º 1
0
 def recency(self):
     return '<span class="text-muted">%s</span>' % (
         HtmlGeneration.secondsUpToString(time.time() -
                                          self.commit.data.timestamp) +
         " ago")
Ejemplo n.º 2
0
    def renderTestSuitesSummary(self, builds=False):
        commit = self.commit

        tests = self.allTests()

        if builds:
            tests = [
                t for t in tests if t.testDefinitionSummary.type == "Build"
                and self.shouldIncludeTest(t)
            ]
        else:
            tests = [
                t for t in tests if t.testDefinitionSummary.type == "Test"
                and self.shouldIncludeTest(t)
            ]

        if not tests:
            if commit.data.noTestsFound:
                return card("Commit defined no test definition file.")

            raw_text, extension = self.testManager.getRawTestFileForCommit(
                commit)
            if not raw_text:
                return card(
                    "Commit defined no tests because the test-definitions file is empty."
                )
            elif commit.data.testDefinitionsError:
                return card(
                    "<div>Commit defined no tests or builds. Maybe look at the test definitions? Error was</div><pre><code>%s</code></pre>"
                    % commit.data.testDefinitionsError)
            else:
                if self.projectFilter and self.configFilter:
                    return card(
                        "Commit defined no %s for project '%s' and configuration '%s'."
                        % ("builds" if builds else "tests", self.projectFilter,
                           self.configFilter))
                if self.projectFilter:
                    return card(
                        "Commit defined no %s for project '%s'." %
                        ("builds" if builds else "tests", self.projectFilter))
                if self.configFilter:
                    return card(
                        "Commit defined no %s for configuration %s." %
                        ("builds" if builds else "tests", self.configFilter))
                return card("Commit defined no %s." %
                            ("builds" if builds else "tests"))

        tests = sorted(tests, key=lambda test: test.testDefinitionSummary.name)

        if builds:
            grid = [[
                "BUILD", "HASH", "", "PROJECT", "CONFIGURATION", "STATUS",
                "STAGE", "RUNS", "RUNTIME", "", "DEPENDENCIES"
            ]]
        else:
            grid = [[
                "SUITE", "HASH", "", "PROJECT", "CONFIGURATION", "STATUS",
                "RUNS", "TARGET_RUNS", "TEST_CT", "FAILURE_CT", "AVG_RUNTIME",
                "", "DEPENDENCIES"
            ]]

        if self.options.get("show_disabled"):
            grid[0].append("Disabled")
            grid[0].append("Calculated Priority")

        for t in tests:
            row = []

            row.append(self.contextFor(t).renderLink(includeCommit=False))
            row.append(t.hash[:8])
            row.append(
                HtmlGeneration.Link(
                    self.contextFor(t).bootTestOrEnvUrl(),
                    "BOOT",
                    is_button=True,
                    new_tab=True,
                    button_style=self.renderer.disable_if_cant_write(
                        'btn-primary btn-xs')))

            row.append(t.testDefinitionSummary.project)
            row.append(t.testDefinitionSummary.configuration)

            row.append(
                TestSummaryRenderer.TestSummaryRenderer(
                    [t], "", ignoreIndividualTests=True).renderSummary())

            all_tests = list(
                self.testManager.database.TestRun.lookupAll(test=t))
            all_noncanceled_tests = [
                testRun for testRun in all_tests if not testRun.canceled
            ]
            all_running_tests = [
                testRun for testRun in all_noncanceled_tests
                if testRun.endTimestamp == 0.0
            ]
            finished_tests = [
                testRun for testRun in all_noncanceled_tests
                if testRun.endTimestamp > 0.0
            ]

            if builds:
                if not all_running_tests or not t.testDefinitionSummary.artifacts:
                    row.append("")
                else:
                    completed = len(all_running_tests[0].artifactsCompleted)
                    row.append(
                        "%s / %s" %
                        (completed, len(t.testDefinitionSummary.artifacts)) +
                        ([
                            " (" + x + ")"
                            for x in t.testDefinitionSummary.artifacts
                        ] + [""])[completed])

            row.append(str(t.totalRuns))

            if not builds:
                row.append(self.renderIncreaseSuiteTargetCount(t))

            if t.totalRuns:
                if not builds:
                    if t.totalRuns == 1:
                        #don't want to convert these to floats
                        row.append("%d" % t.totalTestCount)
                        row.append("%d" % t.totalFailedTestCount)
                    else:
                        row.append(str(t.totalTestCount / float(t.totalRuns)))
                        row.append(
                            str(t.totalFailedTestCount / float(t.totalRuns)))

                if finished_tests:
                    row.append(
                        HtmlGeneration.secondsUpToString(
                            sum([
                                testRun.endTimestamp - testRun.startedTimestamp
                                for testRun in finished_tests
                            ]) / len(finished_tests)))
                else:
                    row.append("")
            else:
                if not builds:
                    row.append("")
                    row.append("")

                if all_noncanceled_tests:
                    row.append(
                        HtmlGeneration.secondsUpToString(
                            sum([
                                time.time() - testRun.startedTimestamp
                                for testRun in all_noncanceled_tests
                            ]) / len(all_noncanceled_tests)) + " so far")
                else:
                    row.append("")

            runButtons = []

            for testRun in all_noncanceled_tests[:5]:
                runButtons.append(
                    self.renderer.testLogsButton(testRun._identity).render())
            if len(all_noncanceled_tests) > 5:
                runButtons.append(" and %s more" %
                                  (len(all_noncanceled_tests) - 5))

            row.append(" ".join(runButtons))
            row.append(self.testDependencySummary(t))

            if self.options.get("show_disabled"):
                row.append(
                    "Disabled" if t.testDefinitionSummary.disabled else "")
                row.append(str(t.calculatedPriority))

            grid.append(row)

        return HtmlGeneration.grid(grid)
Ejemplo n.º 3
0
    def renderPageBody(self):
        machines = self.testManager.database.Machine.lookupAll(isAlive=True)

        grid = [[
            "MachineID", "Hardware", "OS", "UP FOR", "STATUS", "LASTMSG",
            "COMMIT", "TEST", "LOGS", "CANCEL", ""
        ]]
        for m in sorted(machines, key=lambda m: -m.bootTime):
            row = []
            row.append(m.machineId)
            row.append("%s cores, %s GB" %
                       (m.hardware.cores, m.hardware.ram_gb))
            if m.os.matches.WindowsVM:
                row.append("Win(%s, %s)" % (m.os.ami, m.os.setupHash[:8]))
            elif m.os.matches.LinuxVM:
                row.append("Linux(%s, %s)" % (m.os.ami, m.os.setupHash[:8]))
            elif m.os.matches.LinuxWithDocker:
                row.append("LinuxDocker()")
            elif m.os.matches.WindowsWithDocker:
                row.append("WindowsDocker()")
            else:
                row.append("Unknown")

            row.append(
                HtmlGeneration.secondsUpToString(time.time() - m.bootTime))

            if m.firstHeartbeat < 1.0:
                row.append(
                    '<span class="octicon octicon-watch" aria-hidden="true"></span>'
                )
            elif time.time() - m.lastHeartbeat < 60:
                row.append(
                    '<span class="octicon octicon-check" aria-hidden="true"' +
                    ' data-toggle="tooltip" data-placement="right" title="Heartbeat %s seconds ago" '
                    % (int(time.time() - m.lastHeartbeat)) + '></span>')
            else:
                row.append(
                    '<span class="octicon octicon-issue-opened" aria-hidden="true"'
                    +
                    ' data-toggle="tooltip" data-placement="right" title="Heartbeat %s seconds ago" '
                    % (int(time.time() - m.lastHeartbeat)) + '></span>')

            row.append(m.lastHeartbeatMsg)

            tests = self.testManager.database.TestRun.lookupAll(
                runningOnMachine=m)
            deployments = self.testManager.database.Deployment.lookupAll(
                runningOnMachine=m)

            if len(tests) + len(deployments) > 1:
                row.append("ERROR: multiple test runs/deployments")
            elif tests:
                commit = self.testManager.oldestCommitForTest(tests[0].test)
                try:
                    row.append(self.contextFor(commit).renderLink())
                except:
                    row.append("")

                row.append(
                    self.renderer.testRunLink(
                        tests[0], tests[0].test.testDefinitionSummary.name))
                row.append(self.renderer.testLogsButton(tests[0]._identity))
                row.append(
                    self.renderer.cancelTestRunButton(tests[0]._identity))

            elif deployments:
                commit = self.testManager.oldestCommitForTest(
                    deployments[0].test)
                try:
                    row.append(self.contextFor(commit).renderLink())
                except:
                    row.append("")

                d = deployments[0]
                row.append("DEPLOYMENT")

            grid.append(row)

        return HtmlGeneration.grid(grid)