From 834979e56a72959ce06bee865d3e98866326e994 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Mon, 16 Sep 2024 21:12:41 +1000 Subject: [PATCH] Add state.sls_exists to ssh client fixes: #66893 Signed-off-by: Olivier Mehani --- salt/client/ssh/wrapper/state.py | 22 ++++++++++++++++++++++ tests/integration/ssh/test_state.py | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/salt/client/ssh/wrapper/state.py b/salt/client/ssh/wrapper/state.py index 4f29c92bc176..f086e22d1aed 100644 --- a/salt/client/ssh/wrapper/state.py +++ b/salt/client/ssh/wrapper/state.py @@ -1112,6 +1112,28 @@ def show_low_sls(mods, saltenv="base", test=None, **kwargs): _cleanup_slsmod_low_data(ret) return ret +def sls_exists(mods, test=None, queue=None, **kwargs): + """ + Tests for the existence the of a specific SLS or list of SLS files on the + master. Similar to :py:func:`state.show_sls `, + rather than returning state details, returns True or False. The default + environment is ``base``, use ``saltenv`` to specify a different environment. + + .. versionadded:: 3007.1.1 + + saltenv + Specify a salt fileserver environment from which to look for the SLS files + specified in the ``mods`` argument + + CLI Example: + + .. code-block:: bash + + salt '*' state.sls_exists core,edit.vim saltenv=dev + """ + return isinstance(show_sls(mods, test=test, queue=queue, **kwargs), dict) + + def show_top(**kwargs): """ diff --git a/tests/integration/ssh/test_state.py b/tests/integration/ssh/test_state.py index 8cabc98d76b7..d56e35e08b9b 100644 --- a/tests/integration/ssh/test_state.py +++ b/tests/integration/ssh/test_state.py @@ -122,6 +122,16 @@ def test_state_show_sls(self): check_file = self.run_function("file.file_exists", [SSH_SLS_FILE], wipe=False) self.assertFalse(check_file) + def test_state_sls_exists(self): + """ + test state.sls_exists with salt-ssh + """ + ret = self.run_function("state.sls_exists", [SSH_SLS]) + self.assertTrue(ret) + + check_file = self.run_function("file.file_exists", [SSH_SLS_FILE], wipe=False) + self.assertFalse(check_file) + def test_state_show_top(self): """ test state.show_top with salt-ssh