diff --git src/allmydata/node.py src/allmydata/node.py
index 7f5bf61..04a1035 100644
|
|
class Node(service.MultiService): |
258 | 258 | |
259 | 259 | service.MultiService.startService(self) |
260 | 260 | d = defer.succeed(None) |
261 | | d.addCallback(lambda res: iputil.get_local_addresses_async()) |
| 261 | location = self.get_config("node", "tub.location", None) |
| 262 | if location == "": |
| 263 | d.addCallback(lambda res: ['127.0.0.1']) |
| 264 | else: |
| 265 | d.addCallback(lambda res: iputil.get_local_addresses_async()) |
262 | 266 | d.addCallback(self._setup_tub) |
263 | 267 | def _ready(res): |
264 | 268 | self.log("%s running" % self.NODETYPE) |
… |
… |
class Node(service.MultiService): |
333 | 337 | base_location = ",".join([ "%s:%d" % (addr, portnum) |
334 | 338 | for addr in local_addresses ]) |
335 | 339 | location = self.get_config("node", "tub.location", base_location) |
| 340 | if location == "": |
| 341 | location = base_location |
336 | 342 | self.log("Tub location set to %s" % location) |
337 | 343 | self.tub.setLocation(location) |
338 | 344 | |
diff --git src/allmydata/test/test_node.py src/allmydata/test/test_node.py
index 24ec571..c1300c1 100644
|
|
|
1 | 1 | |
2 | 2 | import os, stat, sys, time |
| 3 | |
| 4 | from mock import patch |
| 5 | |
3 | 6 | from twisted.trial import unittest |
4 | 7 | from twisted.internet import defer |
5 | 8 | from twisted.python import log |
… |
… |
class TestCase(testutil.SignalMixin, unittest.TestCase): |
31 | 34 | d.addCallback(flushEventualQueue) |
32 | 35 | return d |
33 | 36 | |
| 37 | # XXX should use mock decorator from #1301 |
| 38 | def test_anonymous_location(self): |
| 39 | patcher = patch('allmydata.util.iputil.get_local_addresses_async') |
| 40 | mock = patcher.__enter__() |
| 41 | mock.return_value = ["1.2.3.4"] |
| 42 | |
| 43 | basedir = "test_node/test_anonymous_location" |
| 44 | fileutil.make_dirs(basedir) |
| 45 | f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt') |
| 46 | f.write("[node]\n") |
| 47 | f.write("tub.location = \n") |
| 48 | f.close() |
| 49 | |
| 50 | n = TestNode(basedir) |
| 51 | n.setServiceParent(self.parent) |
| 52 | d = n.when_tub_ready() |
| 53 | |
| 54 | def _check_addresses(ignored_result): |
| 55 | furl = n.tub.registerReference(n) |
| 56 | self.failIf("1.2.3.4" in furl, furl) |
| 57 | self.failUnless("127.0.0.1" in furl, furl) |
| 58 | |
| 59 | d.addCallback(_check_addresses) |
| 60 | |
| 61 | def cleanup(res): |
| 62 | patcher.__exit__() |
| 63 | return res |
| 64 | d.addBoth(cleanup) |
| 65 | return d |
| 66 | |
34 | 67 | def test_location(self): |
35 | 68 | basedir = "test_node/test_location" |
36 | 69 | fileutil.make_dirs(basedir) |