mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-25 07:31:07 +00:00
Merge pull request #1150 from tahoe-lafs/3832.backdated-leases
Supported backdated leases for the test suite Fixes: ticket:3832
This commit is contained in:
commit
7b554d1077
0
newsfragments/3832.minor
Normal file
0
newsfragments/3832.minor
Normal file
@ -152,11 +152,22 @@ class ShareFile(object):
|
|||||||
self._write_lease_record(f, num_leases, lease_info)
|
self._write_lease_record(f, num_leases, lease_info)
|
||||||
self._write_num_leases(f, num_leases+1)
|
self._write_num_leases(f, num_leases+1)
|
||||||
|
|
||||||
def renew_lease(self, renew_secret, new_expire_time):
|
def renew_lease(self, renew_secret, new_expire_time, allow_backdate=False):
|
||||||
|
# type: (bytes, int, bool) -> None
|
||||||
|
"""
|
||||||
|
Update the expiration time on an existing lease.
|
||||||
|
|
||||||
|
:param allow_backdate: If ``True`` then allow the new expiration time
|
||||||
|
to be before the current expiration time. Otherwise, make no
|
||||||
|
change when this is the case.
|
||||||
|
|
||||||
|
:raise IndexError: If there is no lease matching the given renew
|
||||||
|
secret.
|
||||||
|
"""
|
||||||
for i,lease in enumerate(self.get_leases()):
|
for i,lease in enumerate(self.get_leases()):
|
||||||
if timing_safe_compare(lease.renew_secret, renew_secret):
|
if timing_safe_compare(lease.renew_secret, renew_secret):
|
||||||
# yup. See if we need to update the owner time.
|
# yup. See if we need to update the owner time.
|
||||||
if new_expire_time > lease.get_expiration_time():
|
if allow_backdate or new_expire_time > lease.get_expiration_time():
|
||||||
# yes
|
# yes
|
||||||
lease = lease.renew(new_expire_time)
|
lease = lease.renew(new_expire_time)
|
||||||
with open(self.home, 'rb+') as f:
|
with open(self.home, 'rb+') as f:
|
||||||
|
@ -298,13 +298,24 @@ class MutableShareFile(object):
|
|||||||
else:
|
else:
|
||||||
self._write_lease_record(f, num_lease_slots, lease_info)
|
self._write_lease_record(f, num_lease_slots, lease_info)
|
||||||
|
|
||||||
def renew_lease(self, renew_secret, new_expire_time):
|
def renew_lease(self, renew_secret, new_expire_time, allow_backdate=False):
|
||||||
|
# type: (bytes, int, bool) -> None
|
||||||
|
"""
|
||||||
|
Update the expiration time on an existing lease.
|
||||||
|
|
||||||
|
:param allow_backdate: If ``True`` then allow the new expiration time
|
||||||
|
to be before the current expiration time. Otherwise, make no
|
||||||
|
change when this is the case.
|
||||||
|
|
||||||
|
:raise IndexError: If there is no lease matching the given renew
|
||||||
|
secret.
|
||||||
|
"""
|
||||||
accepting_nodeids = set()
|
accepting_nodeids = set()
|
||||||
with open(self.home, 'rb+') as f:
|
with open(self.home, 'rb+') as f:
|
||||||
for (leasenum,lease) in self._enumerate_leases(f):
|
for (leasenum,lease) in self._enumerate_leases(f):
|
||||||
if timing_safe_compare(lease.renew_secret, renew_secret):
|
if timing_safe_compare(lease.renew_secret, renew_secret):
|
||||||
# yup. See if we need to update the owner time.
|
# yup. See if we need to update the owner time.
|
||||||
if new_expire_time > lease.get_expiration_time():
|
if allow_backdate or new_expire_time > lease.get_expiration_time():
|
||||||
# yes
|
# yes
|
||||||
lease = lease.renew(new_expire_time)
|
lease = lease.renew(new_expire_time)
|
||||||
self._write_lease_record(f, leasenum, lease)
|
self._write_lease_record(f, leasenum, lease)
|
||||||
|
@ -485,17 +485,7 @@ class LeaseCrawler(unittest.TestCase, pollmixin.PollMixin):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def backdate_lease(self, sf, renew_secret, new_expire_time):
|
def backdate_lease(self, sf, renew_secret, new_expire_time):
|
||||||
# ShareFile.renew_lease ignores attempts to back-date a lease (i.e.
|
sf.renew_lease(renew_secret, new_expire_time, allow_backdate=True)
|
||||||
# "renew" a lease with a new_expire_time that is older than what the
|
|
||||||
# current lease has), so we have to reach inside it.
|
|
||||||
for i,lease in enumerate(sf.get_leases()):
|
|
||||||
if lease.renew_secret == renew_secret:
|
|
||||||
lease = lease.renew(new_expire_time)
|
|
||||||
f = open(sf.home, 'rb+')
|
|
||||||
sf._write_lease_record(f, i, lease)
|
|
||||||
f.close()
|
|
||||||
return
|
|
||||||
raise IndexError("unable to renew non-existent lease")
|
|
||||||
|
|
||||||
def test_expire_age(self):
|
def test_expire_age(self):
|
||||||
basedir = "storage/LeaseCrawler/expire_age"
|
basedir = "storage/LeaseCrawler/expire_age"
|
||||||
|
Loading…
Reference in New Issue
Block a user