more refactoring: move get_all_serverids() and get_nickname_for_serverid() from Clien...
authorBrian Warner <warner@lothar.com>
Tue, 2 Jun 2009 03:07:50 +0000 (20:07 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 2 Jun 2009 03:07:50 +0000 (20:07 -0700)
src/allmydata/client.py
src/allmydata/test/no_network.py
src/allmydata/test/test_checker.py
src/allmydata/test/test_mutable.py
src/allmydata/test/test_system.py
src/allmydata/test/test_web.py
src/allmydata/web/check_results.py

index 465c546a5653c0e05133deb9c492f20dfe445b54..0a08cddd82919c26859b3ec167ddad3a36a1724d 100644 (file)
@@ -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)
index 35431a13be76ab5b3b19646876ab11d491670968..d5d3b48c122397eb584b5c2f103396c5751ee183 100644 (file)
@@ -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 = {}
index 03b57530d41711470057646793f1be362bcb7629..88f749517453ca418c7f8e2069e3fd3eea4b474d 100644 (file)
@@ -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
 
index 942fa7628fcee13a15dbd783bd5d836614756533..8f548d94d072bc7d9554ec005bb7b9c2de4023ae 100644 (file)
@@ -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",
index 7ace3d1ca3521f04a64dca53fa836538b19a08ae..6d65b9b90ed57c2fecbb1a799b050038a3f7f0f6 100644 (file)
@@ -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"))
index 0570473cbcb65142d93c8ec72f9de142bfcec37a..2cccb27dc9108a499e3c493d0aa3c1ef3bdc6177 100644 (file)
@@ -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
index cf5634a775c01057926a40a40a99248676690406..94fb7f61532a02babbe1f31b701764eda8536819 100644 (file)
@@ -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))