Merge "Fix how the dir persistence backend was not listing logbooks"

This commit is contained in:
Jenkins 2015-10-11 02:16:17 +00:00 committed by Gerrit Code Review
commit 2d8b9dad24
2 changed files with 27 additions and 2 deletions

View File

@ -136,9 +136,13 @@ class Connection(path_based.PathBasedConnection):
shutil.rmtree(path)
def _get_children(self, path):
if path == self.book_path:
filter_func = os.path.isdir
else:
filter_func = os.path.islink
with _storagefailure_wrapper():
return [link for link in os.listdir(path)
if os.path.islink(self._join_path(path, link))]
return [child for child in os.listdir(path)
if filter_func(self._join_path(path, child))]
def _ensure_path(self, path):
with _storagefailure_wrapper():

View File

@ -69,6 +69,27 @@ class PersistenceTestMixin(object):
self.assertIsNotNone(lb2.find(fd.uuid))
self.assertIsNotNone(lb2.find(fd2.uuid))
def test_logbook_save_retrieve_many(self):
lb_ids = {}
for i in range(0, 10):
lb_id = uuidutils.generate_uuid()
lb_name = 'lb-%s-%s' % (i, lb_id)
lb = models.LogBook(name=lb_name, uuid=lb_id)
lb_ids[lb_id] = True
# Should not already exist
with contextlib.closing(self._get_connection()) as conn:
self.assertRaises(exc.NotFound, conn.get_logbook, lb_id)
conn.save_logbook(lb)
# Now fetch them all
with contextlib.closing(self._get_connection()) as conn:
lbs = conn.get_logbooks()
for lb in lbs:
self.assertIn(lb.uuid, lb_ids)
lb_ids.pop(lb.uuid)
self.assertEqual(0, len(lb_ids))
def test_logbook_save_retrieve(self):
lb_id = uuidutils.generate_uuid()
lb_meta = {'1': 2}