Never display builds from unknown hosts
[build-farm.git] / buildfarm / web / __init__.py
index aa60fc46f84d41c73bf80f3729df77465c9fc9e5..c4972dc57a73faf072f20eb18ca4f226a58dfc08 100755 (executable)
@@ -167,6 +167,8 @@ def subunit_to_buildfarm_result(subunit_result):
         return "failed"
     elif subunit_result == "xfail":
         return "xfailed"
+    elif subunit_result == "uxsuccess":
+        return "uxpassed"
     else:
         return "unknown"
 
@@ -239,7 +241,7 @@ class LogPrettyPrinter(object):
         log = re.sub("""
               ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
               (.*?)
-              (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
+              (success|xfail|failure|skip|uxsuccess): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
            """, self._format_test, log)
 
         return "<pre>%s</pre>" % log
@@ -313,9 +315,9 @@ def make_collapsible_html(type, title, output, id, status=""):
     :param title: the title to be displayed
     """
     if status.lower() in ("", "failed"):
-        icon = 'icon_hide_16.png'
+        icon = '/icon_hide_16.png'
     else:
-        icon = 'icon_unhide_16.png'
+        icon = '/icon_unhide_16.png'
 
     # trim leading and trailing whitespace
     output = output.strip()
@@ -371,6 +373,11 @@ class BuildFarmPage(object):
             return "<span class='old'>%s</span>" % util.dhm_time(age)
         return util.dhm_time(age)
 
+    def tree_link(self, myself, treename):
+        try:
+            return tree_link(myself, self.buildfarm.trees[treename])
+        except KeyError:
+            return treename
 
     def render(self, output_type):
         raise NotImplementedError(self.render)
@@ -446,7 +453,7 @@ class ViewBuildPage(BuildFarmPage):
                 (myself, build.host, build.tree, build.compiler, build.host, self.buildfarm.hostdb[build.host].platform.encode("utf-8"))
         if uname is not None:
             yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
-        yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % tree_link(myself, self.buildfarm.trees[build.tree])
+        yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, build.tree)
         yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, build.tree)
         yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
         yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_link(myself, build)
@@ -466,7 +473,15 @@ class ViewBuildPage(BuildFarmPage):
 
         yield "<div id='log'>"
 
-        yield "<p><a href='%s/+subunit'>Subunit output</a></p>" % build_uri(myself, build)
+        yield "<p><a href='%s/+subunit'>Subunit output</a>" % build_uri(myself, build)
+        try:
+            previous_build = self.buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, build.revision)
+        except NoSuchBuildError:
+            pass
+        else:
+            yield ", <a href='%s/+subunit-diff/%s'>diff against previous</a>" % (
+                build_uri(myself, build), previous_build.log_checksum())
+        yield "</p>"
         yield "<p><a href='%s/+stdout'>Standard output (as plain text)</a>, " % build_uri(myself, build)
         yield "<a href='%s/+stderr'>Standard error (as plain text)</a>" % build_uri(myself, build)
         yield "</p>"
@@ -518,6 +533,10 @@ class ViewRecentBuildsPage(BuildFarmPage):
         all_builds = []
 
         def build_platform(build):
+            host = self.buildfarm.hostdb[build.host]
+            return host.platform.encode("utf-8")
+
+        def build_platform_safe(build):
             try:
                 host = self.buildfarm.hostdb[build.host]
             except hostdb.NoSuchHost:
@@ -529,7 +548,7 @@ class ViewRecentBuildsPage(BuildFarmPage):
             "revision": lambda a, b: cmp(a.revision, b.revision),
             "age": lambda a, b: cmp(a.age, b.age),
             "host": lambda a, b: cmp(a.host, b.host),
-            "platform": lambda a, b: cmp(build_platform(a), build_platform(b)),
+            "platform": lambda a, b: cmp(build_platform_safe(a), build_platform_safe(b)),
             "compiler": lambda a, b: cmp(a.compiler, b.compiler),
             "status": lambda a, b: cmp(a.status(), b.status()),
             }
@@ -564,15 +583,19 @@ class ViewRecentBuildsPage(BuildFarmPage):
         yield "<tbody>"
 
         for build in all_builds:
-            yield "<tr>"
-            yield "<td>%s</td>" % util.dhm_time(build.age)
-            yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
-            yield "<td>%s</td>" % build.tree
-            yield "<td>%s</td>" % build_platform(build)
-            yield "<td>%s</td>" % host_link(myself, build.host)
-            yield "<td>%s</td>" % build.compiler
-            yield "<td>%s</td>" % build_link(myself, build)
-            yield "</tr>"
+            try:
+                build_platform_name = build_platform(build)
+                yield "<tr>"
+                yield "<td>%s</td>" % util.dhm_time(build.age)
+                yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
+                yield "<td>%s</td>" % build.tree
+                yield "<td>%s</td>" % build_platform_name
+                yield "<td>%s</td>" % host_link(myself, build.host)
+                yield "<td>%s</td>" % build.compiler
+                yield "<td>%s</td>" % build_link(myself, build)
+                yield "</tr>"
+            except hostdb.NoSuchHost:
+                pass
         yield "</tbody></table>"
         yield "</div>"
 
@@ -590,7 +613,7 @@ class ViewHostPage(BuildFarmPage):
     def _render_build_html(self, myself, build):
         warnings = build.err_count()
         yield "<tr>"
-        yield "<td><span class='tree'>" + tree_link(myself, self.buildfarm.trees[build.tree]) +"</span>/" + build.compiler + "</td>"
+        yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
         yield "<td>" + revision_link(myself, build.revision, build.tree) + "</td>"
         yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
         yield "<td><div class='status'>%s</div></td>" % build_link(myself, build)
@@ -604,7 +627,6 @@ class ViewHostPage(BuildFarmPage):
             try:
                 host = self.buildfarm.hostdb[hostname]
             except hostdb.NoSuchHost:
-                deadhosts.append(hostname)
                 continue
             builds = list(self.buildfarm.get_host_builds(hostname))
             if len(builds) > 0:
@@ -660,7 +682,7 @@ class ViewHostPage(BuildFarmPage):
             try:
                 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
             except hostdb.NoSuchHost:
-                platform = "UNKNOWN"
+                continue
             yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
                     (host, platform, util.dhm_time(age))
 
@@ -717,7 +739,7 @@ class ViewSummaryPage(BuildFarmPage):
 
         for tree in sorted(self.buildfarm.trees.keys()):
             yield "<tr>"
-            yield "<td>%s</td>" % tree_link(myself, self.buildfarm.trees[tree])
+            yield "<td>%s</td>" % self.tree_link(myself, tree)
             yield "<td>%s</td>" % host_count[tree]
             yield "<td>%s</td>" % broken_count[tree]
             if panic_count[tree]:
@@ -725,6 +747,7 @@ class ViewSummaryPage(BuildFarmPage):
             else:
                     yield "<td>"
             yield "%d</td>" % panic_count[tree]
+
             try:
                 lcov_status = self.buildfarm.lcov_status(tree)
             except NoSuchBuildError:
@@ -735,6 +758,17 @@ class ViewSummaryPage(BuildFarmPage):
                         self.buildfarm.LCOVHOST, tree, lcov_status)
                 else:
                     yield "<td></td>"
+
+            try:
+                unused_fns = self.buildfarm.unused_fns(tree)
+            except NoSuchBuildError:
+                yield "<td></td>"
+            else:
+                if unused_fns is not None:
+                    yield "<td><a href=\"/lcov/data/%s/%s/%s\">Unused Functions</a></td>" % (
+                        self.buildfarm.LCOVHOST, tree, unused_fns)
+                else:
+                    yield "<td></td>"
             yield "</tr>"
 
         yield "</tbody></table>"
@@ -807,7 +841,11 @@ class HistoryPage(BuildFarmPage):
 class DiffPage(HistoryPage):
 
     def render(self, myself, tree, revision):
-        t = self.buildfarm.trees[tree]
+        try:
+            t = self.buildfarm.trees[tree]
+        except KeyError:
+            yield "Unknown tree %s" % tree
+            return
         branch = t.get_branch()
         (entry, diff) = branch.diff(revision)
         # get information about the current diff
@@ -889,7 +927,7 @@ class BuildFarmApp(object):
         yield "    <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
         yield "    <meta name='robots' contents='noindex'/>"
         yield "    <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
-        yield "    <link rel='stylesheet' href='http://master.samba.org/samba/style/common.css' type='text/css' media='all'/>"
+        yield "    <link rel='stylesheet' href='http://www.samba.org/samba/style/common.css' type='text/css' media='all'/>"
         yield "    <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
         yield "  </head>"
         yield "<body>"
@@ -970,14 +1008,20 @@ class BuildFarmApp(object):
         else:
             fn = wsgiref.util.shift_path_info(environ)
             if fn == "tree":
-                start_response('200 OK', [
-                    ('Content-type', 'text/html; charset=utf-8')])
                 tree = wsgiref.util.shift_path_info(environ)
                 subfn = wsgiref.util.shift_path_info(environ)
                 if subfn in ("", None, "+recent"):
+                    start_response('200 OK', [
+                        ('Content-type', 'text/html; charset=utf-8')])
                     page = ViewRecentBuildsPage(self.buildfarm)
                     yield "".join(self.html_page(form, page.render(myself, tree, get_param(form, 'sortby') or 'age')))
+                elif subfn == "+recent-ids":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/plain; charset=utf-8')])
+                    yield "".join([x.log_checksum()+"\n" for x in self.buildfarm.get_tree_builds(tree) if x.has_log()])
                 else:
+                    start_response('200 OK', [
+                        ('Content-type', 'text/html; charset=utf-8')])
                     yield "Unknown subfn %s" % subfn
             elif fn == "host":
                 start_response('200 OK', [
@@ -1011,6 +1055,16 @@ class BuildFarmApp(object):
                         ('Content-type', 'text/plain; charset=utf-8'),
                         ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.err"' % (build.tree, build.host, build.compiler, build.revision))])
                     yield build.read_err().read()
+                elif subfn == "+subunit-diff":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/plain; charset=utf-8')])
+                    subunit_this = build.read_subunit().readlines()
+                    other_build_checksum = wsgiref.util.shift_path_info(environ)
+                    other_build = self.buildfarm.builds.get_by_checksum(other_build_checksum)
+                    subunit_other = other_build.read_subunit().readlines()
+                    import difflib
+                    yield "".join(difflib.unified_diff(subunit_other, subunit_this))
+
                 elif subfn in ("", None):
                     start_response('200 OK', [
                         ('Content-type', 'text/html; charset=utf-8')])