Skip to content

Commit

Permalink
Merge pull request #242 from rohanpm/multiple-arls
Browse files Browse the repository at this point in the history
Make --cdn-arl-template argument work as expected by Pub [RHELDST-20512]
  • Loading branch information
rohanpm authored Sep 28, 2023
2 parents 0dffac5 + e509d04 commit f85734c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pubtools/_pulp/services/cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def add_service_args(self, parser):
"--cdn-arl-template",
help="ARL template used for flushing cache by ARL",
nargs="*",
# FIXME: combination of nargs='*' and action='append' will
# generate a list of lists, but we just want one flat list.
# We flatten this elsewhere.
#
# When minimum python is >= 3.8, replace this with action="extend"
action="append",
default=[],
)

@property
Expand All @@ -61,6 +68,11 @@ def cdn_client(self):

def __get_instance(self):
args = self._service_args

# FIXME: see above comment about action="extend" for python >= 3.8
# This flattens the list-of-list.
args.cdn_arl_template = [x for y in args.cdn_arl_template for x in y]

if not args.cdn_url:
# disable requests made to CDN
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
[ INFO] Publish: finished
[ INFO] Flush CDN cache: started
[ INFO] Flushing cache for repo1:
[ INFO] /bar/fake-ttl/content/unit/1/client/mutable1
[ INFO] /bar/fake-ttl/content/unit/1/client/mutable2
[ INFO] /baz/fake-ttl/content/unit/1/client/mutable1
[ INFO] /baz/fake-ttl/content/unit/1/client/mutable2
[ INFO] /foo/fake-ttl/content/unit/1/client/mutable1
[ INFO] /foo/fake-ttl/content/unit/1/client/mutable2
[ INFO] https://cdn.example.com/content/unit/1/client/mutable1
Expand Down
7 changes: 7 additions & 0 deletions tests/publish/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def test_repo_publish_cache_cleanup_with_arl(command_tester):
"https://cdn.example.com/",
"--cdn-arl-template",
"/foo/{ttl}/{path}",
"--cdn-arl-template",
"/bar/{ttl}/{path}",
"/baz/{ttl}/{path}",
"--cdn-cert",
"/some/path/to/cert",
"--cdn-key",
Expand All @@ -279,6 +282,10 @@ def test_repo_publish_cache_cleanup_with_arl(command_tester):
assert [hist.repository.id for hist in fake_pulp.publish_history] == ["repo1"]
# flushed the urls and the arls
assert sorted(fake_publish.fastpurge_client.purged_urls) == [
"/bar/fake-ttl/content/unit/1/client/mutable1",
"/bar/fake-ttl/content/unit/1/client/mutable2",
"/baz/fake-ttl/content/unit/1/client/mutable1",
"/baz/fake-ttl/content/unit/1/client/mutable2",
"/foo/fake-ttl/content/unit/1/client/mutable1",
"/foo/fake-ttl/content/unit/1/client/mutable2",
"https://cdn.example.com/content/unit/1/client/mutable1",
Expand Down

0 comments on commit f85734c

Please sign in to comment.