From: Brian Warner Date: Tue, 2 Jun 2009 03:07:50 +0000 (-0700) Subject: more refactoring: move get_all_serverids() and get_nickname_for_serverid() from Clien... X-Git-Tag: trac-3900~3 X-Git-Url: https://git.rkrishnan.org/listings/frontends/running.html?a=commitdiff_plain;h=35b3f7f426c193cf32be2a34ff4ea2283824d4b7;p=tahoe-lafs%2Ftahoe-lafs.git more refactoring: move get_all_serverids() and get_nickname_for_serverid() from Client to storage_broker --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 465c546a..0a08cddd 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -375,11 +375,6 @@ class Client(node.Node, pollmixin.PollMixin): self.log("hotline file missing, shutting down") reactor.stop() - def get_all_serverids(self): - return self.storage_broker.get_all_serverids() - def get_nickname_for_serverid(self, serverid): - return self.storage_broker.get_nickname_for_serverid(serverid) - def get_encoding_parameters(self): return self.DEFAULT_ENCODING_PARAMETERS @@ -400,7 +395,7 @@ class Client(node.Node, pollmixin.PollMixin): temporary test network and need to know when it is safe to proceed with an upload or download.""" def _check(): - current_clients = list(self.get_all_serverids()) + current_clients = list(self.storage_broker.get_all_serverids()) return len(current_clients) >= num_clients d = self.poll(_check, 0.5) d.addCallback(lambda res: None) diff --git a/src/allmydata/test/no_network.py b/src/allmydata/test/no_network.py index 35431a13..d5d3b48c 100644 --- a/src/allmydata/test/no_network.py +++ b/src/allmydata/test/no_network.py @@ -108,6 +108,8 @@ class NoNetworkStorageBroker: def get_servers(self, key): return sorted(self.client._servers, key=lambda x: sha.new(key+x[0]).digest()) + def get_nickname_for_serverid(self, serverid): + return None class NoNetworkClient(Client): @@ -140,9 +142,6 @@ class NoNetworkClient(Client): def get_servers(self, service_name): return self._servers - def get_nickname_for_serverid(self, serverid): - return None - class SimpleStats: def __init__(self): self.counters = {} diff --git a/src/allmydata/test/test_checker.py b/src/allmydata/test/test_checker.py index 03b57530..88f74951 100644 --- a/src/allmydata/test/test_checker.py +++ b/src/allmydata/test/test_checker.py @@ -7,8 +7,6 @@ from allmydata.storage_client import StorageFarmBroker, NativeStorageClient from common_web import WebRenderingMixin class FakeClient: - def get_nickname_for_serverid(self, serverid): - return self.storage_broker.get_nickname_for_serverid(serverid) def get_storage_broker(self): return self.storage_broker diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py index 942fa762..8f548d94 100644 --- a/src/allmydata/test/test_mutable.py +++ b/src/allmydata/test/test_mutable.py @@ -179,8 +179,6 @@ class FakeClient: fss = FakeStorageServer(peerid, self._storage) self.storage_broker.add_server(peerid, fss) - def get_all_serverids(self): - return self.storage_broker.get_all_serverids() def get_storage_broker(self): return self.storage_broker def debug_break_connection(self, peerid): @@ -275,7 +273,8 @@ class Filenode(unittest.TestCase, testutil.ShouldFailMixin): def _created(n): self.failUnless(isinstance(n, FastMutableFileNode)) self.failUnlessEqual(n.get_storage_index(), n._storage_index) - peer0 = sorted(self.client.get_all_serverids())[0] + sb = self.client.get_storage_broker() + peer0 = sorted(sb.get_all_serverids())[0] shnums = self.client._storage._peers[peer0].keys() self.failUnlessEqual(len(shnums), 1) d.addCallback(_created) @@ -1573,8 +1572,9 @@ class MultipleEncodings(unittest.TestCase): places = [2, 2, 3, 2, 1, 1, 1, 2] sharemap = {} + sb = self._client.get_storage_broker() - for i,peerid in enumerate(self._client.get_all_serverids()): + for i,peerid in enumerate(sb.get_all_serverids()): peerid_s = shortnodeid_b2a(peerid) for shnum in self._shares1.get(peerid, {}): if shnum < len(places): @@ -1958,8 +1958,9 @@ class Problems(unittest.TestCase, testutil.ShouldFailMixin): # not prevent an update from succeeding either. basedir = os.path.join("mutable/CollidingWrites/test_bad_server") self.client = LessFakeClient(basedir, 10) + sb = self.client.get_storage_broker() - peerids = list(self.client.get_all_serverids()) + peerids = list(sb.get_all_serverids()) self.client.debug_break_connection(peerids[0]) d = self.client.create_mutable_file("contents 1") @@ -1982,7 +1983,8 @@ class Problems(unittest.TestCase, testutil.ShouldFailMixin): # Break all servers: the publish should fail basedir = os.path.join("mutable/CollidingWrites/publish_all_servers_bad") self.client = LessFakeClient(basedir, 20) - for peerid in self.client.get_all_serverids(): + sb = self.client.get_storage_broker() + for peerid in sb.get_all_serverids(): self.client.debug_break_connection(peerid) d = self.shouldFail(NotEnoughServersError, "test_publish_all_servers_bad", diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 7ace3d1c..6d65b9b9 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -72,7 +72,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase): def _check(extra_node): self.extra_node = extra_node for c in self.clients: - all_peerids = list(c.get_all_serverids()) + all_peerids = list(c.get_storage_broker().get_all_serverids()) self.failUnlessEqual(len(all_peerids), self.numclients+1) sb = c.storage_broker permuted_peers = list(sb.get_servers("a")) @@ -110,7 +110,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase): d = self.set_up_nodes() def _check_connections(res): for c in self.clients: - all_peerids = list(c.get_all_serverids()) + all_peerids = list(c.get_storage_broker().get_all_serverids()) self.failUnlessEqual(len(all_peerids), self.numclients) sb = c.storage_broker permuted_peers = list(sb.get_servers("a")) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 0570473c..2cccb27d 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -65,9 +65,6 @@ class FakeClient(service.MultiService): def connected_to_introducer(self): return False - def get_nickname_for_serverid(self, serverid): - return u"John Doe" - storage_broker = StorageFarmBroker() def get_storage_broker(self): return self.storage_broker diff --git a/src/allmydata/web/check_results.py b/src/allmydata/web/check_results.py index cf5634a7..94fb7f61 100644 --- a/src/allmydata/web/check_results.py +++ b/src/allmydata/web/check_results.py @@ -80,6 +80,7 @@ class ResultsBase: def _render_results(self, ctx, cr): assert ICheckResults(cr) c = self.client + sb = c.get_storage_broker() data = cr.get_data() r = [] def add(name, value): @@ -95,7 +96,7 @@ class ResultsBase: if data["list-corrupt-shares"]: badsharemap = [] for (serverid, si, shnum) in data["list-corrupt-shares"]: - nickname = c.get_nickname_for_serverid(serverid) + nickname = sb.get_nickname_for_serverid(serverid) badsharemap.append(T.tr[T.td["sh#%d" % shnum], T.td[T.div(class_="nickname")[nickname], T.div(class_="nodeid")[T.tt[base32.b2a(serverid)]]], @@ -123,7 +124,7 @@ class ResultsBase: shareid_s = "" if i == 0: shareid_s = shareid - nickname = c.get_nickname_for_serverid(serverid) + nickname = sb.get_nickname_for_serverid(serverid) sharemap.append(T.tr[T.td[shareid_s], T.td[T.div(class_="nickname")[nickname], T.div(class_="nodeid")[T.tt[base32.b2a(serverid)]]] @@ -145,7 +146,7 @@ class ResultsBase: num_shares_left = sum([len(shares) for shares in servers.values()]) servermap = [] for serverid in permuted_peer_ids: - nickname = c.get_nickname_for_serverid(serverid) + nickname = sb.get_nickname_for_serverid(serverid) shareids = servers.get(serverid, []) shareids.reverse() shareids_s = [ T.tt[shareid, " "] for shareid in sorted(shareids) ] @@ -419,7 +420,8 @@ class DeepCheckResults(rend.Page, ResultsBase, ReloadMixin): def render_server_problem(self, ctx, data): serverid = data data = [idlib.shortnodeid_b2a(serverid)] - nickname = self.client.get_nickname_for_serverid(serverid) + sb = self.client.get_storage_broker() + nickname = sb.get_nickname_for_serverid(serverid) if nickname: data.append(" (%s)" % self._html(nickname)) return ctx.tag[data] @@ -433,7 +435,8 @@ class DeepCheckResults(rend.Page, ResultsBase, ReloadMixin): return self.monitor.get_status().get_corrupt_shares() def render_share_problem(self, ctx, data): serverid, storage_index, sharenum = data - nickname = self.client.get_nickname_for_serverid(serverid) + sb = self.client.get_storage_broker() + nickname = sb.get_nickname_for_serverid(serverid) ctx.fillSlots("serverid", idlib.shortnodeid_b2a(serverid)) if nickname: ctx.fillSlots("nickname", self._html(nickname))