add remaining get_* methods to storage_client.Server, NoNetworkServer, and

MockIServer stubs
This commit is contained in:
Brian Warner 2011-02-26 19:11:32 -07:00
parent 36fabb4f4a
commit 9672b34880
3 changed files with 39 additions and 9 deletions

View File

@ -179,6 +179,7 @@ class NativeStorageServer:
def __init__(self, serverid, ann_d, min_shares=1): def __init__(self, serverid, ann_d, min_shares=1):
self.serverid = serverid self.serverid = serverid
self._tubid = serverid
self.announcement = ann_d self.announcement = ann_d
self.min_shares = min_shares self.min_shares = min_shares
@ -191,10 +192,24 @@ class NativeStorageServer:
self._reconnector = None self._reconnector = None
self._trigger_cb = None self._trigger_cb = None
def __repr__(self):
return "<NativeStorageServer for %s>" % self.name()
def get_serverid(self): def get_serverid(self):
return self.serverid return self._tubid
def get_permutation_seed(self): def get_permutation_seed(self):
return self.serverid return self._tubid
def get_version(self):
if self.rref:
return self.rref.version
return None
def name(self): # keep methodname short
return self.serverid_s
def longname(self):
return idlib.nodeid_b2a(self._tubid)
def get_lease_seed(self):
return self._tubid
def get_foolscap_write_enabler_seed(self):
return self._tubid
def get_nickname(self): def get_nickname(self):
return self.announcement["nickname"].decode("utf-8") return self.announcement["nickname"].decode("utf-8")
@ -215,8 +230,8 @@ class NativeStorageServer:
self._reconnector = tub.connectTo(furl, self._got_connection) self._reconnector = tub.connectTo(furl, self._got_connection)
def _got_connection(self, rref): def _got_connection(self, rref):
lp = log.msg(format="got connection to %(serverid)s, getting versions", lp = log.msg(format="got connection to %(name)s, getting versions",
serverid=self.serverid_s, name=self.name(),
facility="tahoe.storage_broker", umid="coUECQ") facility="tahoe.storage_broker", umid="coUECQ")
if self._trigger_cb: if self._trigger_cb:
eventually(self._trigger_cb) eventually(self._trigger_cb)
@ -224,11 +239,11 @@ class NativeStorageServer:
d = add_version_to_remote_reference(rref, default) d = add_version_to_remote_reference(rref, default)
d.addCallback(self._got_versioned_service, lp) d.addCallback(self._got_versioned_service, lp)
d.addErrback(log.err, format="storageclient._got_connection", d.addErrback(log.err, format="storageclient._got_connection",
serverid=self.serverid_s, umid="Sdq3pg") name=self.name(), umid="Sdq3pg")
def _got_versioned_service(self, rref, lp): def _got_versioned_service(self, rref, lp):
log.msg(format="%(serverid)s provided version info %(version)s", log.msg(format="%(name)s provided version info %(version)s",
serverid=self.serverid_s, version=rref.version, name=self.name(), version=rref.version,
facility="tahoe.storage_broker", umid="SWmJYg", facility="tahoe.storage_broker", umid="SWmJYg",
level=log.NOISY, parent=lp) level=log.NOISY, parent=lp)
@ -241,8 +256,7 @@ class NativeStorageServer:
return self.rref return self.rref
def _lost(self): def _lost(self):
log.msg(format="lost connection to %(serverid)s", log.msg(format="lost connection to %(name)s", name=self.name(),
serverid=self.serverid_s,
facility="tahoe.storage_broker", umid="zbRllw") facility="tahoe.storage_broker", umid="zbRllw")
self.last_loss_time = time.time() self.last_loss_time = time.time()
self.rref = None self.rref = None

View File

@ -121,12 +121,24 @@ class NoNetworkServer:
def __init__(self, serverid, rref): def __init__(self, serverid, rref):
self.serverid = serverid self.serverid = serverid
self.rref = rref self.rref = rref
def __repr__(self):
return "<NoNetworkServer for %s>" % self.name()
def get_serverid(self): def get_serverid(self):
return self.serverid return self.serverid
def get_permutation_seed(self): def get_permutation_seed(self):
return self.serverid return self.serverid
def get_lease_seed(self):
return self.serverid
def name(self):
return idlib.shortnodeid_b2a(self.serverid)
def longname(self):
return idlib.nodeid_b2a(self.serverid)
def get_nickname(self):
return "nickname"
def get_rref(self): def get_rref(self):
return self.rref return self.rref
def get_version(self):
return self.rref.version
class NoNetworkStorageBroker: class NoNetworkStorageBroker:
implements(IStorageBroker) implements(IStorageBroker)

View File

@ -103,6 +103,10 @@ class TestShareFinder(unittest.TestCase):
return self.serverid return self.serverid
def get_rref(self): def get_rref(self):
return self.rref return self.rref
def name(self):
return "name-%s" % self.serverid
def get_version(self):
return self.rref.version
mockserver1 = MockServer({1: mock.Mock(), 2: mock.Mock()}) mockserver1 = MockServer({1: mock.Mock(), 2: mock.Mock()})
mockserver2 = MockServer({}) mockserver2 = MockServer({})