Remove ugly shadowing of Client.DEFAULT_ENCODING_PARAMETERS. fixes #1847

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2014-04-21 22:40:28 +01:00
parent 77b536c7a4
commit 77767e9e12
7 changed files with 54 additions and 52 deletions

View File

@ -130,7 +130,7 @@ class Client(node.Node, pollmixin.PollMixin):
node.Node.__init__(self, basedir)
self.started_timestamp = time.time()
self.logSource="Client"
self.DEFAULT_ENCODING_PARAMETERS = self.DEFAULT_ENCODING_PARAMETERS.copy()
self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
self.init_introducer_client()
self.init_stats_provider()
self.init_secrets()
@ -322,7 +322,7 @@ class Client(node.Node, pollmixin.PollMixin):
if helper_furl in ("None", ""):
helper_furl = None
DEP = self.DEFAULT_ENCODING_PARAMETERS
DEP = self.encoding_params
DEP["k"] = int(self.get_config("client", "shares.needed", DEP["k"]))
DEP["n"] = int(self.get_config("client", "shares.total", DEP["n"]))
DEP["happy"] = int(self.get_config("client", "shares.happy", DEP["happy"]))
@ -504,7 +504,7 @@ class Client(node.Node, pollmixin.PollMixin):
reactor.stop()
def get_encoding_parameters(self):
return self.DEFAULT_ENCODING_PARAMETERS
return self.encoding_params
def connected_to_introducer(self):
if self.introducer_client:

View File

@ -364,9 +364,9 @@ class BalancingAct(GridTestMixin, unittest.TestCase):
self.basedir = "checker/BalancingAct/1115"
self.set_up_grid(num_servers=1)
c0 = self.g.clients[0]
c0.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
c0.DEFAULT_ENCODING_PARAMETERS['n'] = 4
c0.DEFAULT_ENCODING_PARAMETERS['k'] = 3
c0.encoding_params['happy'] = 1
c0.encoding_params['n'] = 4
c0.encoding_params['k'] = 3
DATA = "data" * 100
d = c0.upload(Data(DATA, convergence=""))
@ -423,7 +423,7 @@ class AddLease(GridTestMixin, unittest.TestCase):
self.basedir = "checker/AddLease/875"
self.set_up_grid(num_servers=1)
c0 = self.g.clients[0]
c0.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
c0.encoding_params['happy'] = 1
self.uris = {}
DATA = "data" * 100
d = c0.upload(Data(DATA, convergence=""))
@ -511,11 +511,11 @@ class TooParallel(GridTestMixin, unittest.TestCase):
def _start(ign):
self.set_up_grid(num_servers=4)
self.c0 = self.g.clients[0]
self.c0.DEFAULT_ENCODING_PARAMETERS = { "k": 1,
"happy": 4,
"n": 4,
"max_segment_size": 5,
}
self.c0.encoding_params = { "k": 1,
"happy": 4,
"n": 4,
"max_segment_size": 5,
}
self.uris = {}
DATA = "data" * 100 # 400/5 = 80 blocks
return self.c0.upload(Data(DATA, convergence=""))

View File

@ -140,10 +140,10 @@ class Test(GridTestMixin, unittest.TestCase, common.ShouldFailMixin):
c1 = self.g.clients[1]
# We need multiple segments to test crypttext hash trees that are
# non-trivial (i.e. they have more than just one hash in them).
c1.DEFAULT_ENCODING_PARAMETERS['max_segment_size'] = 12
c1.encoding_params['max_segment_size'] = 12
# Tests that need to test servers of happiness using this should
# set their own value for happy -- the default (7) breaks stuff.
c1.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
c1.encoding_params['happy'] = 1
d = c1.upload(Data(TEST_DATA, convergence=""))
def _after_upload(ur):
self.uri = ur.get_uri()

View File

@ -59,7 +59,7 @@ class RepairTestMixin:
def upload_and_stash(self):
c0 = self.g.clients[0]
c1 = self.g.clients[1]
c0.DEFAULT_ENCODING_PARAMETERS['max_segment_size'] = 12
c0.encoding_params['max_segment_size'] = 12
d = c0.upload(upload.Data(common.TEST_DATA, convergence=""))
def _stash_uri(ur):
self.uri = ur.get_uri()
@ -678,8 +678,8 @@ class Repairer(GridTestMixin, unittest.TestCase, RepairTestMixin,
self.set_up_grid()
c0 = self.g.clients[0]
DATA = "a"*135
c0.DEFAULT_ENCODING_PARAMETERS['k'] = 22
c0.DEFAULT_ENCODING_PARAMETERS['n'] = 66
c0.encoding_params['k'] = 22
c0.encoding_params['n'] = 66
d = c0.upload(upload.Data(DATA, convergence=""))
def _then(ur):
self.uri = ur.get_uri()

View File

@ -102,7 +102,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
d = self.set_up_nodes()
def _check_connections(res):
for c in self.clients:
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 5
c.encoding_params['happy'] = 5
all_peerids = c.get_storage_broker().get_all_serverids()
self.failUnlessEqual(len(all_peerids), self.numclients)
sb = c.storage_broker
@ -214,7 +214,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
add_to_sparent=True))
def _added(extra_node):
self.extra_node = extra_node
self.extra_node.DEFAULT_ENCODING_PARAMETERS['happy'] = 5
self.extra_node.encoding_params['happy'] = 5
d.addCallback(_added)
def _has_helper():
@ -724,7 +724,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
d = self.set_up_nodes(use_stats_gatherer=True)
def _new_happy_semantics(ign):
for c in self.clients:
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
c.encoding_params['happy'] = 1
d.addCallback(_new_happy_semantics)
d.addCallback(self._test_introweb)
d.addCallback(self.log, "starting publish")
@ -1171,7 +1171,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
def _new_happy_semantics(ign):
for c in self.clients:
# these get reset somewhere? Whatever.
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
c.encoding_params['happy'] = 1
d.addCallback(_new_happy_semantics)
d.addCallback(lambda res: self.PUT(public + "/subdir3/big.txt",
"big" * 500000)) # 1.5MB
@ -1764,7 +1764,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
d = self.set_up_nodes()
def _new_happy_semantics(ign):
for c in self.clients:
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
c.encoding_params['happy'] = 1
d.addCallback(_new_happy_semantics)
def _run_in_subprocess(ignored, verb, *args, **kwargs):

View File

@ -98,7 +98,7 @@ class SetDEPMixin:
"n": n,
"max_segment_size": max_segsize,
}
self.node.DEFAULT_ENCODING_PARAMETERS = p
self.node.encoding_params = p
class FakeStorageServer:
def __init__(self, mode):
@ -190,8 +190,10 @@ class FakeClient:
"n": 100,
"max_segment_size": 1*MiB,
}
def __init__(self, mode="good", num_servers=50):
self.num_servers = num_servers
self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
if type(mode) is str:
mode = dict([i,mode] for i in range(num_servers))
servers = [ ("%20d"%fakeid, FakeStorageServer(mode[fakeid]))
@ -206,7 +208,7 @@ class FakeClient:
def log(self, *args, **kwargs):
pass
def get_encoding_parameters(self):
return self.DEFAULT_ENCODING_PARAMETERS
return self.encoding_params
def get_storage_broker(self):
return self.storage_broker
_secret_holder = client.SecretHolder("lease secret", "convergence secret")
@ -497,7 +499,7 @@ class ServerSelection(unittest.TestCase):
"n": n,
"max_segment_size": max_segsize,
}
self.node.DEFAULT_ENCODING_PARAMETERS = p
self.node.encoding_params = p
def test_one_each(self):
# if we have 50 shares, and there are 50 servers, and they all accept
@ -811,8 +813,8 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
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']
k = self.g.clients[0].encoding_params['k']
h = self.g.clients[0].encoding_params['happy']
return is_happy_enough(servertoshnums, h, k)
def _add_server(self, server_number, readonly=False):
@ -864,10 +866,10 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
"""
self._setup_grid()
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 1
client.encoding_params['happy'] = 1
if "n" in kwargs and "k" in kwargs:
client.DEFAULT_ENCODING_PARAMETERS['k'] = kwargs['k']
client.DEFAULT_ENCODING_PARAMETERS['n'] = kwargs['n']
client.encoding_params['k'] = kwargs['k']
client.encoding_params['n'] = kwargs['n']
data = upload.Data("data" * 10000, convergence="")
self.data = data
d = client.upload(data)
@ -948,7 +950,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# work with 5, as long as the original 4 are not stuck in the open
# BucketWriter state (open() but not
parms = {"k":2, "happy":5, "n":5, "max_segment_size": 1*MiB}
c.DEFAULT_ENCODING_PARAMETERS = parms
c.encoding_params = parms
d = self.shouldFail(UploadUnhappinessError, "test_aborted_shares",
"shares could be placed on only 4 "
"server(s) such that any 2 of them have enough "
@ -1006,7 +1008,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# Set happy = 4 in the client.
def _prepare():
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
client.encoding_params['happy'] = 4
return client
d.addCallback(lambda ign:
_prepare())
@ -1043,7 +1045,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
readonly=True))
def _prepare2():
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
client.encoding_params['happy'] = 4
return client
d.addCallback(lambda ign:
_prepare2())
@ -1092,7 +1094,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# Ideally, a reupload of our original data should work.
def _reset_encoding_parameters(ign, happy=4):
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = happy
client.encoding_params['happy'] = happy
return client
d.addCallback(_reset_encoding_parameters)
d.addCallback(lambda client:
@ -1191,7 +1193,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# Copy shares
self._copy_share_to_server(3, 1)
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
client.encoding_params['happy'] = 4
return client
d.addCallback(_setup)
@ -1231,7 +1233,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
readonly=True))
def _reset_encoding_parameters(ign, happy=4):
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = happy
client.encoding_params['happy'] = happy
return client
d.addCallback(_reset_encoding_parameters)
d.addCallback(lambda client:
@ -1270,7 +1272,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self.g.remove_server(self.g.servers_by_number[0].my_nodeid))
def _reset_encoding_parameters(ign, happy=4):
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = happy
client.encoding_params['happy'] = happy
return client
d.addCallback(_reset_encoding_parameters)
d.addCallback(lambda client:
@ -1565,7 +1567,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self.g.remove_server(self.g.servers_by_number[0].my_nodeid))
def _prepare_client(ign):
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
client.encoding_params['happy'] = 4
return client
d.addCallback(_prepare_client)
d.addCallback(lambda client:
@ -1590,7 +1592,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# counting in the exception message. The same progress message
# is also used when the upload is successful, but in that case it
# only gets written to a log, so we can't see what it says.
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 45
c.encoding_params['happy'] = 45
return c
d.addCallback(_setup)
d.addCallback(lambda c:
@ -1613,7 +1615,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self._add_server(server_number=12, readonly=True)
self.g.remove_server(self.g.servers_by_number[0].my_nodeid)
c = self.g.clients[0]
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 45
c.encoding_params['happy'] = 45
return c
d.addCallback(_then)
d.addCallback(lambda c:
@ -1643,7 +1645,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self.g.remove_server(self.g.servers_by_number[0].my_nodeid)
# Make happiness unsatisfiable
c = self.g.clients[0]
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 45
c.encoding_params['happy'] = 45
return c
d.addCallback(_next)
d.addCallback(lambda c:
@ -1662,9 +1664,9 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self._add_server(server_number=i, readonly=True)
self.g.remove_server(self.g.servers_by_number[0].my_nodeid)
c = self.g.clients[0]
c.DEFAULT_ENCODING_PARAMETERS['k'] = 2
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
c.DEFAULT_ENCODING_PARAMETERS['n'] = 4
c.encoding_params['k'] = 2
c.encoding_params['happy'] = 4
c.encoding_params['n'] = 4
return c
d.addCallback(_then)
d.addCallback(lambda client:
@ -1700,7 +1702,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self.g.remove_server(self.g.servers_by_number[0].my_nodeid))
def _reset_encoding_parameters(ign, happy=4):
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = happy
client.encoding_params['happy'] = happy
return client
d.addCallback(_reset_encoding_parameters)
d.addCallback(lambda client:
@ -1856,7 +1858,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# Remove server 0
self.g.remove_server(self.g.servers_by_number[0].my_nodeid)
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 3
client.encoding_params['happy'] = 3
return client
d.addCallback(_setup)
@ -1891,7 +1893,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# create an empty storedir to replace the one we just removed
os.mkdir(storedir)
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
client.encoding_params['happy'] = 4
return client
d.addCallback(_setup)
@ -1932,7 +1934,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# create an empty storedir to replace the one we just removed
os.mkdir(storedir)
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
client.encoding_params['happy'] = 4
return client
d.addCallback(_setup)
@ -1972,7 +1974,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self.g.remove_server(self.g.servers_by_number[0].my_nodeid)
# Set the client appropriately
c = self.g.clients[0]
c.DEFAULT_ENCODING_PARAMETERS['happy'] = 4
c.encoding_params['happy'] = 4
return c
d.addCallback(_server_setup)
d.addCallback(lambda client:
@ -2022,7 +2024,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
# the current grid. This will fail, but should not take up any
# space on the storage servers after it fails.
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 7
client.encoding_params['happy'] = 7
d = defer.succeed(None)
d.addCallback(lambda ignored:
self.shouldFail(UploadUnhappinessError,
@ -2049,7 +2051,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
self.set_up_grid(num_servers=4)
client = self.g.clients[0]
client.DEFAULT_ENCODING_PARAMETERS['happy'] = 7
client.encoding_params['happy'] = 7
d = defer.succeed(None)
d.addCallback(lambda ignored:

View File

@ -5501,7 +5501,7 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
self.basedir = "web/Grid/exceptions"
self.set_up_grid(num_clients=1, num_servers=2)
c0 = self.g.clients[0]
c0.DEFAULT_ENCODING_PARAMETERS['happy'] = 2
c0.encoding_params['happy'] = 2
self.fileurls = {}
DATA = "data" * 100
d = c0.create_dirnode()