This is an automated email from the ASF dual-hosted git repository.

jialiang pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 91c885add0 AMBARI-26241: _threadlocal has no uid because it is always 
None #3898
91c885add0 is described below

commit 91c885add0f424e4561a0a56bac9510659dff7f4
Author: Peng Lu <[email protected]>
AuthorDate: Fri Nov 29 08:58:15 2024 +0800

    AMBARI-26241: _threadlocal has no uid because it is always None #3898
---
 ambari-agent/src/test/python/ambari_agent/TestShell.py | 6 ++++++
 ambari-common/src/main/python/ambari_commons/shell.py  | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ambari-agent/src/test/python/ambari_agent/TestShell.py 
b/ambari-agent/src/test/python/ambari_agent/TestShell.py
index 3bd6e0bf7d..ed78a01d3c 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestShell.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestShell.py
@@ -23,6 +23,7 @@ import signal
 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
@@ -144,3 +145,8 @@ class TestShell(unittest.TestCase):
     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)
\ No newline at end of file
diff --git a/ambari-common/src/main/python/ambari_commons/shell.py 
b/ambari-common/src/main/python/ambari_commons/shell.py
index 1a19c62221..5ec162982d 100644
--- a/ambari-common/src/main/python/ambari_commons/shell.py
+++ b/ambari-common/src/main/python/ambari_commons/shell.py
@@ -823,7 +823,8 @@ class shellRunnerLinux(shellRunner):
         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}")
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to