Improve the behavior of get_slot_leases when no shares exist

This commit is contained in:
Jean-Paul Calderone 2019-08-15 11:08:04 -04:00
parent fce9657ce3
commit de8199d3b0
2 changed files with 13 additions and 4 deletions

View File

@ -412,10 +412,8 @@ class StorageServer(service.MultiService, Referenceable):
:return: An iterable of the leases attached to this slot.
"""
si_dir = storage_index_to_dir(storage_index)
bucketdir = os.path.join(self.sharedir, si_dir)
for share_filename in os.listdir(bucketdir):
share = MutableShareFile(os.path.join(bucketdir, share_filename))
for _, share_filename in self._get_bucket_shares(storage_index):
share = MutableShareFile(share_filename)
return share.get_leases()
return []

View File

@ -1398,6 +1398,17 @@ class MutableServer(unittest.TestCase):
leases = list(ss.get_slot_leases(storage_index))
self.assertEqual([], leases)
def test_get_slot_leases_empty_slot(self):
"""
When ``get_slot_leases`` is called for a slot for which the server has no
shares, it returns an empty iterable.
"""
ss = self.create(b"test_get_slot_leases_empty_slot")
self.assertEqual(
list(ss.get_slot_leases(b"si1")),
[],
)
def test_remove_non_present(self):
"""
A write vector which would remove a share completely can be applied on a