Skip to content

Commit

Permalink
Allow kwargs for fileserver roots update (bsc#1218482)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycedres committed Jan 11, 2024
1 parent 107de57 commit 06cc4a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/65819.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow keyword arguments for the fileserver roots backend update function.
16 changes: 10 additions & 6 deletions salt/fileserver/roots.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,16 @@ def serve_file(load, fnd):
return ret


def update():
def update(**kwargs):
"""
When we are asked to update (regular interval) lets reap the cache
"""
# __pub_user responsible for the runner can be passed but we don't do anything with it
if "__pub_user" in kwargs:
del kwargs["__pub_user"]
if kwargs:
raise ValueError("Unexpected keyword arguments received")

try:
salt.fileserver.reap_fileserver_cache_dir(
os.path.join(__opts__["cachedir"], "roots", "hash"), find_file
Expand Down Expand Up @@ -193,9 +199,7 @@ def update():
os.makedirs(mtime_map_path_dir)
with salt.utils.files.fopen(mtime_map_path, "wb") as fp_:
for file_path, mtime in new_mtime_map.items():
fp_.write(
salt.utils.stringutils.to_bytes("{}:{}\n".format(file_path, mtime))
)
fp_.write(salt.utils.stringutils.to_bytes(f"{file_path}:{mtime}\n"))

if __opts__.get("fileserver_events", False):
# if there is a change, fire an event
Expand Down Expand Up @@ -326,11 +330,11 @@ def _file_lists(load, form):
return []
list_cache = os.path.join(
list_cachedir,
"{}.p".format(salt.utils.files.safe_filename_leaf(actual_saltenv)),
f"{salt.utils.files.safe_filename_leaf(actual_saltenv)}.p",
)
w_lock = os.path.join(
list_cachedir,
".{}.w".format(salt.utils.files.safe_filename_leaf(actual_saltenv)),
f".{salt.utils.files.safe_filename_leaf(actual_saltenv)}.w",
)
cache_match, refresh_cache, save_cache = salt.fileserver.check_file_list_cache(
__opts__, form, list_cache, w_lock
Expand Down
8 changes: 7 additions & 1 deletion tests/pytests/unit/fileserver/test_roots.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def test_update_mtime_map():
# between Python releases.
lines_written = sorted(mtime_map_mock.write_calls())
expected = sorted(
salt.utils.stringutils.to_bytes("{key}:{val}\n".format(key=key, val=val))
salt.utils.stringutils.to_bytes(f"{key}:{val}\n")
for key, val in new_mtime_map.items()
)
assert lines_written == expected, lines_written
Expand Down Expand Up @@ -277,3 +277,9 @@ def test_update_mtime_map_unicode_error(tmp_path):
},
"backend": "roots",
}


def test_update_unexpected_kwargs():
with pytest.raises(ValueError) as exc_info:
ret = roots.update(foo="bar")
assert str(exc_info.value) == "Unexpected keyword arguments received"

0 comments on commit 06cc4a4

Please sign in to comment.