From f6450d9d6b848c59c0ca0fa1fc95f0e5eae1a1fe Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 4 Sep 2015 11:08:11 -0700 Subject: [PATCH] Fix how the dir persistence backend was not listing logbooks Due to the usage of the os.path.islink check this means that no logbooks would be returned when get_logbooks was called, which is not the behavior we want. Closes-Bug: #1492403 Change-Id: Ife6a5bec777c9e2d820391914ce2c6fbbadf4f79 --- taskflow/persistence/backends/impl_dir.py | 8 ++++++-- taskflow/tests/unit/persistence/base.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/taskflow/persistence/backends/impl_dir.py b/taskflow/persistence/backends/impl_dir.py index f91c4e72..9d7b3ca2 100644 --- a/taskflow/persistence/backends/impl_dir.py +++ b/taskflow/persistence/backends/impl_dir.py @@ -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(): diff --git a/taskflow/tests/unit/persistence/base.py b/taskflow/tests/unit/persistence/base.py index 0b56617f..f5a20bd0 100644 --- a/taskflow/tests/unit/persistence/base.py +++ b/taskflow/tests/unit/persistence/base.py @@ -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}