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
This commit is contained in:
@@ -136,9 +136,13 @@ class Connection(path_based.PathBasedConnection):
|
|||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def _get_children(self, 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():
|
with _storagefailure_wrapper():
|
||||||
return [link for link in os.listdir(path)
|
return [child for child in os.listdir(path)
|
||||||
if os.path.islink(self._join_path(path, link))]
|
if filter_func(self._join_path(path, child))]
|
||||||
|
|
||||||
def _ensure_path(self, path):
|
def _ensure_path(self, path):
|
||||||
with _storagefailure_wrapper():
|
with _storagefailure_wrapper():
|
||||||
|
@@ -69,6 +69,27 @@ class PersistenceTestMixin(object):
|
|||||||
self.assertIsNotNone(lb2.find(fd.uuid))
|
self.assertIsNotNone(lb2.find(fd.uuid))
|
||||||
self.assertIsNotNone(lb2.find(fd2.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):
|
def test_logbook_save_retrieve(self):
|
||||||
lb_id = uuidutils.generate_uuid()
|
lb_id = uuidutils.generate_uuid()
|
||||||
lb_meta = {'1': 2}
|
lb_meta = {'1': 2}
|
||||||
|
Reference in New Issue
Block a user