Browse Source

Checkpoint marker not working when using plan or date

When listing checkpoints by plan or by date with marker,
the result is not correct. It is because that the marker
that generated in the process is not right, this patch
will fix it.

Closes-Bug: #1803409

Change-Id: I3d6c1a93e6408de1ca95552531d9ff2d2395afa2
jiaopengju 5 months ago
parent
commit
0a756778ed

+ 2
- 3
karbor/services/protection/checkpoint.py View File

@@ -326,13 +326,12 @@ class CheckpointCollection(object):
326 326
             prefix = "/by-plan/%s/%s/" % (plan_id, project_id)
327 327
             if marker is not None:
328 328
                 date = marker_checkpoint["created_at"]
329
-                marker = "/by-plan/%s/%s/%s/%s" % (
330
-                    plan_id, project_id, date, marker)
329
+                marker = "/%s/%s" % (date, marker)
331 330
         else:
332 331
             prefix = "/by-date/"
333 332
             if marker is not None:
334 333
                 date = marker_checkpoint["created_at"]
335
-                marker = "/by-date/%s/%s/%s" % (date, project_id, marker)
334
+                marker = "/%s/%s/%s" % (date, project_id, marker)
336 335
 
337 336
         return self._list_ids(project_id, prefix, limit, marker, start_date,
338 337
                               end_date, sort_dir, context=context)

+ 32
- 0
karbor/tests/unit/protection/test_checkpoint_collection.py View File

@@ -95,6 +95,20 @@ class CheckpointCollectionTest(base.TestCase):
95 95
             plan_id="fake_plan_id", start_date=date2)),
96 96
             checkpoints_plan_date2)
97 97
 
98
+    def test_list_checkpoints_by_plan_with_marker(self):
99
+        collection = self._create_test_collection()
100
+        plan = fake_protection_plan()
101
+        plan["id"] = "fake_plan_id"
102
+        plan['provider_id'] = "fake_provider_id"
103
+        plan["project_id"] = "fake_project_id"
104
+        provider_id = plan['provider_id']
105
+        checkpoints_plan = {collection.create(plan, {
106
+            'checkpoint_id': i}).id for i in range(10)}
107
+        checkpoints_sorted = sorted(checkpoints_plan)
108
+        self.assertEqual(len(collection.list_ids(
109
+            project_id="fake_project_id", provider_id=provider_id,
110
+            plan_id="fake_plan_id", marker=checkpoints_sorted[0])) < 10, True)
111
+
98 112
     def test_list_checkpoints_by_date(self):
99 113
         collection = self._create_test_collection()
100 114
         date1 = datetime.strptime("2016-06-12", "%Y-%m-%d")
@@ -121,6 +135,24 @@ class CheckpointCollectionTest(base.TestCase):
121 135
             end_date=date2)),
122 136
             checkpoints_date_2)
123 137
 
138
+    def test_list_checkpoints_by_date_with_marker(self):
139
+        collection = self._create_test_collection()
140
+        date = datetime.strptime("2018-11-12", "%Y-%m-%d")
141
+        timeutils.utcnow = mock.MagicMock()
142
+        timeutils.utcnow.return_value = date
143
+        plan = fake_protection_plan()
144
+        plan["id"] = "fake_plan_id"
145
+        plan['provider_id'] = "fake_provider_id"
146
+        plan["project_id"] = "fake_project_id"
147
+        provider_id = plan['provider_id']
148
+        checkpoints_plan = {collection.create(plan, {
149
+            'checkpoint_id': i}).id for i in range(10)}
150
+        checkpoints_sorted = sorted(checkpoints_plan)
151
+        self.assertEqual(len(collection.list_ids(
152
+            project_id="fake_project_id", provider_id=provider_id,
153
+            start_date=date,
154
+            marker=checkpoints_sorted[0])) < 10, True)
155
+
124 156
     def test_delete_checkpoint(self):
125 157
         collection = self._create_test_collection()
126 158
         plan = fake_protection_plan()

Loading…
Cancel
Save