2009-02-16 21:58:44 +00:00
|
|
|
|
|
|
|
# This contains a test harness that creates a full Tahoe grid in a single
|
|
|
|
# process (actually in a single MultiService) which does not use the network.
|
|
|
|
# It does not use an Introducer, and there are no foolscap Tubs. Each storage
|
|
|
|
# server puts real shares on disk, but is accessed through loopback
|
|
|
|
# RemoteReferences instead of over serialized SSL. It is not as complete as
|
|
|
|
# the common.SystemTestMixin framework (which does use the network), but
|
2009-02-17 01:06:43 +00:00
|
|
|
# should be considerably faster: on my laptop, it takes 50-80ms to start up,
|
|
|
|
# whereas SystemTestMixin takes close to 2s.
|
|
|
|
|
|
|
|
# This should be useful for tests which want to examine and/or manipulate the
|
|
|
|
# uploaded shares, checker/verifier/repairer tests, etc. The clients have no
|
|
|
|
# Tubs, so it is not useful for tests that involve a Helper, a KeyGenerator,
|
|
|
|
# or the control.furl .
|
2009-02-16 21:58:44 +00:00
|
|
|
|
|
|
|
import os.path
|
2009-06-21 23:51:19 +00:00
|
|
|
from zope.interface import implements
|
2009-02-16 21:58:44 +00:00
|
|
|
from twisted.application import service
|
2010-01-29 12:38:45 +00:00
|
|
|
from twisted.internet import defer, reactor
|
2009-05-22 00:46:32 +00:00
|
|
|
from twisted.python.failure import Failure
|
|
|
|
from foolscap.api import Referenceable, fireEventually, RemoteException
|
2009-02-16 21:58:44 +00:00
|
|
|
from base64 import b32encode
|
2009-02-17 05:12:42 +00:00
|
|
|
from allmydata import uri as tahoe_uri
|
2009-02-16 21:58:44 +00:00
|
|
|
from allmydata.client import Client
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.server import StorageServer, storage_index_to_dir
|
2009-05-22 00:46:32 +00:00
|
|
|
from allmydata.util import fileutil, idlib, hashutil
|
2009-12-15 00:01:47 +00:00
|
|
|
from allmydata.util.hashutil import sha1
|
2009-02-25 01:33:00 +00:00
|
|
|
from allmydata.test.common_web import HTTPClientGETFactory
|
2009-06-21 23:51:19 +00:00
|
|
|
from allmydata.interfaces import IStorageBroker
|
2009-02-16 21:58:44 +00:00
|
|
|
|
|
|
|
class IntentionalError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Marker:
|
|
|
|
pass
|
|
|
|
|
|
|
|
class LocalWrapper:
|
|
|
|
def __init__(self, original):
|
|
|
|
self.original = original
|
|
|
|
self.broken = False
|
2010-01-29 12:38:45 +00:00
|
|
|
self.hung_until = None
|
2009-02-16 21:58:44 +00:00
|
|
|
self.post_call_notifier = None
|
|
|
|
self.disconnectors = {}
|
|
|
|
|
2009-02-17 00:19:47 +00:00
|
|
|
def callRemoteOnly(self, methname, *args, **kwargs):
|
|
|
|
d = self.callRemote(methname, *args, **kwargs)
|
2010-01-14 22:17:19 +00:00
|
|
|
del d # explicitly ignored
|
2009-02-17 00:19:47 +00:00
|
|
|
return None
|
|
|
|
|
2009-02-16 21:58:44 +00:00
|
|
|
def callRemote(self, methname, *args, **kwargs):
|
2009-02-17 00:19:47 +00:00
|
|
|
# this is ideally a Membrane, but that's too hard. We do a shallow
|
|
|
|
# wrapping of inbound arguments, and per-methodname wrapping of
|
|
|
|
# selected return values.
|
2009-02-16 21:58:44 +00:00
|
|
|
def wrap(a):
|
|
|
|
if isinstance(a, Referenceable):
|
|
|
|
return LocalWrapper(a)
|
|
|
|
else:
|
|
|
|
return a
|
|
|
|
args = tuple([wrap(a) for a in args])
|
|
|
|
kwargs = dict([(k,wrap(kwargs[k])) for k in kwargs])
|
2010-01-29 12:38:45 +00:00
|
|
|
|
|
|
|
def _really_call():
|
|
|
|
meth = getattr(self.original, "remote_" + methname)
|
|
|
|
return meth(*args, **kwargs)
|
|
|
|
|
2009-02-16 21:58:44 +00:00
|
|
|
def _call():
|
|
|
|
if self.broken:
|
|
|
|
raise IntentionalError("I was asked to break")
|
2010-01-29 12:38:45 +00:00
|
|
|
if self.hung_until:
|
|
|
|
d2 = defer.Deferred()
|
|
|
|
self.hung_until.addCallback(lambda ign: _really_call())
|
|
|
|
self.hung_until.addCallback(lambda res: d2.callback(res))
|
|
|
|
def _err(res):
|
|
|
|
d2.errback(res)
|
|
|
|
return res
|
|
|
|
self.hung_until.addErrback(_err)
|
|
|
|
return d2
|
|
|
|
return _really_call()
|
|
|
|
|
2009-02-16 21:58:44 +00:00
|
|
|
d = fireEventually()
|
|
|
|
d.addCallback(lambda res: _call())
|
2009-05-22 00:46:32 +00:00
|
|
|
def _wrap_exception(f):
|
|
|
|
return Failure(RemoteException(f))
|
|
|
|
d.addErrback(_wrap_exception)
|
2009-02-16 21:58:44 +00:00
|
|
|
def _return_membrane(res):
|
|
|
|
# rather than complete the difficult task of building a
|
|
|
|
# fully-general Membrane (which would locate all Referenceable
|
|
|
|
# objects that cross the simulated wire and replace them with
|
|
|
|
# wrappers), we special-case certain methods that we happen to
|
|
|
|
# know will return Referenceables.
|
|
|
|
if methname == "allocate_buckets":
|
|
|
|
(alreadygot, allocated) = res
|
|
|
|
for shnum in allocated:
|
|
|
|
allocated[shnum] = LocalWrapper(allocated[shnum])
|
|
|
|
if methname == "get_buckets":
|
|
|
|
for shnum in res:
|
|
|
|
res[shnum] = LocalWrapper(res[shnum])
|
|
|
|
return res
|
|
|
|
d.addCallback(_return_membrane)
|
|
|
|
if self.post_call_notifier:
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
d.addCallback(self.post_call_notifier, self, methname)
|
2009-02-16 21:58:44 +00:00
|
|
|
return d
|
|
|
|
|
|
|
|
def notifyOnDisconnect(self, f, *args, **kwargs):
|
|
|
|
m = Marker()
|
|
|
|
self.disconnectors[m] = (f, args, kwargs)
|
|
|
|
return m
|
|
|
|
def dontNotifyOnDisconnect(self, marker):
|
|
|
|
del self.disconnectors[marker]
|
|
|
|
|
2009-06-23 02:10:47 +00:00
|
|
|
def wrap_storage_server(original):
|
2009-05-22 00:46:32 +00:00
|
|
|
# Much of the upload/download code uses rref.version (which normally
|
|
|
|
# comes from rrefutil.add_version_to_remote_reference). To avoid using a
|
|
|
|
# network, we want a LocalWrapper here. Try to satisfy all these
|
|
|
|
# constraints at the same time.
|
|
|
|
wrapper = LocalWrapper(original)
|
2009-06-23 02:10:47 +00:00
|
|
|
wrapper.version = original.remote_get_version()
|
2009-05-22 00:46:32 +00:00
|
|
|
return wrapper
|
2009-02-16 21:58:44 +00:00
|
|
|
|
2009-06-01 21:06:04 +00:00
|
|
|
class NoNetworkStorageBroker:
|
2009-06-21 23:51:19 +00:00
|
|
|
implements(IStorageBroker)
|
|
|
|
def get_servers_for_index(self, key):
|
2009-06-01 21:06:04 +00:00
|
|
|
return sorted(self.client._servers,
|
2009-12-15 00:01:47 +00:00
|
|
|
key=lambda x: sha1(key+x[0]).digest())
|
2009-06-21 23:51:19 +00:00
|
|
|
def get_all_servers(self):
|
|
|
|
return frozenset(self.client._servers)
|
2009-06-02 03:07:50 +00:00
|
|
|
def get_nickname_for_serverid(self, serverid):
|
|
|
|
return None
|
2009-06-01 21:06:04 +00:00
|
|
|
|
2009-02-16 21:58:44 +00:00
|
|
|
class NoNetworkClient(Client):
|
|
|
|
def create_tub(self):
|
|
|
|
pass
|
|
|
|
def init_introducer_client(self):
|
|
|
|
pass
|
|
|
|
def setup_logging(self):
|
|
|
|
pass
|
|
|
|
def startService(self):
|
|
|
|
service.MultiService.startService(self)
|
|
|
|
def stopService(self):
|
|
|
|
service.MultiService.stopService(self)
|
|
|
|
def when_tub_ready(self):
|
2009-02-23 00:28:55 +00:00
|
|
|
raise NotImplementedError("NoNetworkClient has no Tub")
|
2009-02-16 21:58:44 +00:00
|
|
|
def init_control(self):
|
|
|
|
pass
|
|
|
|
def init_helper(self):
|
|
|
|
pass
|
|
|
|
def init_key_gen(self):
|
|
|
|
pass
|
|
|
|
def init_storage(self):
|
|
|
|
pass
|
2009-06-01 21:06:04 +00:00
|
|
|
def init_client_storage_broker(self):
|
|
|
|
self.storage_broker = NoNetworkStorageBroker()
|
|
|
|
self.storage_broker.client = self
|
2009-02-16 21:58:44 +00:00
|
|
|
def init_stub_client(self):
|
|
|
|
pass
|
2009-06-21 23:51:19 +00:00
|
|
|
#._servers will be set by the NoNetworkGrid which creates us
|
2009-02-16 21:58:44 +00:00
|
|
|
|
2009-02-24 00:39:37 +00:00
|
|
|
class SimpleStats:
|
|
|
|
def __init__(self):
|
|
|
|
self.counters = {}
|
|
|
|
self.stats_producers = []
|
|
|
|
|
|
|
|
def count(self, name, delta=1):
|
|
|
|
val = self.counters.setdefault(name, 0)
|
|
|
|
self.counters[name] = val + delta
|
|
|
|
|
|
|
|
def register_producer(self, stats_producer):
|
|
|
|
self.stats_producers.append(stats_producer)
|
|
|
|
|
|
|
|
def get_stats(self):
|
|
|
|
stats = {}
|
|
|
|
for sp in self.stats_producers:
|
|
|
|
stats.update(sp.get_stats())
|
|
|
|
ret = { 'counters': self.counters, 'stats': stats }
|
|
|
|
return ret
|
2009-02-16 21:58:44 +00:00
|
|
|
|
|
|
|
class NoNetworkGrid(service.MultiService):
|
2009-02-17 00:44:57 +00:00
|
|
|
def __init__(self, basedir, num_clients=1, num_servers=10,
|
|
|
|
client_config_hooks={}):
|
2009-02-16 21:58:44 +00:00
|
|
|
service.MultiService.__init__(self)
|
|
|
|
self.basedir = basedir
|
|
|
|
fileutil.make_dirs(basedir)
|
|
|
|
|
2009-02-17 00:36:58 +00:00
|
|
|
self.servers_by_number = {}
|
|
|
|
self.servers_by_id = {}
|
2009-02-17 00:19:47 +00:00
|
|
|
self.clients = []
|
|
|
|
|
2009-02-16 21:58:44 +00:00
|
|
|
for i in range(num_servers):
|
2009-02-20 03:22:54 +00:00
|
|
|
ss = self.make_server(i)
|
|
|
|
self.add_server(i, ss)
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.rebuild_serverlist()
|
2009-02-16 21:58:44 +00:00
|
|
|
|
|
|
|
for i in range(num_clients):
|
|
|
|
clientid = hashutil.tagged_hash("clientid", str(i))[:20]
|
|
|
|
clientdir = os.path.join(basedir, "clients",
|
|
|
|
idlib.shortnodeid_b2a(clientid))
|
|
|
|
fileutil.make_dirs(clientdir)
|
2009-02-17 00:19:47 +00:00
|
|
|
f = open(os.path.join(clientdir, "tahoe.cfg"), "w")
|
|
|
|
f.write("[node]\n")
|
|
|
|
f.write("nickname = client-%d\n" % i)
|
|
|
|
f.write("web.port = tcp:0:interface=127.0.0.1\n")
|
|
|
|
f.write("[storage]\n")
|
|
|
|
f.write("enabled = false\n")
|
|
|
|
f.close()
|
2009-02-17 00:44:57 +00:00
|
|
|
c = None
|
|
|
|
if i in client_config_hooks:
|
|
|
|
# this hook can either modify tahoe.cfg, or return an
|
|
|
|
# entirely new Client instance
|
|
|
|
c = client_config_hooks[i](clientdir)
|
|
|
|
if not c:
|
|
|
|
c = NoNetworkClient(clientdir)
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
c.set_default_mutable_keysize(522)
|
2009-02-16 21:58:44 +00:00
|
|
|
c.nodeid = clientid
|
|
|
|
c.short_nodeid = b32encode(clientid).lower()[:8]
|
|
|
|
c._servers = self.all_servers # can be updated later
|
|
|
|
c.setServiceParent(self)
|
|
|
|
self.clients.append(c)
|
|
|
|
|
2009-02-20 03:22:54 +00:00
|
|
|
def make_server(self, i):
|
|
|
|
serverid = hashutil.tagged_hash("serverid", str(i))[:20]
|
|
|
|
serverdir = os.path.join(self.basedir, "servers",
|
|
|
|
idlib.shortnodeid_b2a(serverid))
|
|
|
|
fileutil.make_dirs(serverdir)
|
2009-02-24 00:39:37 +00:00
|
|
|
ss = StorageServer(serverdir, serverid, stats_provider=SimpleStats())
|
2009-02-20 03:22:54 +00:00
|
|
|
return ss
|
|
|
|
|
|
|
|
def add_server(self, i, ss):
|
|
|
|
# to deal with the fact that all StorageServers are named 'storage',
|
|
|
|
# we interpose a middleman
|
|
|
|
middleman = service.MultiService()
|
|
|
|
middleman.setServiceParent(self)
|
|
|
|
ss.setServiceParent(middleman)
|
|
|
|
serverid = ss.my_nodeid
|
2009-02-17 00:36:58 +00:00
|
|
|
self.servers_by_number[i] = ss
|
2009-06-23 02:10:47 +00:00
|
|
|
self.servers_by_id[serverid] = wrap_storage_server(ss)
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.rebuild_serverlist()
|
|
|
|
|
|
|
|
def rebuild_serverlist(self):
|
2009-02-17 00:36:58 +00:00
|
|
|
self.all_servers = frozenset(self.servers_by_id.items())
|
2009-02-17 00:19:47 +00:00
|
|
|
for c in self.clients:
|
|
|
|
c._servers = self.all_servers
|
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def remove_server(self, serverid):
|
|
|
|
# it's enough to remove the server from c._servers (we don't actually
|
|
|
|
# have to detach and stopService it)
|
|
|
|
for i,ss in self.servers_by_number.items():
|
|
|
|
if ss.my_nodeid == serverid:
|
|
|
|
del self.servers_by_number[i]
|
|
|
|
break
|
|
|
|
del self.servers_by_id[serverid]
|
|
|
|
self.rebuild_serverlist()
|
|
|
|
|
|
|
|
def break_server(self, serverid):
|
|
|
|
# mark the given server as broken, so it will throw exceptions when
|
|
|
|
# asked to hold a share
|
|
|
|
self.servers_by_id[serverid].broken = True
|
|
|
|
|
2010-01-29 12:38:45 +00:00
|
|
|
def hang_server(self, serverid, until=defer.Deferred()):
|
|
|
|
# hang the given server until 'until' fires
|
|
|
|
self.servers_by_id[serverid].hung_until = until
|
|
|
|
|
|
|
|
|
2009-02-17 00:19:47 +00:00
|
|
|
class GridTestMixin:
|
|
|
|
def setUp(self):
|
|
|
|
self.s = service.MultiService()
|
|
|
|
self.s.startService()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
return self.s.stopService()
|
|
|
|
|
2009-02-20 03:22:54 +00:00
|
|
|
def set_up_grid(self, num_clients=1, num_servers=10,
|
|
|
|
client_config_hooks={}):
|
2009-02-17 00:19:47 +00:00
|
|
|
# self.basedir must be set
|
2009-02-20 03:22:54 +00:00
|
|
|
self.g = NoNetworkGrid(self.basedir,
|
|
|
|
num_clients=num_clients,
|
|
|
|
num_servers=num_servers,
|
2009-02-17 00:44:57 +00:00
|
|
|
client_config_hooks=client_config_hooks)
|
2009-02-17 00:19:47 +00:00
|
|
|
self.g.setServiceParent(self.s)
|
2009-02-17 05:12:42 +00:00
|
|
|
self.client_webports = [c.getServiceNamed("webish").listener._port.getHost().port
|
|
|
|
for c in self.g.clients]
|
|
|
|
self.client_baseurls = ["http://localhost:%d/" % p
|
|
|
|
for p in self.client_webports]
|
2009-02-17 00:19:47 +00:00
|
|
|
|
|
|
|
def get_clientdir(self, i=0):
|
|
|
|
return self.g.clients[i].basedir
|
2009-02-17 00:36:58 +00:00
|
|
|
|
|
|
|
def get_serverdir(self, i):
|
|
|
|
return self.g.servers_by_number[i].storedir
|
|
|
|
|
|
|
|
def iterate_servers(self):
|
|
|
|
for i in sorted(self.g.servers_by_number.keys()):
|
|
|
|
ss = self.g.servers_by_number[i]
|
|
|
|
yield (i, ss, ss.storedir)
|
2009-02-17 05:12:42 +00:00
|
|
|
|
|
|
|
def find_shares(self, uri):
|
|
|
|
si = tahoe_uri.from_string(uri).get_storage_index()
|
|
|
|
prefixdir = storage_index_to_dir(si)
|
|
|
|
shares = []
|
|
|
|
for i,ss in self.g.servers_by_number.items():
|
|
|
|
serverid = ss.my_nodeid
|
|
|
|
basedir = os.path.join(ss.storedir, "shares", prefixdir)
|
|
|
|
if not os.path.exists(basedir):
|
|
|
|
continue
|
|
|
|
for f in os.listdir(basedir):
|
|
|
|
try:
|
|
|
|
shnum = int(f)
|
|
|
|
shares.append((shnum, serverid, os.path.join(basedir, f)))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return sorted(shares)
|
|
|
|
|
2009-02-24 00:42:27 +00:00
|
|
|
def delete_share(self, (shnum, serverid, sharefile)):
|
|
|
|
os.unlink(sharefile)
|
|
|
|
|
|
|
|
def delete_shares_numbered(self, uri, shnums):
|
|
|
|
for (i_shnum, i_serverid, i_sharefile) in self.find_shares(uri):
|
|
|
|
if i_shnum in shnums:
|
|
|
|
os.unlink(i_sharefile)
|
|
|
|
|
|
|
|
def corrupt_share(self, (shnum, serverid, sharefile), corruptor_function):
|
|
|
|
sharedata = open(sharefile, "rb").read()
|
|
|
|
corruptdata = corruptor_function(sharedata)
|
|
|
|
open(sharefile, "wb").write(corruptdata)
|
2009-02-24 05:15:06 +00:00
|
|
|
|
2010-01-10 01:36:19 +00:00
|
|
|
def corrupt_shares_numbered(self, uri, shnums, corruptor, debug=False):
|
2009-02-24 05:15:06 +00:00
|
|
|
for (i_shnum, i_serverid, i_sharefile) in self.find_shares(uri):
|
|
|
|
if i_shnum in shnums:
|
|
|
|
sharedata = open(i_sharefile, "rb").read()
|
2010-01-10 01:36:19 +00:00
|
|
|
corruptdata = corruptor(sharedata, debug=debug)
|
2009-02-24 05:15:06 +00:00
|
|
|
open(i_sharefile, "wb").write(corruptdata)
|
2009-02-25 01:33:00 +00:00
|
|
|
|
|
|
|
def GET(self, urlpath, followRedirect=False, return_response=False,
|
|
|
|
method="GET", clientnum=0, **kwargs):
|
|
|
|
# if return_response=True, this fires with (data, statuscode,
|
|
|
|
# respheaders) instead of just data.
|
|
|
|
assert not isinstance(urlpath, unicode)
|
|
|
|
url = self.client_baseurls[clientnum] + urlpath
|
|
|
|
factory = HTTPClientGETFactory(url, method=method,
|
|
|
|
followRedirect=followRedirect, **kwargs)
|
|
|
|
reactor.connectTCP("localhost", self.client_webports[clientnum],factory)
|
|
|
|
d = factory.deferred
|
|
|
|
def _got_data(data):
|
|
|
|
return (data, factory.status, factory.response_headers)
|
|
|
|
if return_response:
|
|
|
|
d.addCallback(_got_data)
|
|
|
|
return factory.deferred
|