From de8199d3b0986da15d35e611cc1f47415754a3eb Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 15 Aug 2019 11:08:04 -0400 Subject: [PATCH] Improve the behavior of get_slot_leases when no shares exist --- src/allmydata/storage/server.py | 6 ++---- src/allmydata/test/test_storage.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/allmydata/storage/server.py b/src/allmydata/storage/server.py index e5f5a6c40..eae6fd698 100644 --- a/src/allmydata/storage/server.py +++ b/src/allmydata/storage/server.py @@ -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 [] diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 03a7d5def..87458c3a7 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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