From: Brian Warner Date: Wed, 16 Jul 2008 22:42:56 +0000 (-0700) Subject: checker: re-enable checker web results (although they just say 'Healthy' right now) X-Git-Url: https://git.rkrishnan.org/pf/content/%22news.html/frontends/webapi.txt?a=commitdiff_plain;h=3e9322bcb6c620789b9347b2bbd65e3c7300de86;p=tahoe-lafs%2Ftahoe-lafs.git checker: re-enable checker web results (although they just say 'Healthy' right now) --- diff --git a/docs/webapi.txt b/docs/webapi.txt index 281452bc..029460d6 100644 --- a/docs/webapi.txt +++ b/docs/webapi.txt @@ -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 diff --git a/src/allmydata/immutable/checker.py b/src/allmydata/immutable/checker.py index c49aeb28..c3269217 100644 --- a/src/allmydata/immutable/checker.py +++ b/src/allmydata/immutable/checker.py @@ -28,19 +28,20 @@ class Results: def is_healthy(self): return self.healthy - def html_summary(self): - if self.healthy: - return "healthy" - return "NOT HEALTHY" + 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 = "
\n" - s += "

Checker Results for Immutable SI=%s

\n" % self.storage_index_s + def to_string(self): + s = "" if self.healthy: - s += "

Healthy!

\n" + s += "Healthy!\n" else: - s += "

Not Healthy!

\n" - s += "
\n" + s += "Not Healthy!\n" return s diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index b31d59ce..c03d4d18 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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 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
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: diff --git a/src/allmydata/mutable/checker.py b/src/allmydata/mutable/checker.py index 4d6698ab..391a29be 100644 --- a/src/allmydata/mutable/checker.py +++ b/src/allmydata/mutable/checker.py @@ -158,18 +158,17 @@ class Results: def is_healthy(self): return self.healthy - def html_summary(self): - if self.healthy: - return "healthy" - return "NOT HEALTHY" + def get_storage_index_string(self): + return self.storage_index_s + + def get_mutability_string(self): + return "mutable" - def html(self): - s = "
\n" - s += "

Checker Results for Mutable SI=%s

\n" % self.storage_index_s + def to_string(self): + s = "" if self.healthy: - s += "

Healthy!

\n" + s += "Healthy!\n" else: - s += "

Not Healthy!

\n" - s += "
\n" + s += "Not Healthy!\n" return s diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 09698883..a867c927 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -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): diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 6ef18678..10dcddfb 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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 index 00000000..01fa8fc8 --- /dev/null +++ b/src/allmydata/web/checker-results.xhtml @@ -0,0 +1,18 @@ + + + AllMyData - Tahoe - Check Results + + + + + + +

File Check Results for SI= ()

+ +
+
+
+ + + diff --git a/src/allmydata/web/checker_results.py b/src/allmydata/web/checker_results.py new file mode 100644 index 00000000..351a7c00 --- /dev/null +++ b/src/allmydata/web/checker_results.py @@ -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 "" diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 1b612629..4c6d0351 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -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", diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index 9a9a28ef..21ede7e2 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -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):