Skip to content

Commit

Permalink
Execute function only in sls
Browse files Browse the repository at this point in the history
  • Loading branch information
m-czernek committed Apr 18, 2024
1 parent 89609c8 commit 7a7f7a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions salt/modules/transactional_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,14 +990,16 @@ def call(function, *args, **kwargs):
finally:
# Check if reboot is needed
if (activate_transaction and pending_transaction()) or (
not kwargs.get("test", False) and _user_specified_reboot(local)
not kwargs.get("test", False) and _user_specified_reboot(local, function)
):
reboot()


def _user_specified_reboot(local):
def _user_specified_reboot(local, function):
if function != "state.highstate" and function != "state.sls":
return False

if not isinstance(local, dict):
# Skip if execution is not state/highstate
return False

explicit_reboot_cmds = set(["reboot", "system.reboot"])
Expand Down
6 changes: 3 additions & 3 deletions tests/pytests/unit/modules/test_transactional_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def test_call_success_explicit_reboot():
with patch.dict(tu.__utils__, utils_mock), patch.dict(
tu.__salt__, salt_mock
), patch("salt.modules.transactional_update.reboot", reboot_mock):
tu.call("module.function", key="value")
tu.call("state.sls", key="value")
reboot_mock.assert_called_once()


Expand All @@ -549,7 +549,7 @@ def test_call_success_explicit_reboot_test():
with patch.dict(tu.__utils__, utils_mock), patch.dict(
tu.__salt__, salt_mock
), patch("salt.modules.transactional_update.reboot", reboot_mock):
tu.call("module.function", test="True")
tu.call("state.sls", test="True")
assert not reboot_mock.called


Expand All @@ -574,7 +574,7 @@ def test_call_fail_explicit_reboot():
with patch.dict(tu.__utils__, utils_mock), patch.dict(
tu.__salt__, salt_mock
), patch("salt.modules.transactional_update.reboot", reboot_mock):
tu.call("module.function", test="True")
tu.call("state.sls", test="True")
assert not reboot_mock.called


Expand Down

0 comments on commit 7a7f7a1

Please sign in to comment.