diff --git a/karbor/services/protection/bank_plugin.py b/karbor/services/protection/bank_plugin.py index 882f75b5..714b3078 100644 --- a/karbor/services/protection/bank_plugin.py +++ b/karbor/services/protection/bank_plugin.py @@ -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):] diff --git a/karbor/tests/unit/protection/test_bank.py b/karbor/tests/unit/protection/test_bank.py index 5522b5ac..de02bc1c 100644 --- a/karbor/tests/unit/protection/test_bank.py +++ b/karbor/tests/unit/protection/test_bank.py @@ -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)