Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ambari-agent/src/test/python/ambari_agent/TestShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from mock.mock import patch, MagicMock, call
from ambari_commons import shell
from ambari_commons import OSCheck
from ambari_commons.shell import shellRunnerLinux
from io import StringIO

ROOT_PID = 10
Expand Down Expand Up @@ -144,3 +145,8 @@ def test_kill_process_with_children_except_yum(self, os_kill_mock, os_list_dir_m
os_kill_pids = [item[0][0] for item in os_kill_mock.call_args_list]
self.assertEqual(len(os_kill_pids), 1)
self.assertEqual([10], os_kill_pids)

def test_shellRunnerLinux_run(self):
shell_runner = shellRunnerLinux()
result = shell_runner.run(["ls", "-l"])
self.assertTrue(shell_runner._threadLocal is None)
3 changes: 2 additions & 1 deletion ambari-common/src/main/python/ambari_commons/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ def run(self, script, user=None):
user = pwd.getpwnam(user)[2]
else:
user = os.getuid()
self._threadLocal.uid = user
if self._threadLocal is not None:
self._threadLocal.uid = user
except Exception as e:
_logger.warn(f"Unable to switch user for RUN_COMMAND. Error details: {e}")

Expand Down