Changeset 7f8bbcc in trunk


Ignore:
Timestamp:
2011-11-20T23:24:26Z (14 years ago)
Author:
david-sarah <david-sarah@…>
Branches:
master
Children:
d887782
Parents:
7989fe2
Message:

Use a private/drop_upload_dircap file instead of the [drop_upload]upload.dircap option in tahoe.cfg. Fail if the upload.dircap option is used, or options are missing. Also updates tests and docs. fixes #1593

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified docs/frontends/drop-upload.rst

    r7989fe2 r7f8bbcc  
    2121should not keep important data in the upload directory, and should not rely
    2222on all changes to files in the local directory to result in successful uploads.
    23 There might be incompatible changes to how the feature is configured in
    24 future versions. There is even the possibility that it may be abandoned, for
     23There might be (and have been) incompatible changes to how the feature is
     24configured. There is even the possibility that it may be abandoned, for
    2525example if unsolveable reliability issues are found.
    2626
     
    4343``enabled = (boolean, optional)``
    4444
    45     If this is ``True``, drop-upload will be enabled (provided that the
    46     ``upload.dircap`` and ``local.directory`` fields are also set). The
    47     default value is ``False``.
    48 
    49 ``upload.dircap = (directory writecap)``
    50 
    51     This is a writecap pointing to an existing mutable directory to be used
    52     as the target of uploads. It will start with ``URI:DIR2:``, and cannot
    53     include an alias or path.
     45    If this is ``True``, drop-upload will be enabled. The default value is
     46    ``False``.
    5447
    5548``local.directory = (UTF-8 path)``
     
    5952    in UTF-8 regardless of the system's filesystem encoding. Relative paths
    6053    will be interpreted starting from the node's base directory.
     54
     55In addition, the file  ``private/drop_upload_dircap`` must contain a
     56writecap pointing to an existing mutable directory to be used as the target
     57of uploads. It will start with ``URI:DIR2:``, and cannot include an alias
     58or path.
    6159
    6260After setting the above fields and starting or restarting the gateway,
  • TabularUnified src/allmydata/client.py

    r7989fe2 r7f8bbcc  
    2727from allmydata.nodemaker import NodeMaker
    2828from allmydata.blacklist import Blacklist
     29from allmydata.node import OldConfigOptionError
    2930
    3031
     
    440441    def init_drop_uploader(self):
    441442        if self.get_config("drop_upload", "enabled", False, boolean=True):
    442             upload_dircap = self.get_config("drop_upload", "upload.dircap", None)
    443             local_dir_utf8 = self.get_config("drop_upload", "local.directory", None)
    444 
    445             if upload_dircap and local_dir_utf8:
    446                 try:
    447                     from allmydata.frontends import drop_upload
    448                     s = drop_upload.DropUploader(self, upload_dircap, local_dir_utf8)
    449                     s.setServiceParent(self)
    450                     s.startService()
    451                 except Exception, e:
    452                     self.log("couldn't start drop-uploader: %r", args=(e,))
    453             else:
    454                 self.log("couldn't start drop-uploader: upload.dircap or local.directory not specified")
     443            if self.get_config("drop_upload", "upload.dircap", None):
     444                raise OldConfigOptionError("The [drop_upload]upload.dircap option is no longer supported; please "
     445                                           "put the cap in a 'private/drop_upload_dircap' file, and delete this option.")
     446
     447            upload_dircap = self.get_or_create_private_config("drop_upload_dircap")
     448            local_dir_utf8 = self.get_config("drop_upload", "local.directory")
     449
     450            try:
     451                from allmydata.frontends import drop_upload
     452                s = drop_upload.DropUploader(self, upload_dircap, local_dir_utf8)
     453                s.setServiceParent(self)
     454                s.startService()
     455            except Exception, e:
     456                self.log("couldn't start drop-uploader: %r", args=(e,))
    455457
    456458    def _check_hotline(self, hotline_file):
  • TabularUnified src/allmydata/node.py

    r7989fe2 r7f8bbcc  
    5252                "See docs/historical/configuration.rst."
    5353                % "\n".join([quote_output(fname) for fname in self.args[0]]))
     54
     55class OldConfigOptionError(Exception):
     56    pass
    5457
    5558
     
    202205        open(privname, "w").write(value.strip())
    203206
    204     def get_or_create_private_config(self, name, default):
     207    def get_or_create_private_config(self, name, default=_None):
    205208        """Try to get the (string) contents of a private config file (which
    206209        is a config file that resides within the subdirectory named
     
    208211        stripped from the data.
    209212
    210         If the file does not exist, try to create it using default, and
    211         then return the value that was written. If 'default' is a string,
    212         use it as a default value. If not, treat it as a 0-argument callable
    213         which is expected to return a string.
     213        If the file does not exist, and default is not given, report an error.
     214        If the file does not exist and a default is specified, try to create
     215        it using that default, and then return the value that was written.
     216        If 'default' is a string, use it as a default value. If not, treat it
     217        as a zero-argument callable that is expected to return a string.
    214218        """
    215219        privname = os.path.join(self.basedir, "private", name)
     
    217221            value = fileutil.read(privname)
    218222        except EnvironmentError:
     223            if os.path.exists(privname):
     224                raise
     225            if default is _None:
     226                raise MissingConfigEntry("The required configuration file %s is missing."
     227                                         % (quote_output(privname),))
    219228            if isinstance(default, basestring):
    220229                value = default
  • TabularUnified src/allmydata/scripts/create_node.py

    r7989fe2 r7f8bbcc  
    156156    c.write("# Shall this node automatically upload files created or modified in a local directory?\n")
    157157    c.write("enabled = false\n")
    158     c.write("# This must be a mutable directory writecap.\n")
    159     c.write("upload.dircap =\n")
     158    c.write("# To specify the target of uploads, a mutable directory writecap URI must be placed\n"
     159            "# in 'private/drop_upload_dircap'.\n")
    160160    c.write("local.directory = ~/drop_upload\n")
    161161    c.write("\n")
  • TabularUnified src/allmydata/test/test_client.py

    r7989fe2 r7f8bbcc  
    44
    55import allmydata
    6 from allmydata.node import OldConfigError
     6from allmydata.node import OldConfigError, OldConfigOptionError, MissingConfigEntry
    77from allmydata import client
    88from allmydata.storage_client import StorageFarmBroker
     
    192192                  "enabled = false\n" +
    193193                  "[drop_upload]\n" +
    194                   "enabled = true\n" +
    195                   "upload.dircap = " + upload_dircap + "\n" +
    196                   "local.directory = " + local_dir_utf8 + "\n")
     194                  "enabled = true\n")
    197195
    198196        basedir1 = "test_client.Basic.test_create_drop_uploader1"
    199197        os.mkdir(basedir1)
     198        fileutil.write(os.path.join(basedir1, "tahoe.cfg"),
     199                       config + "local.directory = " + local_dir_utf8 + "\n")
     200        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir1)
     201
    200202        fileutil.write(os.path.join(basedir1, "tahoe.cfg"), config)
     203        fileutil.write(os.path.join(basedir1, "private", "drop_upload_dircap"), "URI:DIR2:blah")
     204        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir1)
     205
     206        fileutil.write(os.path.join(basedir1, "tahoe.cfg"),
     207                       config + "upload.dircap = " + upload_dircap + "\n")
     208        self.failUnlessRaises(OldConfigOptionError, client.Client, basedir1)
     209
     210        fileutil.write(os.path.join(basedir1, "tahoe.cfg"),
     211                       config + "local.directory = " + local_dir_utf8 + "\n")
    201212        c1 = client.Client(basedir1)
    202213        uploader = c1.getServiceNamed('drop-upload')
     
    214225        basedir2 = "test_client.Basic.test_create_drop_uploader2"
    215226        os.mkdir(basedir2)
     227        os.mkdir(os.path.join(basedir2, "private"))
    216228        fileutil.write(os.path.join(basedir2, "tahoe.cfg"),
    217229                       BASECONFIG +
    218230                       "[drop_upload]\n" +
    219                        "enabled = true\n")
     231                       "enabled = true\n" +
     232                       "local.directory = " + local_dir_utf8 + "\n")
     233        fileutil.write(os.path.join(basedir2, "private", "drop_upload_dircap"), "URI:DIR2:blah")
    220234        c2 = client.Client(basedir2)
    221235        self.failUnlessRaises(KeyError, c2.getServiceNamed, 'drop-upload')
    222         self.failIf([True for arg in mock_log_msg.call_args_list if "Boom" in repr(arg)],
    223                     mock_log_msg.call_args_list)
    224         self.failUnless([True for arg in mock_log_msg.call_args_list if "upload.dircap or local.directory not specified" in repr(arg)],
    225                         mock_log_msg.call_args_list)
    226 
    227         basedir3 = "test_client.Basic.test_create_drop_uploader3"
    228         os.mkdir(basedir3)
    229         fileutil.write(os.path.join(basedir3, "tahoe.cfg"), config)
    230         client.Client(basedir3)
    231236        self.failUnless([True for arg in mock_log_msg.call_args_list if "Boom" in repr(arg)],
    232237                        mock_log_msg.call_args_list)
Note: See TracChangeset for help on using the changeset viewer.