@@ -24,21 +24,18 @@ def _content_factory(name):
2424
2525
2626@pytest .fixture (scope = "class" )
27- def setup (
28- file_repository_factory ,
29- file_distribution_factory ,
30- content_factory ,
31- file_bindings ,
32- monitor_task ,
33- ):
34- def create_publication (repo , checkpoint ):
35- nonlocal content_counter
27+ def create_publication (content_factory , file_bindings , monitor_task ):
28+ counter = [0 ]
29+
30+ def _create_publication (repo , checkpoint ):
31+ content_href = content_factory (f"{ counter [0 ]} " )
32+ counter [0 ] += 1
33+
3634 monitor_task (
3735 file_bindings .RepositoriesFileApi .modify (
38- repo .pulp_href , {"add_content_units" : [content_factory ( f" { content_counter } " ) ]}
36+ repo .pulp_href , {"add_content_units" : [content_href ]}
3937 ).task
4038 )
41- content_counter += 1
4239
4340 response = monitor_task (
4441 file_bindings .PublicationsFileApi .create (
@@ -47,11 +44,19 @@ def create_publication(repo, checkpoint):
4744 )
4845 return file_bindings .PublicationsFileApi .read (response .created_resources [0 ])
4946
47+ return _create_publication
48+
49+
50+ @pytest .fixture (scope = "class" )
51+ def setup (
52+ file_repository_factory ,
53+ file_distribution_factory ,
54+ create_publication ,
55+ ):
5056 repo = file_repository_factory ()
5157 distribution = file_distribution_factory (repository = repo .pulp_href , checkpoint = True )
5258
5359 pubs = []
54- content_counter = 0
5560 pubs .append (create_publication (repo , False ))
5661 sleep (1 )
5762 pubs .append (create_publication (repo , True ))
@@ -227,3 +232,51 @@ def test_checkpoint_publication_with_repository_version_fails(
227232 file_bindings .PublicationsFileApi ,
228233 {"repository_version" : repo .latest_version_href , "checkpoint" : True },
229234 )
235+
236+
237+ @pytest .mark .parallel
238+ def test_checkpoint_retention (
239+ file_bindings ,
240+ file_repository_factory ,
241+ file_distribution_factory ,
242+ create_publication ,
243+ monitor_task ,
244+ ):
245+ """Test retain_checkpoints for repositories.
246+
247+ When retain_checkpoints is set, only the N most recent checkpoint publications should
248+ retain their checkpoint=True flag. Older ones get their checkpoint flag cleared.
249+ """
250+ repo = file_repository_factory ()
251+ file_distribution_factory (repository = repo .pulp_href , checkpoint = True )
252+
253+ # Create 4 checkpoint publications
254+ checkpoint_pubs = []
255+ for _ in range (4 ):
256+ checkpoint_pubs .append (create_publication (repo , True ))
257+
258+ # Verify all 4 publications are checkpoints
259+ for pub in checkpoint_pubs :
260+ assert file_bindings .PublicationsFileApi .read (pub .pulp_href ).checkpoint is True
261+
262+ # Set retain_checkpoints=2 — should clear checkpoint flag on the 2 oldest
263+ task = file_bindings .RepositoriesFileApi .partial_update (
264+ repo .pulp_href , {"retain_checkpoints" : 2 }
265+ ).task
266+ monitor_task (task )
267+
268+ # Verify the 2 oldest had their flag cleared
269+ for pub in checkpoint_pubs [:2 ]:
270+ assert file_bindings .PublicationsFileApi .read (pub .pulp_href ).checkpoint is False
271+
272+ # Verify the 2 most recent still have checkpoint=True
273+ for pub in checkpoint_pubs [2 :]:
274+ assert file_bindings .PublicationsFileApi .read (pub .pulp_href ).checkpoint is True
275+
276+ # Create another checkpoint — should trigger steady-state cleanup
277+ new_pub = create_publication (repo , True )
278+
279+ # checkpoint_pubs[2] should now be cleared too
280+ assert file_bindings .PublicationsFileApi .read (checkpoint_pubs [2 ].pulp_href ).checkpoint is False
281+ assert file_bindings .PublicationsFileApi .read (checkpoint_pubs [3 ].pulp_href ).checkpoint is True
282+ assert file_bindings .PublicationsFileApi .read (new_pub .pulp_href ).checkpoint is True
0 commit comments