return i
return None
- def enumerate_leases(self, f):
+ def _enumerate_leases(self, f):
"""Yields (leasenum, (ownerid, expiration_time, renew_secret,
cancel_secret, accepting_nodeid)) for all leases."""
for i in range(self._get_num_lease_slots(f)):
except IndexError:
return
+ def debug_enumerate_leases(self):
+ f = open(self.home, 'rb')
+ leases = list(self._enumerate_leases(f))
+ f.close()
+ return leases
+
def add_lease(self, lease_info):
f = open(self.home, 'rb+')
num_lease_slots = self._get_num_lease_slots(f)
def renew_lease(self, renew_secret, new_expire_time):
accepting_nodeids = set()
f = open(self.home, 'rb+')
- for (leasenum,(oid,et,rs,cs,anid)) in self.enumerate_leases(f):
+ for (leasenum,(oid,et,rs,cs,anid)) in self._enumerate_leases(f):
if rs == renew_secret:
# yup. See if we need to update the owner time.
if new_expire_time > et:
blank = "\x00"*32
blank_lease = (0, 0, blank, blank, blank)
f = open(self.home, 'rb+')
- for (leasenum,(oid,et,rs,cs,anid)) in self.enumerate_leases(f):
+ for (leasenum,(oid,et,rs,cs,anid)) in self._enumerate_leases(f):
accepting_nodeids.add(anid)
if cs == cancel_secret:
self._write_lease_record(f, leasenum, blank_lease)
# cancel one of them
ss.remote_cancel_lease("si1", self.cancel_secret(secret+5))
+ all_leases = s0.debug_enumerate_leases()
+ self.failUnlessEqual(len(all_leases), 5)
+
# and write enough data to expand the container, forcing the server
# to move the leases
answer = s0.remote_testv_and_writev(WE,
[(0, data),],
new_length=200)
- # TODO: read back the leases, make sure they're still intact. We need
- # a renew_lease() call for this.
+ # read back the leases, make sure they're still intact.
+ self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+
ss.remote_renew_lease("si1", self.renew_secret(secret))
ss.remote_renew_lease("si1", self.renew_secret(secret+1))
ss.remote_renew_lease("si1", self.renew_secret(secret+2))
ss.remote_cancel_lease, "si1",
self.cancel_secret(secret+20))
+ self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+ answer = s0.remote_testv_and_writev(WE,
+ [],
+ [(200, "make me bigger"),],
+ new_length=None)
+ self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+
+ answer = s0.remote_testv_and_writev(WE,
+ [],
+ [(500, "make me really bigger"),],
+ new_length=None)
+ self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+
# now cancel them all
ss.remote_cancel_lease("si1", self.cancel_secret(secret))
ss.remote_cancel_lease("si1", self.cancel_secret(secret+1))
ss.remote_cancel_lease("si1", self.cancel_secret(secret+2))
ss.remote_cancel_lease("si1", self.cancel_secret(secret+3))
- # slot should still be there
+ # the slot should still be there
shares3 = ss.remote_get_mutable_slot("si1")
self.failUnlessEqual(len(shares3), 3)
+ self.failUnlessEqual(len(s0.debug_enumerate_leases()), 1)
+
ss.remote_cancel_lease("si1", self.cancel_secret(secret+4))
# now the slot should be gone
self.failUnlessEqual(ss.remote_get_mutable_slot("si1"), {})