summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-15 01:58:44 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-15 02:01:26 +0800
commit0a756778ed2e14ec054911b61b00cace65f47620 (patch)
treede5823abacb182eb4d9c033585faa2a3f798d45e
parent705040dbe3381c9ea63e71e66ed8618246baeb11 (diff)
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
Notes
Notes (review): Code-Review+2: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Workflow+1: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 16 Nov 2018 00:59:29 +0000 Reviewed-on: https://review.openstack.org/618005 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/services/protection/checkpoint.py5
-rw-r--r--karbor/tests/unit/protection/test_checkpoint_collection.py32
2 files changed, 34 insertions, 3 deletions
diff --git a/karbor/services/protection/checkpoint.py b/karbor/services/protection/checkpoint.py
index c88ed2d..72cbf24 100644
--- a/karbor/services/protection/checkpoint.py
+++ b/karbor/services/protection/checkpoint.py
@@ -326,13 +326,12 @@ class CheckpointCollection(object):
326 prefix = "/by-plan/%s/%s/" % (plan_id, project_id) 326 prefix = "/by-plan/%s/%s/" % (plan_id, project_id)
327 if marker is not None: 327 if marker is not None:
328 date = marker_checkpoint["created_at"] 328 date = marker_checkpoint["created_at"]
329 marker = "/by-plan/%s/%s/%s/%s" % ( 329 marker = "/%s/%s" % (date, marker)
330 plan_id, project_id, date, marker)
331 else: 330 else:
332 prefix = "/by-date/" 331 prefix = "/by-date/"
333 if marker is not None: 332 if marker is not None:
334 date = marker_checkpoint["created_at"] 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 return self._list_ids(project_id, prefix, limit, marker, start_date, 336 return self._list_ids(project_id, prefix, limit, marker, start_date,
338 end_date, sort_dir, context=context) 337 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 6c968c3..5f10d4d 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):
95 plan_id="fake_plan_id", start_date=date2)), 95 plan_id="fake_plan_id", start_date=date2)),
96 checkpoints_plan_date2) 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 def test_list_checkpoints_by_date(self): 112 def test_list_checkpoints_by_date(self):
99 collection = self._create_test_collection() 113 collection = self._create_test_collection()
100 date1 = datetime.strptime("2016-06-12", "%Y-%m-%d") 114 date1 = datetime.strptime("2016-06-12", "%Y-%m-%d")
@@ -121,6 +135,24 @@ class CheckpointCollectionTest(base.TestCase):
121 end_date=date2)), 135 end_date=date2)),
122 checkpoints_date_2) 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 def test_delete_checkpoint(self): 156 def test_delete_checkpoint(self):
125 collection = self._create_test_collection() 157 collection = self._create_test_collection()
126 plan = fake_protection_plan() 158 plan = fake_protection_plan()