From fcc8003699d453b2c1ead8f58efd4052452750ac Mon Sep 17 00:00:00 2001 From: Twangboy Date: Fri, 24 Jan 2025 15:05:31 -0700 Subject: [PATCH] Clear the environment in the test --- salt/modules/cmdmod.py | 58 +++++++++---------- .../functional/modules/cmd/test_script.py | 3 +- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index 791ea3348b0..ee700bf4186 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -2943,38 +2943,34 @@ def _cleanup_tempfile(path): cmd_path = _cmd_quote(path, escape=False) else: cmd_path = path - if not env: - env = {} - if shell.lower() == "powershell": - mod_paths = [ - pathlib.Path( - rf'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules' - ), - pathlib.Path( - rf'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules' - ), - ] - else: - mod_paths = [ - pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\Modules'), - pathlib.Path( - rf'{os.getenv("ProgramFiles")}\PowerShell\6.0.0\Modules' - ), - pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\7\Modules'), - ] - ps_module_path = [ - pathlib.Path(x) for x in os.getenv("PSModulePath", "").split(";") - ] - for mod_path in mod_paths: - if mod_path.exists(): - if mod_path not in ps_module_path: - ps_module_path.append(mod_path) - mod_paths = "" - for mod_path in ps_module_path: - if mod_path: - mod_paths += f"{str(path)};" + # if not env: + # env = {} + # if shell.lower() == "powershell": + # mod_paths = [ + # pathlib.Path( + # rf'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules' + # ), + # pathlib.Path(rf'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules'), + # ] + # else: + # mod_paths = [ + # pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\Modules'), + # pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\6.0.0\Modules'), + # pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\7\Modules'), + # ] + # ps_module_path = [ + # pathlib.Path(x) for x in os.getenv("PSModulePath", "").split(";") + # ] + # for mod_path in mod_paths: + # if mod_path.exists(): + # if mod_path not in ps_module_path: + # ps_module_path.append(mod_path) + # mod_paths = "" + # for mod_path in ps_module_path: + # if mod_path: + # mod_paths += f"{str(path)};" # env.update({"PSModulePath": mod_paths}) - env.update({"PSModulePath": ""}) + # env.update({"PSModulePath": ""}) else: cmd_path = _cmd_quote(path) diff --git a/tests/pytests/functional/modules/cmd/test_script.py b/tests/pytests/functional/modules/cmd/test_script.py index 9b97a860fe0..b7093badfde 100644 --- a/tests/pytests/functional/modules/cmd/test_script.py +++ b/tests/pytests/functional/modules/cmd/test_script.py @@ -57,7 +57,8 @@ def test_windows_script_args_powershell(cmd, shell, issue_56195): ) script = "salt://issue-56195/test.ps1" - ret = cmd.script(source=script, args=args, shell=shell, saltenv="base") + ps_path = {"PSModulePath": ""} + ret = cmd.script(source=script, args=args, shell=shell, saltenv="base", env=ps_path) import_result = cmd.run("Import-Module Microsoft.PowerShell.Security", shell=shell) powershell_version = cmd.run("$PSVersionTable", shell=shell)