]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webapi: fix t=check for DIR2-LIT (i.e. empty immutable directories)
authorBrian Warner <warner@lothar.com>
Thu, 26 Nov 2009 23:27:31 +0000 (15:27 -0800)
committerBrian Warner <warner@lothar.com>
Thu, 26 Nov 2009 23:27:31 +0000 (15:27 -0800)
src/allmydata/test/test_web.py
src/allmydata/web/directory.py
src/allmydata/web/filenode.py

index c96a81960db865b34561acc3b72b31a8df9400ed..9d0aad0e4b9522a2c65f3993260c3cc8e7c1b80b 100644 (file)
@@ -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)
index 2c8a609d83f06b55d1f26c7d094cead07fbacfec..a25f8cc43ec1ab64365e3381a78221a2d99dd6c8 100644 (file)
@@ -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):
index 9b2c4535107e794a82f16a16c9f1ae1ac8cf2749..daf3d43ff592421ed10edba03e939d33f71f297d 100644 (file)
@@ -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):