From 1734b07e05fd62acb8bb3373fc59ce5238345b64 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Tue, 17 Mar 2026 08:04:05 +1300 Subject: [PATCH] monit: deprecate support for monit <= 5.18 (#11254) * monit: deprecate support for monit <= 5.18 * add additional runs for checking version * add changelog frag * bump deprecation for 14.0.0 (cherry picked from commit cc24e573072114c36264f62bb46c62abb11b8e7a) --- changelogs/fragments/11254-monit-deprecate-old.yml | 2 ++ plugins/modules/monit.py | 9 +++++++++ tests/unit/plugins/modules/test_monit.py | 1 + tests/unit/plugins/modules/test_monit.yaml | 6 ++++-- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/11254-monit-deprecate-old.yml diff --git a/changelogs/fragments/11254-monit-deprecate-old.yml b/changelogs/fragments/11254-monit-deprecate-old.yml new file mode 100644 index 0000000000..1f148f7587 --- /dev/null +++ b/changelogs/fragments/11254-monit-deprecate-old.yml @@ -0,0 +1,2 @@ +deprecated_features: + - monit - support for Monit version 5.18 or older is deprecated and will be removed in community.general 14.0.0 (https://github.com/ansible-collections/community.general/pull/11254). diff --git a/plugins/modules/monit.py b/plugins/modules/monit.py index 7244c1fec2..f2eb01abd2 100644 --- a/plugins/modules/monit.py +++ b/plugins/modules/monit.py @@ -39,6 +39,8 @@ options: author: - Darryl Stoflet (@dstoflet) - Simon Kelly (@snopoke) +requirements: + - Monit. Support for versions 5.18 and older is deprecated and will be removed in community.general 14.0.0. """ EXAMPLES = r""" @@ -125,6 +127,13 @@ class Monit: self._raw_version = None self._status_change_retry_count = 6 + if self.monit_version() <= (5, 18): + module.deprecate( + "Support for monit 5.18 and older is deprecated and will be removed in community.general 14.0.0.", + version="14.0.0", + collection_name="community.general", + ) + def monit_version(self): if self._monit_version is None: self._raw_version, version = self._get_monit_version() diff --git a/tests/unit/plugins/modules/test_monit.py b/tests/unit/plugins/modules/test_monit.py index fc938e950e..6d3b75daa5 100644 --- a/tests/unit/plugins/modules/test_monit.py +++ b/tests/unit/plugins/modules/test_monit.py @@ -24,6 +24,7 @@ class MonitTest(unittest.TestCase): self.module = mock.MagicMock() self.module.exit_json.side_effect = AnsibleExitJson self.module.fail_json.side_effect = AnsibleFailJson + self.module.run_command.return_value = (0, "This is monit version 5.26.0", "") self.monit = monit.Monit(self.module, "monit", "processX", 1) self.monit._status_change_retry_count = 1 mock_sleep = mock.patch("time.sleep") diff --git a/tests/unit/plugins/modules/test_monit.yaml b/tests/unit/plugins/modules/test_monit.yaml index bc20c768bf..8836c3cfe8 100644 --- a/tests/unit/plugins/modules/test_monit.yaml +++ b/tests/unit/plugins/modules/test_monit.yaml @@ -357,7 +357,7 @@ test_cases: # ------------------------------------------------------------------ reload - id: state_reloaded - # reload exits before any presence/status checks; no version check either + # reload exits before any presence/status checks; version check happens in __init__ input: name: processX state: reloaded @@ -366,6 +366,7 @@ test_cases: state: reloaded mocks: run_command: + - *version_526 - command: [/testbin/monit, reload] environ: {} rc: 0 @@ -396,7 +397,7 @@ test_cases: # ------------------------------------------------------------------ failure cases - id: state_reloaded_fail - # reload returns rc=1 → fail_json("monit reload failed") + # reload returns rc=1 → fail_json("monit reload failed"); version check happens in __init__ input: name: processX state: reloaded @@ -404,6 +405,7 @@ test_cases: failed: true mocks: run_command: + - *version_526 - command: [/testbin/monit, reload] environ: {} rc: 1