Skip to content

Commit 3f1e889

Browse files
committed
Use salt-call from the bundle with transactional_update
1 parent 8c50dda commit 3f1e889

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/saltext/transactional_update/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.exceptions
281284
import salt.utils.args
@@ -936,10 +939,18 @@ def call(function, *args, **kwargs):
936939
activate_transaction = kwargs.pop("activate_transaction", False)
937940

938941
try:
942+
# Set default salt-call command
943+
salt_call_cmd = "salt-call"
944+
python_exec_dir = os.path.dirname(sys.executable)
945+
if "venv-salt-minion" in pathlib.Path(python_exec_dir).parts:
946+
# If the module is executed with the Salt Bundle,
947+
# use salt-call from the Salt Bundle
948+
salt_call_cmd = os.path.join(python_exec_dir, "salt-call")
949+
939950
safe_kwargs = salt.utils.args.clean_kwargs(**kwargs)
940951
salt_argv = (
941952
[
942-
"salt-call",
953+
salt_call_cmd,
943954
"--out",
944955
"json",
945956
"-l",

tests/unit/modules/test_transactional_update.py

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

0 commit comments

Comments
 (0)