Changeset 325028c in trunk


Ignore:
Timestamp:
2016-08-31T08:50:13Z (9 years ago)
Author:
Brian Warner <warner@…>
Branches:
master
Children:
d47fc0f
Parents:
72f17afa
Message:

error if tcp=tor is requested but tor is unimportable

This only catches txtorcon not being installed (which should be fixed by
doing pip install tahoe-lafs[tor]). It doesn't notice that the Tor
daemon is not running (which we can't detect during startup, only
afterwards, when it's harder to notify the user), in which case Tor
connections (and all connections when "tcp = tor" is enabled) will just
fail silently.

Location:
src/allmydata
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/node.py

    r72f17afa r325028c  
    1414from allmydata.util.encodingutil import get_filesystem_encoding, quote_output
    1515from allmydata.util import configutil
     16
     17def _import_tor():
     18    # this exists to be overridden by unit tests
     19    try:
     20        from foolscap.connections import tor
     21        return tor
     22    except ImportError: # pragma: no cover
     23        return None
     24
     25def _import_i2p():
     26    try:
     27        from foolscap.connections import i2p
     28        return i2p
     29    except ImportError: # pragma: no cover
     30        return None
    1631
    1732# Add our application versions to the data that Foolscap's LogPublisher
     
    176191        if not enabled:
    177192            return None
    178         try:
    179             from foolscap.connections import tor
    180         except ImportError:
     193        tor = _import_tor()
     194        if not tor:
    181195            return None
    182196
     
    216230        if not enabled:
    217231            return None
    218         try:
    219             from foolscap.connections import i2p
    220         except ImportError:
     232        i2p = _import_i2p()
     233        if not i2p:
    221234            return None
    222235
     
    260273                             " uses unknown handler type '%s'"
    261274                             % tcp_handler_name)
     275        if not handlers[tcp_handler_name]:
     276            raise ValueError("'tahoe.cfg [connections] tcp=' uses "
     277                             "unavailable/unimportable handler type '%s'. "
     278                             "Please pip install tahoe-lafs[%s] to fix."
     279                             % (tcp_handler_name, tcp_handler_name))
    262280        self._default_connection_handlers["tcp"] = tcp_handler_name
    263281
  • TabularUnified src/allmydata/test/test_connections.py

    r72f17afa r325028c  
    3030        self.assertEqual(h, None)
    3131
     32    def test_unimportable(self):
     33        n = FakeNode(BASECONFIG)
     34        with mock.patch("allmydata.node._import_tor", return_value=None):
     35            h = n._make_tor_handler()
     36        self.assertEqual(h, None)
     37
    3238    def test_default(self):
    3339        n = FakeNode(BASECONFIG)
     
    108114        n = FakeNode(BASECONFIG+"[i2p]\nenable = false\n")
    109115        h = n._make_i2p_handler()
     116        self.assertEqual(h, None)
     117
     118    def test_unimportable(self):
     119        n = FakeNode(BASECONFIG)
     120        with mock.patch("allmydata.node._import_i2p", return_value=None):
     121            h = n._make_i2p_handler()
    110122        self.assertEqual(h, None)
    111123
     
    205217        self.assertEqual(n._default_connection_handlers["i2p"], "i2p")
    206218
     219    def test_tor_unimportable(self):
     220        n = FakeNode(BASECONFIG+"[connections]\ntcp = tor\n")
     221        with mock.patch("allmydata.node._import_tor", return_value=None):
     222            e = self.assertRaises(ValueError, n.init_connections)
     223        self.assertEqual(str(e),
     224                         "'tahoe.cfg [connections] tcp='"
     225                         " uses unavailable/unimportable handler type 'tor'."
     226                         " Please pip install tahoe-lafs[tor] to fix.")
     227
    207228    def test_unknown(self):
    208229        n = FakeNode(BASECONFIG+"[connections]\ntcp = unknown\n")
Note: See TracChangeset for help on using the changeset viewer.