mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #52477 from bloomberg/win_cmd_2019
2019.2 backport #52472 modules.cmdmod: handle windows environ better
This commit is contained in:
commit
7c709cfb57
2 changed files with 20 additions and 2 deletions
|
@ -570,7 +570,11 @@ def _run(cmd,
|
|||
run_env = env
|
||||
|
||||
else:
|
||||
run_env = os.environ.copy()
|
||||
if salt.utils.platform.is_windows():
|
||||
import nt
|
||||
run_env = nt.environ.copy()
|
||||
else:
|
||||
run_env = os.environ.copy()
|
||||
run_env.update(env)
|
||||
|
||||
if prepend_path:
|
||||
|
@ -3284,7 +3288,12 @@ def shell_info(shell, list_modules=False):
|
|||
# salt-call will general have home set, the salt-minion service may not
|
||||
# We need to assume ports of unix shells to windows will look after
|
||||
# themselves in setting HOME as they do it in many different ways
|
||||
newenv = os.environ
|
||||
if salt.utils.platform.is_windows():
|
||||
import nt
|
||||
newenv = nt.environ
|
||||
else:
|
||||
newenv = os.environ
|
||||
|
||||
if ('HOME' not in newenv) and (not salt.utils.platform.is_windows()):
|
||||
newenv['HOME'] = os.path.expanduser('~')
|
||||
log.debug('HOME environment set to %s', newenv['HOME'])
|
||||
|
|
|
@ -403,3 +403,12 @@ class CMDModuleTest(ModuleCase):
|
|||
self.assertIn('administrator', cmd)
|
||||
else:
|
||||
self.assertEqual('root', cmd)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_windows(), 'minion is not windows')
|
||||
def test_windows_env_handling(self):
|
||||
'''
|
||||
Ensure that nt.environ is used properly with cmd.run*
|
||||
'''
|
||||
out = self.run_function('cmd.run', ['set'], env={"abc": "123", "ABC": "456"}).splitlines()
|
||||
self.assertIn('abc=123', out)
|
||||
self.assertIn('ABC=456', out)
|
||||
|
|
Loading…
Add table
Reference in a new issue