Skip to content

Commit 8aed51c

Browse files
vzhestkovagraul
authored andcommitted
Use salt-call from salt bundle with transactional_update
* Use salt-call from the bundle with transactional_update * Add test checking which salt-call is selected by executable BACKPORT-UPSTREAM=saltstack#65204
1 parent 5dca269 commit 8aed51c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

salt/modules/transactional_update.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@
276276
"""
277277

278278
import logging
279+
import os.path
280+
import pathlib
281+
import sys
279282

280283
import salt.client.ssh.state
281284
import salt.client.ssh.wrapper.state
@@ -941,10 +944,18 @@ def call(function, *args, **kwargs):
941944
activate_transaction = kwargs.pop("activate_transaction", False)
942945

943946
try:
947+
# Set default salt-call command
948+
salt_call_cmd = "salt-call"
949+
python_exec_dir = os.path.dirname(sys.executable)
950+
if "venv-salt-minion" in pathlib.Path(python_exec_dir).parts:
951+
# If the module is executed with the Salt Bundle,
952+
# use salt-call from the Salt Bundle
953+
salt_call_cmd = os.path.join(python_exec_dir, "salt-call")
954+
944955
safe_kwargs = salt.utils.args.clean_kwargs(**kwargs)
945956
salt_argv = (
946957
[
947-
"salt-call",
958+
salt_call_cmd,
948959
"--out",
949960
"json",
950961
"-l",

tests/pytests/unit/modules/test_transactional_update.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,47 @@ def test_single_queue_true():
670670
"salt.modules.transactional_update.call", MagicMock(return_value="result")
671671
):
672672
assert tu.single("pkg.installed", name="emacs", queue=True) == "result"
673+
674+
675+
@pytest.mark.parametrize(
676+
"executable,salt_call_cmd",
677+
[
678+
("/usr/bin/python3", "salt-call"),
679+
(
680+
"/usr/lib/venv-salt-minion/bin/python",
681+
"/usr/lib/venv-salt-minion/bin/salt-call",
682+
),
683+
],
684+
)
685+
def test_call_which_salt_call_selected_with_executable(executable, salt_call_cmd):
686+
"""Test transactional_update.chroot which salt-call used"""
687+
utils_mock = {
688+
"json.find_json": MagicMock(return_value={"return": "result"}),
689+
}
690+
salt_mock = {
691+
"cmd.run_all": MagicMock(return_value={"retcode": 0, "stdout": ""}),
692+
}
693+
with patch("sys.executable", executable), patch.dict(
694+
tu.__utils__, utils_mock
695+
), patch.dict(tu.__salt__, salt_mock):
696+
assert tu.call("test.ping") == "result"
697+
698+
salt_mock["cmd.run_all"].assert_called_with(
699+
[
700+
"transactional-update",
701+
"--non-interactive",
702+
"--drop-if-no-change",
703+
"--no-selfupdate",
704+
"--continue",
705+
"--quiet",
706+
"run",
707+
salt_call_cmd,
708+
"--out",
709+
"json",
710+
"-l",
711+
"quiet",
712+
"--no-return-event",
713+
"--",
714+
"test.ping",
715+
]
716+
)

0 commit comments

Comments
 (0)