From 7bbf0031b3f878eec410d4d3cf7263ccae32b136 Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Mon, 7 Nov 2022 19:07:44 -0500 Subject: [PATCH] fixes saltstack/salt#63033 fix file.retention_schedule always reports changes --- changelog/63033.fixed | 1 + salt/states/file.py | 7 ++++--- tests/pytests/unit/states/file/test_retention_schedule.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog/63033.fixed diff --git a/changelog/63033.fixed b/changelog/63033.fixed new file mode 100644 index 000000000000..11687bd183c3 --- /dev/null +++ b/changelog/63033.fixed @@ -0,0 +1 @@ +Fix file.retention_schedule always reports changes diff --git a/salt/states/file.py b/salt/states/file.py index db0b5a41d694..5cec0deb97f5 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -4609,6 +4609,7 @@ def retention_schedule(name, retain, strptime_format=None, timezone=None): Apply retention scheduling to backup storage directory. .. versionadded:: 2016.11.0 + .. versionchanged:: 3006.0 :param name: The filesystem path to the directory containing backups to be managed. @@ -4671,7 +4672,7 @@ def retention_schedule(name, retain, strptime_format=None, timezone=None): name = os.path.expanduser(name) ret = { "name": name, - "changes": {"retained": [], "deleted": [], "ignored": []}, + "changes": {}, "result": True, "comment": "", } @@ -4785,7 +4786,8 @@ def get_first_n_at_depth(fwt, depth, n): "deleted": deletable_files, "ignored": sorted(list(ignored_files), reverse=True), } - ret["changes"] = changes + if deletable_files: + ret["changes"] = changes # TODO: track and report how much space was / would be reclaimed if __opts__["test"]: @@ -4800,7 +4802,6 @@ def get_first_n_at_depth(fwt, depth, n): ret["comment"] = "{} backups were removed from {}.\n".format( len(deletable_files), name ) - ret["changes"] = changes return ret diff --git a/tests/pytests/unit/states/file/test_retention_schedule.py b/tests/pytests/unit/states/file/test_retention_schedule.py index f948338727dd..3e9179afcbfa 100644 --- a/tests/pytests/unit/states/file/test_retention_schedule.py +++ b/tests/pytests/unit/states/file/test_retention_schedule.py @@ -135,7 +135,7 @@ def lstat_side_effect(path): def run_checks(isdir=mock_t, strptime_format=None, test=False): expected_ret = { "name": fake_name, - "changes": {"retained": [], "deleted": [], "ignored": []}, + "changes": {}, "result": True, "comment": "Name provided to file.retention must be a directory", }