From 36b0a0dfe112890c7e5fe05ee5acc43a68d5ca9f Mon Sep 17 00:00:00 2001 From: vzhestkov Date: Fri, 20 Oct 2023 14:11:18 +0200 Subject: [PATCH 1/3] Dereference symlinks to set proper __cli --- salt/config/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/salt/config/__init__.py b/salt/config/__init__.py index 48599f123e62..14aa7061a923 100644 --- a/salt/config/__init__.py +++ b/salt/config/__init__.py @@ -3762,7 +3762,9 @@ def apply_minion_config( ) opts["fileserver_backend"][idx] = new_val - opts["__cli"] = salt.utils.stringutils.to_unicode(os.path.basename(sys.argv[0])) + opts["__cli"] = salt.utils.stringutils.to_unicode( + os.path.basename(salt.utils.path.expand(sys.argv[0])) + ) # No ID provided. Will getfqdn save us? using_ip_for_id = False @@ -3964,7 +3966,9 @@ def apply_master_config(overrides=None, defaults=None): ) opts["keep_acl_in_token"] = True - opts["__cli"] = salt.utils.stringutils.to_unicode(os.path.basename(sys.argv[0])) + opts["__cli"] = salt.utils.stringutils.to_unicode( + os.path.basename(salt.utils.path.expand(sys.argv[0])) + ) if "environment" in opts: if opts["saltenv"] is not None: From 2ad6ffc94296f64cbf0d5d6c9b7313429da38ab3 Mon Sep 17 00:00:00 2001 From: vzhestkov Date: Fri, 20 Oct 2023 14:21:50 +0200 Subject: [PATCH 2/3] Add changelog entry --- changelog/65435.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/65435.fixed.md diff --git a/changelog/65435.fixed.md b/changelog/65435.fixed.md new file mode 100644 index 000000000000..5fa532891d33 --- /dev/null +++ b/changelog/65435.fixed.md @@ -0,0 +1 @@ +Dereference symlinks to set proper __cli opt From 6c6a6f4c92fd5fe055bdd5850f6f1ed83d8389f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= Date: Mon, 13 Nov 2023 12:29:45 +0000 Subject: [PATCH 3/3] Add unit tests to check path is expanded --- tests/pytests/unit/config/test_master_config.py | 12 ++++++++++++ tests/pytests/unit/config/test_minion_config.py | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/pytests/unit/config/test_minion_config.py diff --git a/tests/pytests/unit/config/test_master_config.py b/tests/pytests/unit/config/test_master_config.py index 527f944e0eaa..5de8cd18c9fd 100644 --- a/tests/pytests/unit/config/test_master_config.py +++ b/tests/pytests/unit/config/test_master_config.py @@ -1,4 +1,5 @@ import salt.config +from tests.support.mock import MagicMock, patch def test_apply_no_cluster_id(): @@ -60,3 +61,14 @@ def test_apply_for_cluster(): assert isinstance(opts["cluster_peers"], list) opts["cluster_peers"].sort() assert ["127.0.0.1", "127.0.0.3"] == opts["cluster_peers"] + + +def test___cli_path_is_expanded(): + defaults = salt.config.DEFAULT_MASTER_OPTS.copy() + overrides = {} + with patch( + "salt.utils.path.expand", MagicMock(return_value="/path/to/testcli") + ) as expand_mock: + opts = salt.config.apply_master_config(overrides, defaults) + assert expand_mock.called + assert opts["__cli"] == "testcli" diff --git a/tests/pytests/unit/config/test_minion_config.py b/tests/pytests/unit/config/test_minion_config.py new file mode 100644 index 000000000000..34aa84daa74b --- /dev/null +++ b/tests/pytests/unit/config/test_minion_config.py @@ -0,0 +1,13 @@ +import salt.config +from tests.support.mock import MagicMock, patch + + +def test___cli_path_is_expanded(): + defaults = salt.config.DEFAULT_MINION_OPTS.copy() + overrides = {} + with patch( + "salt.utils.path.expand", MagicMock(return_value="/path/to/testcli") + ) as expand_mock: + opts = salt.config.apply_minion_config(overrides, defaults) + assert expand_mock.called + assert opts["__cli"] == "testcli"