From: Brian Warner Date: Thu, 26 Nov 2009 23:27:31 +0000 (-0800) Subject: webapi: fix t=check for DIR2-LIT (i.e. empty immutable directories) X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/file/URI:LIT:krugkidfnzsc4/index.php?a=commitdiff_plain;h=366a309795c3fedd97b50a7ce57919834eb25cfa;p=tahoe-lafs%2Ftahoe-lafs.git webapi: fix t=check for DIR2-LIT (i.e. empty immutable directories) --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index c96a8196..9d0aad0e 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -2782,6 +2782,8 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ign: c0.upload(upload.Data("literal", convergence=""))) d.addCallback(_stash_uri, "small") + d.addCallback(lambda ign: c0.create_immutable_dirnode({})) + d.addCallback(_stash_mutable_uri, "smalldir") def _compute_fileurls(ignored): self.fileurls = {} @@ -2844,6 +2846,18 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin): self.failUnless(r["results"]["healthy"]) d.addCallback(_got_json_small) + d.addCallback(self.CHECK, "smalldir", "t=check") + def _got_html_smalldir(res): + self.failUnless("Literal files are always healthy" in res, res) + self.failIf("Not Healthy" in res, res) + d.addCallback(_got_html_smalldir) + d.addCallback(self.CHECK, "smalldir", "t=check&output=json") + def _got_json_smalldir(res): + r = simplejson.loads(res) + self.failUnlessEqual(r["storage-index"], "") + self.failUnless(r["results"]["healthy"]) + d.addCallback(_got_json_smalldir) + d.addCallback(self.CHECK, "sick", "t=check") def _got_html_sick(res): self.failUnless("Not Healthy" in res, res) diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 2c8a609d..a25f8cc4 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -26,7 +26,8 @@ from allmydata.web.common import text_plain, WebError, \ from allmydata.web.filenode import ReplaceMeMixin, \ FileNodeHandler, PlaceHolderNodeHandler from allmydata.web.check_results import CheckResults, \ - CheckAndRepairResults, DeepCheckResults, DeepCheckAndRepairResults + CheckAndRepairResults, DeepCheckResults, DeepCheckAndRepairResults, \ + LiteralCheckResults from allmydata.web.info import MoreInfo from allmydata.web.operations import ReloadMixin from allmydata.web.check_results import json_check_results, \ @@ -397,6 +398,11 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin): d.addCallback(lambda res: "thing renamed") return d + def _maybe_literal(self, res, Results_Class): + if res: + return Results_Class(self.client, res) + return LiteralCheckResults(self.client) + def _POST_check(self, req): # check this directory verify = boolean_of_arg(get_arg(req, "verify", "false")) @@ -404,10 +410,10 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin): add_lease = boolean_of_arg(get_arg(req, "add-lease", "false")) if repair: d = self.node.check_and_repair(Monitor(), verify, add_lease) - d.addCallback(lambda res: CheckAndRepairResults(self.client, res)) + d.addCallback(self._maybe_literal, CheckAndRepairResults) else: d = self.node.check(Monitor(), verify, add_lease) - d.addCallback(lambda res: CheckResults(self.client, res)) + d.addCallback(self._maybe_literal, CheckResults) return d def _start_operation(self, monitor, renderer, ctx): diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index 9b2c4535..daf3d43f 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -9,7 +9,6 @@ from nevow.inevow import IRequest from allmydata.interfaces import ExistingChildError, CannotPackUnknownNodeError from allmydata.monitor import Monitor from allmydata.immutable.upload import FileHandle -from allmydata.immutable.filenode import LiteralFileNode from allmydata.unknown import UnknownNode from allmydata.util import log, base32 @@ -260,18 +259,21 @@ class FileNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin): d.addCallback(lambda res: url.URL.fromString(when_done)) return d + def _maybe_literal(self, res, Results_Class): + if res: + return Results_Class(self.client, res) + return LiteralCheckResults(self.client) + def _POST_check(self, req): verify = boolean_of_arg(get_arg(req, "verify", "false")) repair = boolean_of_arg(get_arg(req, "repair", "false")) add_lease = boolean_of_arg(get_arg(req, "add-lease", "false")) - if isinstance(self.node, LiteralFileNode): - return defer.succeed(LiteralCheckResults(self.client)) if repair: d = self.node.check_and_repair(Monitor(), verify, add_lease) - d.addCallback(lambda res: CheckAndRepairResults(self.client, res)) + d.addCallback(self._maybe_literal, CheckAndRepairResults) else: d = self.node.check(Monitor(), verify, add_lease) - d.addCallback(lambda res: CheckResults(self.client, res)) + d.addCallback(self._maybe_literal, CheckResults) return d def render_DELETE(self, ctx):