Merge pull request #46796 from terminalmage/issue46779

Fix regression introduced in merge-forward
This commit is contained in:
Nicole Thomas 2018-04-02 14:10:21 -04:00 committed by GitHub
commit 4f31c1062d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -443,7 +443,7 @@ def _run(cmd,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE
).communicate(salt.utils.stringutils.to_bytes(py_code))[0]
).communicate(salt.utils.stringutils.to_bytes(py_code))
marker_count = env_bytes.count(marker_b)
if marker_count == 0:
# Possibly PAM prevented the login
@ -482,10 +482,11 @@ def _run(cmd,
if env_runas.get('USER') != runas:
env_runas['USER'] = runas
env = env_runas
except ValueError:
except ValueError as exc:
log.exception('Error raised retrieving environment for user %s', runas)
raise CommandExecutionError(
'Environment could not be retrieved for User \'{0}\''.format(
runas
'Environment could not be retrieved for user \'{0}\': {1}'.format(
runas, exc
)
)

View file

@ -15,9 +15,11 @@ from tests.support.helpers import (
skip_if_not_root
)
from tests.support.paths import TMP
from tests.support.unit import skipIf
# Import salt libs
import salt.utils.path
import salt.utils.platform
# Import 3rd-party libs
from salt.ext import six
@ -266,6 +268,15 @@ class CMDModuleTest(ModuleCase):
runas=runas).strip()
self.assertEqual(result, expected_result)
@skipIf(salt.utils.platform.is_windows(), 'minion is windows')
@skip_if_not_root
def test_runas(self):
'''
Ensure that the env is the runas user's
'''
out = self.run_function('cmd.run', ['env'], runas='nobody').splitlines()
self.assertIn('USER=nobody', out)
def test_timeout(self):
'''
cmd.run trigger timeout