diff --git a/karbor/services/protection/checkpoint.py b/karbor/services/protection/checkpoint.py index c88ed2d4..72cbf245 100644 --- a/karbor/services/protection/checkpoint.py +++ b/karbor/services/protection/checkpoint.py @@ -326,13 +326,12 @@ class CheckpointCollection(object): prefix = "/by-plan/%s/%s/" % (plan_id, project_id) if marker is not None: date = marker_checkpoint["created_at"] - marker = "/by-plan/%s/%s/%s/%s" % ( - plan_id, project_id, date, marker) + marker = "/%s/%s" % (date, marker) else: prefix = "/by-date/" if marker is not None: date = marker_checkpoint["created_at"] - marker = "/by-date/%s/%s/%s" % (date, project_id, marker) + marker = "/%s/%s/%s" % (date, project_id, marker) return self._list_ids(project_id, prefix, limit, marker, start_date, end_date, sort_dir, context=context) diff --git a/karbor/tests/unit/protection/test_checkpoint_collection.py b/karbor/tests/unit/protection/test_checkpoint_collection.py index 6c968c35..5f10d4d1 100644 --- a/karbor/tests/unit/protection/test_checkpoint_collection.py +++ b/karbor/tests/unit/protection/test_checkpoint_collection.py @@ -95,6 +95,20 @@ class CheckpointCollectionTest(base.TestCase): plan_id="fake_plan_id", start_date=date2)), checkpoints_plan_date2) + def test_list_checkpoints_by_plan_with_marker(self): + collection = self._create_test_collection() + plan = fake_protection_plan() + plan["id"] = "fake_plan_id" + plan['provider_id'] = "fake_provider_id" + plan["project_id"] = "fake_project_id" + provider_id = plan['provider_id'] + checkpoints_plan = {collection.create(plan, { + 'checkpoint_id': i}).id for i in range(10)} + checkpoints_sorted = sorted(checkpoints_plan) + self.assertEqual(len(collection.list_ids( + project_id="fake_project_id", provider_id=provider_id, + plan_id="fake_plan_id", marker=checkpoints_sorted[0])) < 10, True) + def test_list_checkpoints_by_date(self): collection = self._create_test_collection() date1 = datetime.strptime("2016-06-12", "%Y-%m-%d") @@ -121,6 +135,24 @@ class CheckpointCollectionTest(base.TestCase): end_date=date2)), checkpoints_date_2) + def test_list_checkpoints_by_date_with_marker(self): + collection = self._create_test_collection() + date = datetime.strptime("2018-11-12", "%Y-%m-%d") + timeutils.utcnow = mock.MagicMock() + timeutils.utcnow.return_value = date + plan = fake_protection_plan() + plan["id"] = "fake_plan_id" + plan['provider_id'] = "fake_provider_id" + plan["project_id"] = "fake_project_id" + provider_id = plan['provider_id'] + checkpoints_plan = {collection.create(plan, { + 'checkpoint_id': i}).id for i in range(10)} + checkpoints_sorted = sorted(checkpoints_plan) + self.assertEqual(len(collection.list_ids( + project_id="fake_project_id", provider_id=provider_id, + start_date=date, + marker=checkpoints_sorted[0])) < 10, True) + def test_delete_checkpoint(self): collection = self._create_test_collection() plan = fake_protection_plan()