2006-11-30 23:23:01 +00:00
|
|
|
|
2007-09-14 03:17:42 +00:00
|
|
|
import os
|
2006-11-30 23:23:01 +00:00
|
|
|
from twisted.trial import unittest
|
2007-06-08 05:09:02 +00:00
|
|
|
from twisted.application import service
|
2008-01-03 21:38:24 +00:00
|
|
|
from twisted.python import log
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2007-04-26 19:01:25 +00:00
|
|
|
import allmydata
|
2008-06-18 19:24:16 +00:00
|
|
|
from allmydata import client
|
|
|
|
from allmydata.introducer.client import IntroducerClient
|
2008-10-29 04:28:31 +00:00
|
|
|
from allmydata.util import base32
|
2007-06-08 05:09:02 +00:00
|
|
|
from foolscap.eventual import flushEventualQueue
|
2008-10-29 04:28:31 +00:00
|
|
|
import common_util as testutil
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2008-06-18 19:24:16 +00:00
|
|
|
class FakeIntroducerClient(IntroducerClient):
|
2007-03-30 03:19:52 +00:00
|
|
|
def __init__(self):
|
2008-02-05 20:05:13 +00:00
|
|
|
self._connections = set()
|
|
|
|
def add_peer(self, nodeid):
|
|
|
|
entry = (nodeid, "storage", "rref")
|
|
|
|
self._connections.add(entry)
|
|
|
|
def remove_all_peers(self):
|
|
|
|
self._connections.clear()
|
2007-03-27 23:12:11 +00:00
|
|
|
|
2006-11-30 23:23:01 +00:00
|
|
|
class Basic(unittest.TestCase):
|
2006-12-01 03:18:51 +00:00
|
|
|
def test_loadable(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
basedir = "test_client.Basic.test_loadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2007-06-08 00:55:49 +00:00
|
|
|
def test_loadable_without_vdrive(self):
|
|
|
|
basedir = "test_client.Basic.test_loadable_without_vdrive"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
|
2007-08-28 02:30:26 +00:00
|
|
|
def test_secrets(self):
|
|
|
|
basedir = "test_client.Basic.test_secrets"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
2007-12-17 23:39:54 +00:00
|
|
|
secret_fname = os.path.join(basedir, "private", "secret")
|
|
|
|
self.failUnless(os.path.exists(secret_fname), secret_fname)
|
2007-08-28 02:30:26 +00:00
|
|
|
renew_secret = c.get_renewal_secret()
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless(base32.b2a(renew_secret))
|
2007-08-28 02:30:26 +00:00
|
|
|
cancel_secret = c.get_cancel_secret()
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless(base32.b2a(cancel_secret))
|
2007-08-28 02:30:26 +00:00
|
|
|
|
2007-07-04 00:27:07 +00:00
|
|
|
def test_sizelimit_1(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_1"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("1000")
|
|
|
|
c = client.Client(basedir)
|
2008-02-06 03:28:59 +00:00
|
|
|
self.failUnlessEqual(c.getServiceNamed("storage").sizelimit, 1000)
|
2007-07-04 00:27:07 +00:00
|
|
|
|
|
|
|
def test_sizelimit_2(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_2"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("10K")
|
|
|
|
c = client.Client(basedir)
|
2008-02-06 03:28:59 +00:00
|
|
|
self.failUnlessEqual(c.getServiceNamed("storage").sizelimit, 10*1000)
|
2007-07-04 00:27:07 +00:00
|
|
|
|
|
|
|
def test_sizelimit_3(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_3"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("5mB")
|
|
|
|
c = client.Client(basedir)
|
2008-02-06 03:28:59 +00:00
|
|
|
self.failUnlessEqual(c.getServiceNamed("storage").sizelimit,
|
2007-07-04 00:27:07 +00:00
|
|
|
5*1000*1000)
|
|
|
|
|
|
|
|
def test_sizelimit_4(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_4"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("78Gb")
|
|
|
|
c = client.Client(basedir)
|
2008-02-06 03:28:59 +00:00
|
|
|
self.failUnlessEqual(c.getServiceNamed("storage").sizelimit,
|
2007-07-04 00:27:07 +00:00
|
|
|
78*1000*1000*1000)
|
|
|
|
|
|
|
|
def test_sizelimit_bad(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_bad"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("bogus")
|
|
|
|
c = client.Client(basedir)
|
2008-02-06 03:28:59 +00:00
|
|
|
self.failUnlessEqual(c.getServiceNamed("storage").sizelimit, None)
|
2007-07-04 00:27:07 +00:00
|
|
|
|
2008-02-05 20:05:13 +00:00
|
|
|
def _permute(self, c, key):
|
|
|
|
return [ peerid
|
|
|
|
for (peerid,rref) in c.get_permuted_peers("storage", key) ]
|
|
|
|
|
2006-12-01 03:18:51 +00:00
|
|
|
def test_permute(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
basedir = "test_client.Basic.test_permute"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
2007-03-30 03:19:52 +00:00
|
|
|
c = client.Client(basedir)
|
2007-12-12 01:10:29 +00:00
|
|
|
c.introducer_client = FakeIntroducerClient()
|
2007-03-23 23:15:57 +00:00
|
|
|
for k in ["%d" % i for i in range(5)]:
|
2008-02-05 20:05:13 +00:00
|
|
|
c.introducer_client.add_peer(k)
|
|
|
|
|
|
|
|
self.failUnlessEqual(self._permute(c, "one"), ['3','1','0','4','2'])
|
|
|
|
self.failUnlessEqual(self._permute(c, "two"), ['0','4','2','1','3'])
|
|
|
|
c.introducer_client.remove_all_peers()
|
|
|
|
self.failUnlessEqual(self._permute(c, "one"), [])
|
2007-03-30 03:19:52 +00:00
|
|
|
|
|
|
|
c2 = client.Client(basedir)
|
2007-12-12 01:10:29 +00:00
|
|
|
c2.introducer_client = FakeIntroducerClient()
|
2007-03-23 23:15:57 +00:00
|
|
|
for k in ["%d" % i for i in range(5)]:
|
2008-02-05 20:05:13 +00:00
|
|
|
c2.introducer_client.add_peer(k)
|
|
|
|
self.failUnlessEqual(self._permute(c2, "one"), ['3','1','0','4','2'])
|
2007-01-16 04:22:22 +00:00
|
|
|
|
2007-04-26 19:01:25 +00:00
|
|
|
def test_versions(self):
|
|
|
|
basedir = "test_client.Basic.test_versions"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
2008-02-06 03:28:59 +00:00
|
|
|
ss = c.getServiceNamed("storage")
|
2008-02-05 20:05:13 +00:00
|
|
|
mine, oldest = ss.remote_get_versions()
|
2008-01-03 21:34:59 +00:00
|
|
|
self.failUnlessEqual(mine, str(allmydata.__version__))
|
|
|
|
self.failIfEqual(str(allmydata.__version__), "unknown")
|
|
|
|
self.failUnless("." in str(allmydata.__version__),
|
|
|
|
"non-numeric version in '%s'" % allmydata.__version__)
|
2008-01-03 21:38:24 +00:00
|
|
|
all_versions = allmydata.get_package_versions_string()
|
|
|
|
self.failUnless("allmydata" in all_versions)
|
|
|
|
log.msg("tahoe versions: %s" % all_versions)
|
2008-04-17 18:13:39 +00:00
|
|
|
# also test stats
|
|
|
|
stats = c.get_stats()
|
|
|
|
self.failUnless("node.uptime" in stats)
|
|
|
|
self.failUnless(isinstance(stats["node.uptime"], float))
|
2007-04-26 19:01:25 +00:00
|
|
|
|
2007-06-08 05:09:02 +00:00
|
|
|
def flush_but_dont_ignore(res):
|
|
|
|
d = flushEventualQueue()
|
|
|
|
def _done(ignored):
|
|
|
|
return res
|
|
|
|
d.addCallback(_done)
|
|
|
|
return d
|
|
|
|
|
2008-04-22 23:47:15 +00:00
|
|
|
class Run(unittest.TestCase, testutil.StallMixin):
|
2007-06-08 05:09:02 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.sparent = service.MultiService()
|
|
|
|
self.sparent.startService()
|
|
|
|
def tearDown(self):
|
|
|
|
d = self.sparent.stopService()
|
|
|
|
d.addBoth(flush_but_dont_ignore)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def test_loadable(self):
|
|
|
|
basedir = "test_client.Run.test_loadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write(dummy)
|
|
|
|
open(os.path.join(basedir, "suicide_prevention_hotline"), "w")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
|
|
|
|
def test_reloadable(self):
|
|
|
|
basedir = "test_client.Run.test_reloadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write(dummy)
|
|
|
|
c1 = client.Client(basedir)
|
|
|
|
c1.setServiceParent(self.sparent)
|
|
|
|
|
2007-11-19 03:41:26 +00:00
|
|
|
# delay to let the service start up completely. I'm not entirely sure
|
|
|
|
# this is necessary.
|
|
|
|
d = self.stall(delay=2.0)
|
|
|
|
d.addCallback(lambda res: c1.disownServiceParent())
|
2007-11-02 02:19:08 +00:00
|
|
|
# the cygwin buildslave seems to need more time to let the old
|
|
|
|
# service completely shut down. When delay=0.1, I saw this test fail,
|
|
|
|
# probably due to the logport trying to reclaim the old socket
|
2007-11-19 03:41:26 +00:00
|
|
|
# number. This suggests that either we're dropping a Deferred
|
|
|
|
# somewhere in the shutdown sequence, or that cygwin is just cranky.
|
|
|
|
d.addCallback(self.stall, delay=2.0)
|
2007-06-08 05:09:02 +00:00
|
|
|
def _restart(res):
|
2007-09-26 04:03:54 +00:00
|
|
|
# TODO: pause for slightly over one second, to let
|
|
|
|
# Client._check_hotline poll the file once. That will exercise
|
|
|
|
# another few lines. Then add another test in which we don't
|
|
|
|
# update the file at all, and watch to see the node shutdown. (to
|
|
|
|
# do this, use a modified node which overrides Node.shutdown(),
|
|
|
|
# also change _check_hotline to use it instead of a raw
|
|
|
|
# reactor.stop, also instrument the shutdown event in an
|
|
|
|
# attribute that we can check)
|
2007-06-08 05:09:02 +00:00
|
|
|
c2 = client.Client(basedir)
|
|
|
|
c2.setServiceParent(self.sparent)
|
|
|
|
return c2.disownServiceParent()
|
|
|
|
d.addCallback(_restart)
|
|
|
|
return d
|
|
|
|
|