Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Add state.sls_exists to ssh client #66894

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/66894.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for state.sls_exists when using salt-ssh
22 changes: 22 additions & 0 deletions salt/client/ssh/wrapper/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,28 @@ def show_low_sls(mods, saltenv="base", test=None, **kwargs):
return ret


def sls_exists(mods, test=None, queue=None, **kwargs):
"""
Tests for the existence of a specific SLS or list of SLS files on the
master. Similar to :py:func:`state.show_sls <salt.modules.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:: 3008.0

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):
"""
Return the top data that the minion will use for a highstate
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ def show_sls(mods, test=None, queue=None, **kwargs):

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
Tests for the existence of a specific SLS or list of SLS files on the
master. Similar to :py:func:`state.show_sls <salt.modules.state.show_sls>`,
rather than returning state details, returns True or False. The default
environment is ``base``, use ``saltenv`` to specify a different environment.
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/ssh/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading