[tahoe-lafs-trac-stream] [Tahoe-LAFS] #3832: test_storage_web.py duplicates internal lease management logic

Tahoe-LAFS trac at tahoe-lafs.org
Thu Oct 28 14:43:42 UTC 2021


#3832: test_storage_web.py duplicates internal lease management logic
---------------------+---------------------------
 Reporter:  exarkun  |          Owner:  exarkun
     Type:  defect   |         Status:  new
 Priority:  normal   |      Milestone:  undecided
Component:  unknown  |        Version:  n/a
 Keywords:           |  Launchpad Bug:
---------------------+---------------------------
 `test_storage_web.py` contains:

 {{{
     def backdate_lease(self, sf, renew_secret, new_expire_time):
         # ShareFile.renew_lease ignores attempts to back-date a lease
 (i.e.
         # "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")
 }}}

 which is essentially a copy of the `renew_lease` function in
 `immutable.py`:

 {{{
     def renew_lease(self, renew_secret, new_expire_time):
         for i,lease in enumerate(self.get_leases()):
             if timing_safe_compare(lease.renew_secret, renew_secret):
                 # yup. See if we need to update the owner time.
                 if new_expire_time > lease.get_expiration_time():
                     # yes
                     lease = lease.renew(new_expire_time)
                     with open(self.home, 'rb+') as f:
                         self._write_lease_record(f, i, lease)
                 return
         raise IndexError("unable to renew non-existent lease")
 }}}

 except it omits the "no going backwards" check and doesn't manage the
 lifetime of the open share file safely.

 This duplication is undesirable for the usual reasons and can easily be
 avoided by having the real implementation allow for backdated leases on
 request.

--
Ticket URL: <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3832>
Tahoe-LAFS <https://Tahoe-LAFS.org>
secure decentralized storage


More information about the tahoe-lafs-trac-stream mailing list