Skip to content

Commit

Permalink
Allow explicit reboot on transactional minions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-czernek committed Apr 18, 2024
1 parent 4ec5c8b commit 3c06882
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions salt/modules/transactional_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,30 @@ def call(function, *args, **kwargs):
else:
return local
except ValueError:
return {"result": False, "retcode": 1, "comment": ret_stdout}
local = {"result": False, "retcode": 1, "comment": ret_stdout}
return local
finally:
# Check if reboot is needed
if activate_transaction and pending_transaction():
if (activate_transaction and pending_transaction()) or _user_specified_reboot(
local
):
reboot()


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

explicit_reboot_cmds = ["reboot", "init 6", "shutdown -r", "shutdown --reboot"]
names = []
for _, value in local.items():
if isinstance(value, dict) and "name" in value:
names.append(value["name"])
# Partial match reboot_cmds to names, so that e.g. "reboot" matches "system.reboot"
return any([cmd in name for cmd in explicit_reboot_cmds for name in names])


def apply_(mods=None, **kwargs):
"""Apply an state inside a transaction.
Expand Down

0 comments on commit 3c06882

Please sign in to comment.