summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-13 12:58:08 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-13 13:00:37 +0800
commit705040dbe3381c9ea63e71e66ed8618246baeb11 (patch)
tree2a402c9ad79727d91f3f1a7215b0320b3990b5d5
parentfd17f48547553dbef3d36a79cb3670b61cdeb817 (diff)
Fix listing checkpoints by plan and start_date
Now when listing checkpoints by plan and doing filter by start_date, it will fail with ValueError. It is because the process of datetime is not right when specify start_date and plan_id at the same time. This patch will fix it. Closes-Bug: #1803035 Change-Id: Ifa2c0e03a0b83d0e5a59e53425cec5be663e13fb
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: Tue, 13 Nov 2018 08:37:58 +0000 Reviewed-on: https://review.openstack.org/617444 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/services/protection/checkpoint.py7
-rw-r--r--karbor/tests/unit/protection/test_checkpoint_collection.py26
2 files changed, 31 insertions, 2 deletions
diff --git a/karbor/services/protection/checkpoint.py b/karbor/services/protection/checkpoint.py
index 9107975..c88ed2d 100644
--- a/karbor/services/protection/checkpoint.py
+++ b/karbor/services/protection/checkpoint.py
@@ -354,8 +354,11 @@ class CheckpointCollection(object):
354 marker=marker, 354 marker=marker,
355 sort_dir=sort_dir, 355 sort_dir=sort_dir,
356 context=context): 356 context=context):
357 date = datetime.strptime(key.split("/")[-3], "%Y-%m-%d") 357 date_cursor = -2 if (prefix.find('by-plan') >= 0) else -3
358 checkpoint_project_id = key.split("/")[-2] 358 project_id_cursor = -3 if (prefix.find('by-plan') >= 0) else -2
359 date = datetime.strptime(
360 key.split("/")[date_cursor], "%Y-%m-%d")
361 checkpoint_project_id = key.split("/")[project_id_cursor]
359 if start_date <= date <= end_date and ( 362 if start_date <= date <= end_date and (
360 checkpoint_project_id == project_id): 363 checkpoint_project_id == project_id):
361 ids.append(key[key.find("@") + 1:]) 364 ids.append(key[key.find("@") + 1:])
diff --git a/karbor/tests/unit/protection/test_checkpoint_collection.py b/karbor/tests/unit/protection/test_checkpoint_collection.py
index 7e3d83b..6c968c3 100644
--- a/karbor/tests/unit/protection/test_checkpoint_collection.py
+++ b/karbor/tests/unit/protection/test_checkpoint_collection.py
@@ -69,6 +69,32 @@ class CheckpointCollectionTest(base.TestCase):
69 project_id="fake_project_id_2", provider_id=provider_id_2, 69 project_id="fake_project_id_2", provider_id=provider_id_2,
70 plan_id="fake_plan_id_2")), checkpoints_plan_2) 70 plan_id="fake_plan_id_2")), checkpoints_plan_2)
71 71
72 def test_list_checkpoints_by_plan_id_and_filter_by_start_date(self):
73 collection = self._create_test_collection()
74 date1 = datetime.strptime("2018-11-12", "%Y-%m-%d")
75 date2 = datetime.strptime("2018-11-13", "%Y-%m-%d")
76 timeutils.utcnow = mock.MagicMock()
77 timeutils.utcnow.return_value = date1
78 plan = fake_protection_plan()
79 plan["id"] = "fake_plan_id"
80 plan['provider_id'] = "fake_provider_id"
81 plan["project_id"] = "fake_project_id"
82 provider_id = plan['provider_id']
83 checkpoints_plan_date1 = {
84 collection.create(plan).id for i in range(10)}
85 timeutils.utcnow = mock.MagicMock()
86 timeutils.utcnow.return_value = date2
87 checkpoints_plan_date2 = {
88 collection.create(plan).id for i in range(10)}
89 self.assertEqual(set(collection.list_ids(
90 project_id="fake_project_id", provider_id=provider_id,
91 plan_id="fake_plan_id", start_date=date1, end_date=date1)),
92 checkpoints_plan_date1)
93 self.assertEqual(set(collection.list_ids(
94 project_id="fake_project_id", provider_id=provider_id,
95 plan_id="fake_plan_id", start_date=date2)),
96 checkpoints_plan_date2)
97
72 def test_list_checkpoints_by_date(self): 98 def test_list_checkpoints_by_date(self):
73 collection = self._create_test_collection() 99 collection = self._create_test_collection()
74 date1 = datetime.strptime("2016-06-12", "%Y-%m-%d") 100 date1 = datetime.strptime("2016-06-12", "%Y-%m-%d")