]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
introduction/storage-broker: add assertions of serverids being the right type and...
authorZooko O'Whielacronx <zooko@zooko.com>
Fri, 17 Jul 2009 13:52:21 +0000 (06:52 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Fri, 17 Jul 2009 13:52:21 +0000 (06:52 -0700)
src/allmydata/storage_client.py

index 1dfefdd46840b28f0b8cbcbba14f02d05569d5e5..69161924bb19b77912af2422c10991c9175e0965 100644 (file)
@@ -33,6 +33,7 @@ from zope.interface import implements, Interface
 from foolscap.api import eventually
 from allmydata.interfaces import IStorageBroker
 from allmydata.util import idlib, log
+from allmydata.util.assertutil import _assert, precondition
 from allmydata.util.rrefutil import add_version_to_remote_reference
 
 # who is responsible for de-duplication?
@@ -68,7 +69,7 @@ class StorageFarmBroker:
         # descriptor manages its own Reconnector, and will give us a
         # RemoteReference when we ask them for it.
         self.descriptors = {}
-        # self.servers are statically configured from unit tests
+        # self.test_servers are statically configured from unit tests
         self.test_servers = {} # serverid -> rref
         self.introducer_client = None
 
@@ -83,6 +84,8 @@ class StorageFarmBroker:
         ic.subscribe_to("storage", self._got_announcement)
 
     def _got_announcement(self, serverid, ann_d):
+        precondition(isinstance(serverid, str), serverid)
+        precondition(len(serverid) == 20, serverid)
         assert ann_d["service-name"] == "storage"
         old = self.descriptors.get(serverid)
         if old:
@@ -127,7 +130,9 @@ class StorageFarmBroker:
             rref = dsc.get_rref()
             if rref:
                 servers[serverid] = rref
-        return frozenset(servers.items())
+        result = frozenset(servers.items())
+        _assert(len(result) <= len(self.get_all_serverids()), result, self.get_all_serverids())
+        return result
 
     def get_all_serverids(self):
         serverids = set()