]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
checker: re-enable checker web results (although they just say 'Healthy' right now)
authorBrian Warner <warner@allmydata.com>
Wed, 16 Jul 2008 22:42:56 +0000 (15:42 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 16 Jul 2008 22:42:56 +0000 (15:42 -0700)
docs/webapi.txt
src/allmydata/immutable/checker.py
src/allmydata/interfaces.py
src/allmydata/mutable/checker.py
src/allmydata/test/common.py
src/allmydata/test/test_web.py
src/allmydata/web/checker-results.xhtml [new file with mode: 0644]
src/allmydata/web/checker_results.py [new file with mode: 0644]
src/allmydata/web/directory.py
src/allmydata/web/filenode.py

index 281452bc89e530c430cf04eec861b88f34bd6370..029460d655cd25dea117511d6c9a94ef4190cad8 100644 (file)
@@ -646,8 +646,17 @@ POST $URL?t=check
 
   This triggers the FileChecker to determine the current "health" of the
   given file or directory, by counting how many shares are available. The
-  results will be displayed on the directory page containing this file.
+  page that is returned will display the results. This can be used as a "show
+  me detailed information about this file" page.
 
+  If a when_done=url argument is provided, the return value will be a redirect
+  to that URL instead of the checker results.
+
+  If a return_to=url argument is provided, the returned page will include a
+  link to the given URL entitled "Return to the parent directory".
+
+  If a verify=true argument is provided, the node will perform a more
+  intensive check, downloading and verifying every single bit of every share.
 
 GET $DIRURL?t=manifest
 
index c49aeb289d383310dd7c4a2ebf99314aebde9802..c326921721537764db09323312e287e930835cde 100644 (file)
@@ -28,19 +28,20 @@ class Results:
     def is_healthy(self):
         return self.healthy
 
-    def html_summary(self):
-        if self.healthy:
-            return "<span>healthy</span>"
-        return "<span>NOT HEALTHY</span>"
+    def get_storage_index_string(self):
+        return self.storage_index_s
+
+    def get_mutability_string(self):
+        if self.storage_index:
+            return "immutable"
+        return "literal"
 
-    def html(self):
-        s = "<div>\n"
-        s += "<h1>Checker Results for Immutable SI=%s</h1>\n" % self.storage_index_s
+    def to_string(self):
+        s = ""
         if self.healthy:
-            s += "<h2>Healthy!</h2>\n"
+            s += "Healthy!\n"
         else:
-            s += "<h2>Not Healthy!</h2>\n"
-        s += "</div>\n"
+            s += "Not Healthy!\n"
         return s
 
 
index b31d59ce5e393dca9953b4e1c5d83e340b199e7c..c03d4d188d88d8203ec32cfcfd11b99fb2e603e2 100644 (file)
@@ -1484,16 +1484,15 @@ class ICheckerResults(Interface):
         """Return a bool, True if the file is fully healthy, False if it is
         damaged in any way."""
 
-    def html_summary():
-        """Return a short string, with a single <span> element, that
-        describes summarized results of the check. This will be displayed on
-        the web-interface directory page, in a narrow column, showing stored
-        results for all files at the same time."""
-
-    def html():
-        """Return a string, with a single <div> element that describes the
-        detailed results of the check/verify operation. This string will be
-        displayed on a page all by itself."""
+    def get_storage_index_string():
+        """Return a string with the abbreviated storage index."""
+    def get_mutability_string():
+        """Return a string with 'mutable' or 'immutable'."""
+
+    def to_string():
+        """Return a string that describes the detailed results of the
+        check/verify operation. This string will be displayed on a page all
+        by itself."""
 
     # The old checker results (for only immutable files) were described
     # with this:
index 4d6698ab94815df0904a839d47361acdc82937e3..391a29be6c60003726dd8d26184177ccd7769718 100644 (file)
@@ -158,18 +158,17 @@ class Results:
     def is_healthy(self):
         return self.healthy
 
-    def html_summary(self):
-        if self.healthy:
-            return "<span>healthy</span>"
-        return "<span>NOT HEALTHY</span>"
+    def get_storage_index_string(self):
+        return self.storage_index_s
+
+    def get_mutability_string(self):
+        return "mutable"
 
-    def html(self):
-        s = "<div>\n"
-        s += "<h1>Checker Results for Mutable SI=%s</h1>\n" % self.storage_index_s
+    def to_string(self):
+        s = ""
         if self.healthy:
-            s += "<h2>Healthy!</h2>\n"
+            s += "Healthy!\n"
         else:
-            s += "<h2>Not Healthy!</h2>\n"
-        s += "</div>\n"
+            s += "Not Healthy!\n"
         return s
 
index 09698883bc32462f9d0d1200d062a0786f755cce..a867c9276a14a84230ce60a33592f9e878c8a62b 100644 (file)
@@ -27,8 +27,11 @@ class FakeCHKFileNode:
         return self.my_uri
     def get_verifier(self):
         return IURI(self.my_uri).get_verifier()
-    def check(self):
-        return defer.succeed(None)
+    def check(self, verify=False, repair=False):
+        r = checker.Results(None)
+        r.healthy = True
+        r.problems = []
+        return defer.succeed(r)
     def is_mutable(self):
         return False
     def is_readonly(self):
index 6ef18678df7c9f6d390ec35e751795204f85ca6a..10dcddfb78df7510297331c7cc86f004e63b2bd5 100644 (file)
@@ -1397,12 +1397,53 @@ class Web(WebMixin, unittest.TestCase):
         return d
 
     def test_POST_FILEURL_check(self):
-        d = self.POST(self.public_url + "/foo/bar.txt", t="check")
+        bar_url = self.public_url + "/foo/bar.txt"
+        d = self.POST(bar_url, t="check")
         def _check(res):
-            # this currently just returns "None". You'd only really use it
-            # with a when_done= redirect.
-            self.failUnlessEqual(res, "None")
+            self.failUnless("Healthy!" in res)
         d.addCallback(_check)
+        redir_url = "http://allmydata.org/TARGET"
+        def _check2(statuscode, target):
+            self.failUnlessEqual(statuscode, str(http.FOUND))
+            self.failUnlessEqual(target, redir_url)
+        d.addCallback(lambda res:
+                      self.shouldRedirect2("test_POST_FILEURL_check",
+                                           _check2,
+                                           self.POST, bar_url,
+                                           t="check",
+                                           when_done=redir_url))
+        d.addCallback(lambda res:
+                      self.POST(bar_url, t="check", return_to=redir_url))
+        def _check3(res):
+            self.failUnless("Healthy!" in res)
+            self.failUnless("Return to parent directory" in res)
+            self.failUnless(redir_url in res)
+        d.addCallback(_check3)
+        return d
+
+    def test_POST_DIRURL_check(self):
+        foo_url = self.public_url + "/foo/"
+        d = self.POST(foo_url, t="check")
+        def _check(res):
+            self.failUnless("Healthy!" in res)
+        d.addCallback(_check)
+        redir_url = "http://allmydata.org/TARGET"
+        def _check2(statuscode, target):
+            self.failUnlessEqual(statuscode, str(http.FOUND))
+            self.failUnlessEqual(target, redir_url)
+        d.addCallback(lambda res:
+                      self.shouldRedirect2("test_POST_DIRURL_check",
+                                           _check2,
+                                           self.POST, foo_url,
+                                           t="check",
+                                           when_done=redir_url))
+        d.addCallback(lambda res:
+                      self.POST(foo_url, t="check", return_to=redir_url))
+        def _check3(res):
+            self.failUnless("Healthy!" in res)
+            self.failUnless("Return to parent directory" in res)
+            self.failUnless(redir_url in res)
+        d.addCallback(_check3)
         return d
 
     def test_POST_FILEURL_bad_t(self):
diff --git a/src/allmydata/web/checker-results.xhtml b/src/allmydata/web/checker-results.xhtml
new file mode 100644 (file)
index 0000000..01fa8fc
--- /dev/null
@@ -0,0 +1,18 @@
+<html xmlns:n="http://nevow.com/ns/nevow/0.1">
+  <head>
+    <title>AllMyData - Tahoe - Check Results</title>
+    <!-- <link href="http://www.allmydata.com/common/css/styles.css"
+          rel="stylesheet" type="text/css"/> -->
+    <link href="/webform_css" rel="stylesheet" type="text/css"/>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  </head>
+  <body>
+
+<h1>File Check Results for SI=<span n:render="storage_index" /> (<span n:render="mutability" />)</h1>
+
+<pre n:render="results" />
+
+<div n:render="return" />
+
+  </body>
+</html>
diff --git a/src/allmydata/web/checker_results.py b/src/allmydata/web/checker_results.py
new file mode 100644 (file)
index 0000000..351a7c0
--- /dev/null
@@ -0,0 +1,25 @@
+
+from nevow import rend, inevow, tags as T
+from allmydata.web.common import getxmlfile, get_arg
+
+class CheckerResults(rend.Page):
+    docFactory = getxmlfile("checker-results.xhtml")
+
+    def __init__(self, results):
+        self.r = results
+
+    def render_storage_index(self, ctx, data):
+        return self.r.get_storage_index_string()
+
+    def render_mutability(self, ctx, data):
+        return self.r.get_mutability_string()
+
+    def render_results(self, ctx, data):
+        return ctx.tag[self.r.to_string()]
+
+    def render_return(self, ctx, data):
+        req = inevow.IRequest(ctx)
+        return_to = get_arg(req, "return_to", None)
+        if return_to:
+            return T.div[T.a(href=return_to)["Return to parent directory"]]
+        return ""
index 1b6126297f81b07fae84c3fef833e7b912e1aaef..4c6d0351fab85b56d4bdcc0c8d4ad633bbd255ac 100644 (file)
@@ -11,7 +11,7 @@ from nevow.inevow import IRequest
 
 from foolscap.eventual import fireEventually
 
-from allmydata.util import log, base32
+from allmydata.util import base32
 from allmydata.uri import from_string_verifier, from_string_dirnode, \
      CHKFileVerifierURI
 from allmydata.interfaces import IDirectoryNode, IFileNode, IMutableFileNode, \
@@ -21,6 +21,7 @@ from allmydata.web.common import text_plain, WebError, IClient, \
      getxmlfile, RenderMixin
 from allmydata.web.filenode import ReplaceMeMixin, \
      FileNodeHandler, PlaceHolderNodeHandler
+from allmydata.web.checker_results import CheckerResults
 
 class BlockingFileError(Exception):
     # TODO: catch and transform
@@ -330,12 +331,7 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
     def _POST_check(self, req):
         # check this directory
         d = self.node.check()
-        def _done(res):
-            log.msg("checked %s, results %s" % (self.node, res),
-                    facility="tahoe.webish", level=log.NOISY)
-            return str(res)
-        d.addCallback(_done)
-        # TODO: results
+        d.addCallback(lambda res: CheckerResults(res))
         return d
 
     def _POST_set_children(self, req):
@@ -458,7 +454,7 @@ class DirectoryAsHTML(rend.Page):
             check_done_url = "../uri/%s/" % urllib.quote(self.node.get_uri())
         check = T.form(action=check_url, method="post")[
             T.input(type='hidden', name='t', value='check'),
-            T.input(type='hidden', name='when_done', value=check_done_url),
+            T.input(type='hidden', name='return_to', value=check_done_url),
             T.input(type='submit', value='check', name="check"),
             ]
         ctx.fillSlots("overwrite",
index 9a9a28ef928e0546b286b80db10666d3d9970a33..21ede7e2a47f25e7f1f14650c89e0476c3cc83c8 100644 (file)
@@ -15,6 +15,7 @@ from allmydata.util import log
 
 from allmydata.web.common import text_plain, WebError, IClient, RenderMixin, \
      boolean_of_arg, get_arg, should_create_intermediate_directories
+from allmydata.web.checker_results import CheckerResults
 
 class ReplaceMeMixin:
 
@@ -244,12 +245,7 @@ class FileNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
 
     def _POST_check(self, req):
         d = self.node.check()
-        def _done(res):
-            log.msg("checked %s, results %s" % (self.node, res),
-                    facility="tahoe.webish", level=log.NOISY)
-            return str(res)
-        d.addCallback(_done)
-        # TODO: results
+        d.addCallback(lambda res: CheckerResults(res))
         return d
 
     def render_DELETE(self, ctx):