Fix checkpoints pagination error

Currently, checkpoints pagination is broken. when
we listing checkpoints in dashboard (the number of
checkpoints is more than 20), it always shows the
same content (the first 20 checkpoints).

Change-Id: I07c9145112439a45a15c9be1c790a50e73f26720
Closes-Bug: #1714786
(cherry picked from commit 911ceab977)
This commit is contained in:
jiaopengju 2017-09-03 23:43:38 +08:00 committed by Pengju Jiao
parent 2dba4bd544
commit 78d1bed042
2 changed files with 25 additions and 1 deletions

View File

@ -213,6 +213,18 @@ class BankSection(object):
res += '/'
return res
@staticmethod
def _normalize_marker_with_prefix(marker, prefix):
if not isinstance(marker, six.string_types):
raise exception.InvalidParameterValue(
err=_('marker must be a string')
)
marker = prefix + marker
res = os.path.normpath(marker)
if marker.endswith('/'):
res += '/'
return res
def _validate_writable(self):
if not self.is_writable:
raise exception.BankReadonlyViolation()
@ -237,7 +249,7 @@ class BankSection(object):
prefix = self._prepend_prefix(prefix)
if marker is not None:
marker = self._prepend_prefix(marker)
marker = self._normalize_marker_with_prefix(marker, prefix)
return [
key[len(self._prefix):]

View File

@ -172,6 +172,18 @@ class BankSectionTest(base.TestCase):
expected_result[2:4],
list(section.list_objects("/", limit=2, marker="KeyB")))
def test_list_objects_with_extra_prefix_and_marker(self):
bank = self._create_test_bank()
section = BankSection(bank, "/prefix", is_writable=True)
section.update_object("prefix1/KeyA", "value")
section.update_object("prefix2/KeyB", "value")
section.update_object("prefix2/KeyC", "value")
expected_result = ["prefix2/KeyC"]
self.assertEqual(
expected_result,
list(section.list_objects('/prefix2/', marker="KeyB"))
)
def test_read_only(self):
bank = self._create_test_bank()
section = BankSection(bank, "/prefix", is_writable=False)