mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 17:52:50 +00:00
immutable: extend the tests to check that the shares that got uploaded really do make a sufficiently Happy distribution
This patch also renames some instances of "find_shares()" to "find_all_shares()" and other instances to "find_uri_shares()" as appropriate -- the conflation between those names confused me at first when writing these tests.
This commit is contained in:
parent
2e83f243c2
commit
1dbfcf753d
@ -956,7 +956,7 @@ class ShareManglingMixin(SystemTestMixin):
|
|||||||
d.addCallback(_stash_it)
|
d.addCallback(_stash_it)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def find_shares(self, unused=None):
|
def find_all_shares(self, unused=None):
|
||||||
"""Locate shares on disk. Returns a dict that maps
|
"""Locate shares on disk. Returns a dict that maps
|
||||||
(clientnum,sharenum) to a string that contains the share container
|
(clientnum,sharenum) to a string that contains the share container
|
||||||
(copied directly from the disk, containing leases etc). You can
|
(copied directly from the disk, containing leases etc). You can
|
||||||
@ -981,7 +981,7 @@ class ShareManglingMixin(SystemTestMixin):
|
|||||||
|
|
||||||
def replace_shares(self, newshares, storage_index):
|
def replace_shares(self, newshares, storage_index):
|
||||||
"""Replace shares on disk. Takes a dictionary in the same form
|
"""Replace shares on disk. Takes a dictionary in the same form
|
||||||
as find_shares() returns."""
|
as find_all_shares() returns."""
|
||||||
|
|
||||||
for i, c in enumerate(self.clients):
|
for i, c in enumerate(self.clients):
|
||||||
sharedir = c.getServiceNamed("storage").sharedir
|
sharedir = c.getServiceNamed("storage").sharedir
|
||||||
@ -1006,7 +1006,7 @@ class ShareManglingMixin(SystemTestMixin):
|
|||||||
def _delete_a_share(self, unused=None, sharenum=None):
|
def _delete_a_share(self, unused=None, sharenum=None):
|
||||||
""" Delete one share. """
|
""" Delete one share. """
|
||||||
|
|
||||||
shares = self.find_shares()
|
shares = self.find_all_shares()
|
||||||
ks = shares.keys()
|
ks = shares.keys()
|
||||||
if sharenum is not None:
|
if sharenum is not None:
|
||||||
k = [ key for key in shares.keys() if key[1] == sharenum ][0]
|
k = [ key for key in shares.keys() if key[1] == sharenum ][0]
|
||||||
@ -1018,7 +1018,7 @@ class ShareManglingMixin(SystemTestMixin):
|
|||||||
return unused
|
return unused
|
||||||
|
|
||||||
def _corrupt_a_share(self, unused, corruptor_func, sharenum):
|
def _corrupt_a_share(self, unused, corruptor_func, sharenum):
|
||||||
shares = self.find_shares()
|
shares = self.find_all_shares()
|
||||||
ks = [ key for key in shares.keys() if key[1] == sharenum ]
|
ks = [ key for key in shares.keys() if key[1] == sharenum ]
|
||||||
assert ks, (shares.keys(), sharenum)
|
assert ks, (shares.keys(), sharenum)
|
||||||
k = ks[0]
|
k = ks[0]
|
||||||
@ -1028,14 +1028,14 @@ class ShareManglingMixin(SystemTestMixin):
|
|||||||
|
|
||||||
def _corrupt_all_shares(self, unused, corruptor_func):
|
def _corrupt_all_shares(self, unused, corruptor_func):
|
||||||
""" All shares on disk will be corrupted by corruptor_func. """
|
""" All shares on disk will be corrupted by corruptor_func. """
|
||||||
shares = self.find_shares()
|
shares = self.find_all_shares()
|
||||||
for k in shares.keys():
|
for k in shares.keys():
|
||||||
self._corrupt_a_share(unused, corruptor_func, k[1])
|
self._corrupt_a_share(unused, corruptor_func, k[1])
|
||||||
return corruptor_func
|
return corruptor_func
|
||||||
|
|
||||||
def _corrupt_a_random_share(self, unused, corruptor_func):
|
def _corrupt_a_random_share(self, unused, corruptor_func):
|
||||||
""" Exactly one share on disk will be corrupted by corruptor_func. """
|
""" Exactly one share on disk will be corrupted by corruptor_func. """
|
||||||
shares = self.find_shares()
|
shares = self.find_all_shares()
|
||||||
ks = shares.keys()
|
ks = shares.keys()
|
||||||
k = random.choice(ks)
|
k = random.choice(ks)
|
||||||
self._corrupt_a_share(unused, corruptor_func, k[1])
|
self._corrupt_a_share(unused, corruptor_func, k[1])
|
||||||
|
@ -302,7 +302,7 @@ class GridTestMixin:
|
|||||||
ss = self.g.servers_by_number[i]
|
ss = self.g.servers_by_number[i]
|
||||||
yield (i, ss, ss.storedir)
|
yield (i, ss, ss.storedir)
|
||||||
|
|
||||||
def find_shares(self, uri):
|
def find_uri_shares(self, uri):
|
||||||
si = tahoe_uri.from_string(uri).get_storage_index()
|
si = tahoe_uri.from_string(uri).get_storage_index()
|
||||||
prefixdir = storage_index_to_dir(si)
|
prefixdir = storage_index_to_dir(si)
|
||||||
shares = []
|
shares = []
|
||||||
@ -323,7 +323,7 @@ class GridTestMixin:
|
|||||||
os.unlink(sharefile)
|
os.unlink(sharefile)
|
||||||
|
|
||||||
def delete_shares_numbered(self, uri, shnums):
|
def delete_shares_numbered(self, uri, shnums):
|
||||||
for (i_shnum, i_serverid, i_sharefile) in self.find_shares(uri):
|
for (i_shnum, i_serverid, i_sharefile) in self.find_uri_shares(uri):
|
||||||
if i_shnum in shnums:
|
if i_shnum in shnums:
|
||||||
os.unlink(i_sharefile)
|
os.unlink(i_sharefile)
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ class GridTestMixin:
|
|||||||
open(sharefile, "wb").write(corruptdata)
|
open(sharefile, "wb").write(corruptdata)
|
||||||
|
|
||||||
def corrupt_shares_numbered(self, uri, shnums, corruptor, debug=False):
|
def corrupt_shares_numbered(self, uri, shnums, corruptor, debug=False):
|
||||||
for (i_shnum, i_serverid, i_sharefile) in self.find_shares(uri):
|
for (i_shnum, i_serverid, i_sharefile) in self.find_uri_shares(uri):
|
||||||
if i_shnum in shnums:
|
if i_shnum in shnums:
|
||||||
sharedata = open(i_sharefile, "rb").read()
|
sharedata = open(i_sharefile, "rb").read()
|
||||||
corruptdata = corruptor(sharedata, debug=debug)
|
corruptdata = corruptor(sharedata, debug=debug)
|
||||||
|
@ -1995,7 +1995,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
|
|
||||||
def _clobber_shares(ignored):
|
def _clobber_shares(ignored):
|
||||||
# delete one, corrupt a second
|
# delete one, corrupt a second
|
||||||
shares = self.find_shares(self.uri)
|
shares = self.find_uri_shares(self.uri)
|
||||||
self.failUnlessReallyEqual(len(shares), 10)
|
self.failUnlessReallyEqual(len(shares), 10)
|
||||||
os.unlink(shares[0][2])
|
os.unlink(shares[0][2])
|
||||||
cso = debug.CorruptShareOptions()
|
cso = debug.CorruptShareOptions()
|
||||||
@ -2120,11 +2120,11 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
d.addCallback(_check_stats)
|
d.addCallback(_check_stats)
|
||||||
|
|
||||||
def _clobber_shares(ignored):
|
def _clobber_shares(ignored):
|
||||||
shares = self.find_shares(self.uris[u"gööd"])
|
shares = self.find_uri_shares(self.uris[u"gööd"])
|
||||||
self.failUnlessReallyEqual(len(shares), 10)
|
self.failUnlessReallyEqual(len(shares), 10)
|
||||||
os.unlink(shares[0][2])
|
os.unlink(shares[0][2])
|
||||||
|
|
||||||
shares = self.find_shares(self.uris["mutable"])
|
shares = self.find_uri_shares(self.uris["mutable"])
|
||||||
cso = debug.CorruptShareOptions()
|
cso = debug.CorruptShareOptions()
|
||||||
cso.stdout = StringIO()
|
cso.stdout = StringIO()
|
||||||
cso.parseOptions([shares[1][2]])
|
cso.parseOptions([shares[1][2]])
|
||||||
|
@ -991,7 +991,7 @@ class DeepCheckWebBad(DeepCheckBase, unittest.TestCase):
|
|||||||
self.delete_shares_numbered(node.get_uri(), [0,1])
|
self.delete_shares_numbered(node.get_uri(), [0,1])
|
||||||
|
|
||||||
def _corrupt_some_shares(self, node):
|
def _corrupt_some_shares(self, node):
|
||||||
for (shnum, serverid, sharefile) in self.find_shares(node.get_uri()):
|
for (shnum, serverid, sharefile) in self.find_uri_shares(node.get_uri()):
|
||||||
if shnum in (0,1):
|
if shnum in (0,1):
|
||||||
self._run_cli(["debug", "corrupt-share", sharefile])
|
self._run_cli(["debug", "corrupt-share", sharefile])
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class HungServerDownloadTest(GridTestMixin, ShouldFailMixin, unittest.TestCase):
|
|||||||
os.makedirs(si_dir)
|
os.makedirs(si_dir)
|
||||||
new_sharefile = os.path.join(si_dir, str(sharenum))
|
new_sharefile = os.path.join(si_dir, str(sharenum))
|
||||||
shutil.copy(sharefile, new_sharefile)
|
shutil.copy(sharefile, new_sharefile)
|
||||||
self.shares = self.find_shares(self.uri)
|
self.shares = self.find_uri_shares(self.uri)
|
||||||
# Make sure that the storage server has the share.
|
# Make sure that the storage server has the share.
|
||||||
self.failUnless((sharenum, ss.original.my_nodeid, new_sharefile)
|
self.failUnless((sharenum, ss.original.my_nodeid, new_sharefile)
|
||||||
in self.shares)
|
in self.shares)
|
||||||
@ -95,14 +95,14 @@ class HungServerDownloadTest(GridTestMixin, ShouldFailMixin, unittest.TestCase):
|
|||||||
d = nm.create_mutable_file(mutable_plaintext)
|
d = nm.create_mutable_file(mutable_plaintext)
|
||||||
def _uploaded_mutable(node):
|
def _uploaded_mutable(node):
|
||||||
self.uri = node.get_uri()
|
self.uri = node.get_uri()
|
||||||
self.shares = self.find_shares(self.uri)
|
self.shares = self.find_uri_shares(self.uri)
|
||||||
d.addCallback(_uploaded_mutable)
|
d.addCallback(_uploaded_mutable)
|
||||||
else:
|
else:
|
||||||
data = upload.Data(immutable_plaintext, convergence="")
|
data = upload.Data(immutable_plaintext, convergence="")
|
||||||
d = self.c0.upload(data)
|
d = self.c0.upload(data)
|
||||||
def _uploaded_immutable(upload_res):
|
def _uploaded_immutable(upload_res):
|
||||||
self.uri = upload_res.uri
|
self.uri = upload_res.uri
|
||||||
self.shares = self.find_shares(self.uri)
|
self.shares = self.find_uri_shares(self.uri)
|
||||||
d.addCallback(_uploaded_immutable)
|
d.addCallback(_uploaded_immutable)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class Test(common.ShareManglingMixin, unittest.TestCase):
|
|||||||
# replace_shares, and asserting that the new set of shares equals the
|
# replace_shares, and asserting that the new set of shares equals the
|
||||||
# old is more to test this test code than to test the Tahoe code...
|
# old is more to test this test code than to test the Tahoe code...
|
||||||
d = defer.succeed(None)
|
d = defer.succeed(None)
|
||||||
d.addCallback(self.find_shares)
|
d.addCallback(self.find_all_shares)
|
||||||
stash = [None]
|
stash = [None]
|
||||||
def _stash_it(res):
|
def _stash_it(res):
|
||||||
stash[0] = res
|
stash[0] = res
|
||||||
|
@ -87,7 +87,7 @@ class Verifier(GridTestMixin, unittest.TestCase, RepairTestMixin):
|
|||||||
d.addCallback(_check)
|
d.addCallback(_check)
|
||||||
|
|
||||||
def _remove_all(ignored):
|
def _remove_all(ignored):
|
||||||
for sh in self.find_shares(self.uri):
|
for sh in self.find_uri_shares(self.uri):
|
||||||
self.delete_share(sh)
|
self.delete_share(sh)
|
||||||
d.addCallback(_remove_all)
|
d.addCallback(_remove_all)
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ class Verifier(GridTestMixin, unittest.TestCase, RepairTestMixin):
|
|||||||
def _grab_sh0(res):
|
def _grab_sh0(res):
|
||||||
self.sh0_file = [sharefile
|
self.sh0_file = [sharefile
|
||||||
for (shnum, serverid, sharefile)
|
for (shnum, serverid, sharefile)
|
||||||
in self.find_shares(self.uri)
|
in self.find_uri_shares(self.uri)
|
||||||
if shnum == 0][0]
|
if shnum == 0][0]
|
||||||
self.sh0_orig = open(self.sh0_file, "rb").read()
|
self.sh0_orig = open(self.sh0_file, "rb").read()
|
||||||
d.addCallback(_grab_sh0)
|
d.addCallback(_grab_sh0)
|
||||||
@ -467,11 +467,11 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
self.set_up_grid(num_clients=2)
|
self.set_up_grid(num_clients=2)
|
||||||
d = self.upload_and_stash()
|
d = self.upload_and_stash()
|
||||||
|
|
||||||
d.addCallback(lambda ignored: self.find_shares(self.uri))
|
d.addCallback(lambda ignored: self.find_uri_shares(self.uri))
|
||||||
def _stash_shares(oldshares):
|
def _stash_shares(oldshares):
|
||||||
self.oldshares = oldshares
|
self.oldshares = oldshares
|
||||||
d.addCallback(_stash_shares)
|
d.addCallback(_stash_shares)
|
||||||
d.addCallback(lambda ignored: self.find_shares(self.uri))
|
d.addCallback(lambda ignored: self.find_uri_shares(self.uri))
|
||||||
def _compare(newshares):
|
def _compare(newshares):
|
||||||
self.failUnlessEqual(newshares, self.oldshares)
|
self.failUnlessEqual(newshares, self.oldshares)
|
||||||
d.addCallback(_compare)
|
d.addCallback(_compare)
|
||||||
@ -482,7 +482,7 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
for sh in self.oldshares[1:8]:
|
for sh in self.oldshares[1:8]:
|
||||||
self.delete_share(sh)
|
self.delete_share(sh)
|
||||||
d.addCallback(_delete_8)
|
d.addCallback(_delete_8)
|
||||||
d.addCallback(lambda ignored: self.find_shares(self.uri))
|
d.addCallback(lambda ignored: self.find_uri_shares(self.uri))
|
||||||
d.addCallback(lambda shares: self.failUnlessEqual(len(shares), 2))
|
d.addCallback(lambda shares: self.failUnlessEqual(len(shares), 2))
|
||||||
|
|
||||||
d.addCallback(lambda ignored:
|
d.addCallback(lambda ignored:
|
||||||
@ -499,7 +499,7 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
# test share corruption
|
# test share corruption
|
||||||
def _test_corrupt(ignored):
|
def _test_corrupt(ignored):
|
||||||
olddata = {}
|
olddata = {}
|
||||||
shares = self.find_shares(self.uri)
|
shares = self.find_uri_shares(self.uri)
|
||||||
for (shnum, serverid, sharefile) in shares:
|
for (shnum, serverid, sharefile) in shares:
|
||||||
olddata[ (shnum, serverid) ] = open(sharefile, "rb").read()
|
olddata[ (shnum, serverid) ] = open(sharefile, "rb").read()
|
||||||
for sh in shares:
|
for sh in shares:
|
||||||
@ -510,10 +510,10 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
d.addCallback(_test_corrupt)
|
d.addCallback(_test_corrupt)
|
||||||
|
|
||||||
def _remove_all(ignored):
|
def _remove_all(ignored):
|
||||||
for sh in self.find_shares(self.uri):
|
for sh in self.find_uri_shares(self.uri):
|
||||||
self.delete_share(sh)
|
self.delete_share(sh)
|
||||||
d.addCallback(_remove_all)
|
d.addCallback(_remove_all)
|
||||||
d.addCallback(lambda ignored: self.find_shares(self.uri))
|
d.addCallback(lambda ignored: self.find_uri_shares(self.uri))
|
||||||
d.addCallback(lambda shares: self.failUnlessEqual(shares, []))
|
d.addCallback(lambda shares: self.failUnlessEqual(shares, []))
|
||||||
|
|
||||||
return d
|
return d
|
||||||
@ -544,7 +544,7 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
|
|
||||||
# Now we inspect the filesystem to make sure that it has 10
|
# Now we inspect the filesystem to make sure that it has 10
|
||||||
# shares.
|
# shares.
|
||||||
shares = self.find_shares(self.uri)
|
shares = self.find_uri_shares(self.uri)
|
||||||
self.failIf(len(shares) < 10)
|
self.failIf(len(shares) < 10)
|
||||||
d.addCallback(_check_results)
|
d.addCallback(_check_results)
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
self.failUnless(post.is_healthy(), post.data)
|
self.failUnless(post.is_healthy(), post.data)
|
||||||
|
|
||||||
# Make sure we really have 10 shares.
|
# Make sure we really have 10 shares.
|
||||||
shares = self.find_shares(self.uri)
|
shares = self.find_uri_shares(self.uri)
|
||||||
self.failIf(len(shares) < 10)
|
self.failIf(len(shares) < 10)
|
||||||
d.addCallback(_check_results)
|
d.addCallback(_check_results)
|
||||||
|
|
||||||
@ -650,7 +650,7 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
def OFF_test_repair_from_corruption_of_1(self):
|
def OFF_test_repair_from_corruption_of_1(self):
|
||||||
d = defer.succeed(None)
|
d = defer.succeed(None)
|
||||||
|
|
||||||
d.addCallback(self.find_shares)
|
d.addCallback(self.find_all_shares)
|
||||||
stash = [None]
|
stash = [None]
|
||||||
def _stash_it(res):
|
def _stash_it(res):
|
||||||
stash[0] = res
|
stash[0] = res
|
||||||
@ -685,7 +685,7 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
|
|||||||
|
|
||||||
# Now we inspect the filesystem to make sure that it has 10
|
# Now we inspect the filesystem to make sure that it has 10
|
||||||
# shares.
|
# shares.
|
||||||
shares = self.find_shares()
|
shares = self.find_all_shares()
|
||||||
self.failIf(len(shares) < 10)
|
self.failIf(len(shares) < 10)
|
||||||
|
|
||||||
# Now we assert that the verifier reports the file as healthy.
|
# Now we assert that the verifier reports the file as healthy.
|
||||||
|
@ -383,7 +383,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
|
|||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _find_shares(self, basedir):
|
def _find_all_shares(self, basedir):
|
||||||
shares = []
|
shares = []
|
||||||
for (dirpath, dirnames, filenames) in os.walk(basedir):
|
for (dirpath, dirnames, filenames) in os.walk(basedir):
|
||||||
if "storage" not in dirpath:
|
if "storage" not in dirpath:
|
||||||
@ -475,7 +475,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
|
|||||||
def _test_debug(res):
|
def _test_debug(res):
|
||||||
# find a share. It is important to run this while there is only
|
# find a share. It is important to run this while there is only
|
||||||
# one slot in the grid.
|
# one slot in the grid.
|
||||||
shares = self._find_shares(self.basedir)
|
shares = self._find_all_shares(self.basedir)
|
||||||
(client_num, storage_index, filename, shnum) = shares[0]
|
(client_num, storage_index, filename, shnum) = shares[0]
|
||||||
log.msg("test_system.SystemTest.test_mutable._test_debug using %s"
|
log.msg("test_system.SystemTest.test_mutable._test_debug using %s"
|
||||||
% filename)
|
% filename)
|
||||||
@ -578,7 +578,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
|
|||||||
def _corrupt_shares(res):
|
def _corrupt_shares(res):
|
||||||
# run around and flip bits in all but k of the shares, to test
|
# run around and flip bits in all but k of the shares, to test
|
||||||
# the hash checks
|
# the hash checks
|
||||||
shares = self._find_shares(self.basedir)
|
shares = self._find_all_shares(self.basedir)
|
||||||
## sort by share number
|
## sort by share number
|
||||||
#shares.sort( lambda a,b: cmp(a[3], b[3]) )
|
#shares.sort( lambda a,b: cmp(a[3], b[3]) )
|
||||||
where = dict([ (shnum, filename)
|
where = dict([ (shnum, filename)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os, shutil
|
import os, shutil
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
@ -684,8 +686,66 @@ class StorageIndex(unittest.TestCase):
|
|||||||
d.addCallback(_done)
|
d.addCallback(_done)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
# copied from python docs because itertools.combinations was added in
|
||||||
|
# python 2.6 and we support >= 2.4.
|
||||||
|
def combinations(iterable, r):
|
||||||
|
# combinations('ABCD', 2) --> AB AC AD BC BD CD
|
||||||
|
# combinations(range(4), 3) --> 012 013 023 123
|
||||||
|
pool = tuple(iterable)
|
||||||
|
n = len(pool)
|
||||||
|
if r > n:
|
||||||
|
return
|
||||||
|
indices = range(r)
|
||||||
|
yield tuple(pool[i] for i in indices)
|
||||||
|
while True:
|
||||||
|
for i in reversed(range(r)):
|
||||||
|
if indices[i] != i + n - r:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
indices[i] += 1
|
||||||
|
for j in range(i+1, r):
|
||||||
|
indices[j] = indices[j-1] + 1
|
||||||
|
yield tuple(pool[i] for i in indices)
|
||||||
|
|
||||||
|
def is_happy_enough(servertoshnums, h, k):
|
||||||
|
""" I calculate whether servertoshnums achieves happiness level h. I do this with a naïve "brute force search" approach. (See src/allmydata/util/happinessutil.py for a better algorithm.) """
|
||||||
|
if len(servertoshnums) < h:
|
||||||
|
return False
|
||||||
|
# print "servertoshnums: ", servertoshnums, h, k
|
||||||
|
for happysetcombo in combinations(servertoshnums.iterkeys(), h):
|
||||||
|
# print "happysetcombo: ", happysetcombo
|
||||||
|
for subsetcombo in combinations(happysetcombo, k):
|
||||||
|
shnums = reduce(set.union, [ servertoshnums[s] for s in subsetcombo ])
|
||||||
|
# print "subsetcombo: ", subsetcombo, ", shnums: ", shnums
|
||||||
|
if len(shnums) < k:
|
||||||
|
# print "NOT HAAPP{Y", shnums, k
|
||||||
|
return False
|
||||||
|
# print "HAAPP{Y"
|
||||||
|
return True
|
||||||
|
|
||||||
class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
||||||
ShouldFailMixin):
|
ShouldFailMixin):
|
||||||
|
def find_all_shares(self, unused=None):
|
||||||
|
"""Locate shares on disk. Returns a dict that maps
|
||||||
|
server to set of sharenums.
|
||||||
|
"""
|
||||||
|
assert self.g, "I tried to find a grid at self.g, but failed"
|
||||||
|
servertoshnums = {} # k: server, v: set(shnum)
|
||||||
|
|
||||||
|
for i, c in self.g.servers_by_number.iteritems():
|
||||||
|
for (dirp, dirns, fns) in os.walk(c.sharedir):
|
||||||
|
for fn in fns:
|
||||||
|
try:
|
||||||
|
sharenum = int(fn)
|
||||||
|
except TypeError:
|
||||||
|
# Whoops, I guess that's not a share file then.
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
servertoshnums.setdefault(i, set()).add(sharenum)
|
||||||
|
|
||||||
|
return servertoshnums
|
||||||
|
|
||||||
def _do_upload_with_broken_servers(self, servers_to_break):
|
def _do_upload_with_broken_servers(self, servers_to_break):
|
||||||
"""
|
"""
|
||||||
I act like a normal upload, but before I send the results of
|
I act like a normal upload, but before I send the results of
|
||||||
@ -729,6 +789,11 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_have_shareholders)
|
d.addCallback(_have_shareholders)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def _has_happy_share_distribution(self):
|
||||||
|
servertoshnums = self.find_all_shares()
|
||||||
|
k = self.g.clients[0].DEFAULT_ENCODING_PARAMETERS['k']
|
||||||
|
h = self.g.clients[0].DEFAULT_ENCODING_PARAMETERS['happy']
|
||||||
|
return is_happy_enough(servertoshnums, h, k)
|
||||||
|
|
||||||
def _add_server(self, server_number, readonly=False):
|
def _add_server(self, server_number, readonly=False):
|
||||||
assert self.g, "I tried to find a grid at self.g, but failed"
|
assert self.g, "I tried to find a grid at self.g, but failed"
|
||||||
@ -760,7 +825,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
str(share_number))
|
str(share_number))
|
||||||
if old_share_location != new_share_location:
|
if old_share_location != new_share_location:
|
||||||
shutil.copy(old_share_location, new_share_location)
|
shutil.copy(old_share_location, new_share_location)
|
||||||
shares = self.find_shares(self.uri)
|
shares = self.find_uri_shares(self.uri)
|
||||||
# Make sure that the storage server has the share.
|
# Make sure that the storage server has the share.
|
||||||
self.failUnless((share_number, ss.my_nodeid, new_share_location)
|
self.failUnless((share_number, ss.my_nodeid, new_share_location)
|
||||||
in shares)
|
in shares)
|
||||||
@ -790,7 +855,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
self.uri = ur.uri
|
self.uri = ur.uri
|
||||||
d.addCallback(_store_uri)
|
d.addCallback(_store_uri)
|
||||||
d.addCallback(lambda ign:
|
d.addCallback(lambda ign:
|
||||||
self.find_shares(self.uri))
|
self.find_uri_shares(self.uri))
|
||||||
def _store_shares(shares):
|
def _store_shares(shares):
|
||||||
self.shares = shares
|
self.shares = shares
|
||||||
d.addCallback(_store_shares)
|
d.addCallback(_store_shares)
|
||||||
@ -876,6 +941,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(lambda ign: self._add_server(4, False))
|
d.addCallback(lambda ign: self._add_server(4, False))
|
||||||
# and this time the upload ought to succeed
|
# and this time the upload ought to succeed
|
||||||
d.addCallback(lambda ign: c.upload(DATA))
|
d.addCallback(lambda ign: c.upload(DATA))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
@ -1012,6 +1079,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_reset_encoding_parameters)
|
d.addCallback(_reset_encoding_parameters)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
|
|
||||||
|
|
||||||
# This scenario is basically comment:53, but changed so that the
|
# This scenario is basically comment:53, but changed so that the
|
||||||
@ -1050,6 +1119,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_reset_encoding_parameters)
|
d.addCallback(_reset_encoding_parameters)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
|
|
||||||
|
|
||||||
# Try the same thing, but with empty servers after the first one
|
# Try the same thing, but with empty servers after the first one
|
||||||
@ -1081,6 +1152,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
# servers of happiness were pushed.
|
# servers of happiness were pushed.
|
||||||
d.addCallback(lambda results:
|
d.addCallback(lambda results:
|
||||||
self.failUnlessEqual(results.pushed_shares, 3))
|
self.failUnlessEqual(results.pushed_shares, 3))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_problem_layout_ticket1124(self):
|
def test_problem_layout_ticket1124(self):
|
||||||
@ -1106,6 +1179,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_setup)
|
d.addCallback(_setup)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
test_problem_layout_ticket1124.todo = "Fix this after 1.7.1 release."
|
test_problem_layout_ticket1124.todo = "Fix this after 1.7.1 release."
|
||||||
|
|
||||||
@ -1143,6 +1218,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_reset_encoding_parameters)
|
d.addCallback(_reset_encoding_parameters)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
@ -1180,6 +1257,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_reset_encoding_parameters)
|
d.addCallback(_reset_encoding_parameters)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
@ -1489,6 +1568,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_prepare_client)
|
d.addCallback(_prepare_client)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
@ -1783,6 +1864,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_setup)
|
d.addCallback(_setup)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
test_problem_layout_comment_187.todo = "this isn't fixed yet"
|
test_problem_layout_comment_187.todo = "this isn't fixed yet"
|
||||||
|
|
||||||
@ -1816,6 +1899,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_setup)
|
d.addCallback(_setup)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_upload_succeeds_with_some_homeless_shares(self):
|
def test_upload_succeeds_with_some_homeless_shares(self):
|
||||||
@ -1852,6 +1937,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_server_setup)
|
d.addCallback(_server_setup)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
@ -1879,6 +1966,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
d.addCallback(_server_setup)
|
d.addCallback(_server_setup)
|
||||||
d.addCallback(lambda client:
|
d.addCallback(lambda client:
|
||||||
client.upload(upload.Data("data" * 10000, convergence="")))
|
client.upload(upload.Data("data" * 10000, convergence="")))
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.failUnless(self._has_happy_share_distribution()))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@ -3195,14 +3195,14 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
d.addCallback(_compute_fileurls)
|
d.addCallback(_compute_fileurls)
|
||||||
|
|
||||||
def _clobber_shares(ignored):
|
def _clobber_shares(ignored):
|
||||||
good_shares = self.find_shares(self.uris["good"])
|
good_shares = self.find_uri_shares(self.uris["good"])
|
||||||
self.failUnlessReallyEqual(len(good_shares), 10)
|
self.failUnlessReallyEqual(len(good_shares), 10)
|
||||||
sick_shares = self.find_shares(self.uris["sick"])
|
sick_shares = self.find_uri_shares(self.uris["sick"])
|
||||||
os.unlink(sick_shares[0][2])
|
os.unlink(sick_shares[0][2])
|
||||||
dead_shares = self.find_shares(self.uris["dead"])
|
dead_shares = self.find_uri_shares(self.uris["dead"])
|
||||||
for i in range(1, 10):
|
for i in range(1, 10):
|
||||||
os.unlink(dead_shares[i][2])
|
os.unlink(dead_shares[i][2])
|
||||||
c_shares = self.find_shares(self.uris["corrupt"])
|
c_shares = self.find_uri_shares(self.uris["corrupt"])
|
||||||
cso = CorruptShareOptions()
|
cso = CorruptShareOptions()
|
||||||
cso.stdout = StringIO()
|
cso.stdout = StringIO()
|
||||||
cso.parseOptions([c_shares[0][2]])
|
cso.parseOptions([c_shares[0][2]])
|
||||||
@ -3336,14 +3336,14 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
d.addCallback(_compute_fileurls)
|
d.addCallback(_compute_fileurls)
|
||||||
|
|
||||||
def _clobber_shares(ignored):
|
def _clobber_shares(ignored):
|
||||||
good_shares = self.find_shares(self.uris["good"])
|
good_shares = self.find_uri_shares(self.uris["good"])
|
||||||
self.failUnlessReallyEqual(len(good_shares), 10)
|
self.failUnlessReallyEqual(len(good_shares), 10)
|
||||||
sick_shares = self.find_shares(self.uris["sick"])
|
sick_shares = self.find_uri_shares(self.uris["sick"])
|
||||||
os.unlink(sick_shares[0][2])
|
os.unlink(sick_shares[0][2])
|
||||||
dead_shares = self.find_shares(self.uris["dead"])
|
dead_shares = self.find_uri_shares(self.uris["dead"])
|
||||||
for i in range(1, 10):
|
for i in range(1, 10):
|
||||||
os.unlink(dead_shares[i][2])
|
os.unlink(dead_shares[i][2])
|
||||||
c_shares = self.find_shares(self.uris["corrupt"])
|
c_shares = self.find_uri_shares(self.uris["corrupt"])
|
||||||
cso = CorruptShareOptions()
|
cso = CorruptShareOptions()
|
||||||
cso.stdout = StringIO()
|
cso.stdout = StringIO()
|
||||||
cso.parseOptions([c_shares[0][2]])
|
cso.parseOptions([c_shares[0][2]])
|
||||||
@ -3404,7 +3404,7 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
d.addCallback(_compute_fileurls)
|
d.addCallback(_compute_fileurls)
|
||||||
|
|
||||||
def _clobber_shares(ignored):
|
def _clobber_shares(ignored):
|
||||||
sick_shares = self.find_shares(self.uris["sick"])
|
sick_shares = self.find_uri_shares(self.uris["sick"])
|
||||||
os.unlink(sick_shares[0][2])
|
os.unlink(sick_shares[0][2])
|
||||||
d.addCallback(_clobber_shares)
|
d.addCallback(_clobber_shares)
|
||||||
|
|
||||||
@ -3894,15 +3894,15 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
#d.addCallback(_stash_uri, "corrupt")
|
#d.addCallback(_stash_uri, "corrupt")
|
||||||
|
|
||||||
def _clobber_shares(ignored):
|
def _clobber_shares(ignored):
|
||||||
good_shares = self.find_shares(self.uris["good"])
|
good_shares = self.find_uri_shares(self.uris["good"])
|
||||||
self.failUnlessReallyEqual(len(good_shares), 10)
|
self.failUnlessReallyEqual(len(good_shares), 10)
|
||||||
sick_shares = self.find_shares(self.uris["sick"])
|
sick_shares = self.find_uri_shares(self.uris["sick"])
|
||||||
os.unlink(sick_shares[0][2])
|
os.unlink(sick_shares[0][2])
|
||||||
#dead_shares = self.find_shares(self.uris["dead"])
|
#dead_shares = self.find_uri_shares(self.uris["dead"])
|
||||||
#for i in range(1, 10):
|
#for i in range(1, 10):
|
||||||
# os.unlink(dead_shares[i][2])
|
# os.unlink(dead_shares[i][2])
|
||||||
|
|
||||||
#c_shares = self.find_shares(self.uris["corrupt"])
|
#c_shares = self.find_uri_shares(self.uris["corrupt"])
|
||||||
#cso = CorruptShareOptions()
|
#cso = CorruptShareOptions()
|
||||||
#cso.stdout = StringIO()
|
#cso.stdout = StringIO()
|
||||||
#cso.parseOptions([c_shares[0][2]])
|
#cso.parseOptions([c_shares[0][2]])
|
||||||
@ -3958,7 +3958,7 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
|
|
||||||
def _count_leases(self, ignored, which):
|
def _count_leases(self, ignored, which):
|
||||||
u = self.uris[which]
|
u = self.uris[which]
|
||||||
shares = self.find_shares(u)
|
shares = self.find_uri_shares(u)
|
||||||
lease_counts = []
|
lease_counts = []
|
||||||
for shnum, serverid, fn in shares:
|
for shnum, serverid, fn in shares:
|
||||||
sf = get_share_file(fn)
|
sf = get_share_file(fn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user