diff --git a/changelog/65819.fixed.md b/changelog/65819.fixed.md new file mode 100644 index 0000000000..27c2e9bc70 --- /dev/null +++ b/changelog/65819.fixed.md @@ -0,0 +1 @@ +Allow keyword arguments for the fileserver roots backend update function. diff --git a/salt/fileserver/roots.py b/salt/fileserver/roots.py index 4880cbab9b..5f168099c1 100644 --- a/salt/fileserver/roots.py +++ b/salt/fileserver/roots.py @@ -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: %s" % kwargs) + try: salt.fileserver.reap_fileserver_cache_dir( os.path.join(__opts__["cachedir"], "roots", "hash"), find_file @@ -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 @@ -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 diff --git a/tests/pytests/unit/fileserver/test_roots.py b/tests/pytests/unit/fileserver/test_roots.py index a8a80eea17..46f83c4f1b 100644 --- a/tests/pytests/unit/fileserver/test_roots.py +++ b/tests/pytests/unit/fileserver/test_roots.py @@ -4,6 +4,7 @@ import copy import pathlib +import re import shutil import textwrap @@ -236,7 +237,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 @@ -277,3 +278,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 re.match(r"Unexpected keyword arguments received:", str(exc_info.value))