Updated Branches:
  refs/heads/trunk 66b1c1d56 -> ce40cfc7b

AMBARI-3947. Change PythonExecutor to invoke scripts using current runtime 
(dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ce40cfc7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ce40cfc7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ce40cfc7

Branch: refs/heads/trunk
Commit: ce40cfc7bdb08e67b0452471b666c065c523b25a
Parents: 66b1c1d
Author: Lisnichenko Dmitro <[email protected]>
Authored: Mon Dec 2 22:53:55 2013 +0200
Committer: Lisnichenko Dmitro <[email protected]>
Committed: Mon Dec 2 22:53:55 2013 +0200

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/PythonExecutor.py       | 11 ++++++-----
 .../src/test/python/ambari_agent/TestPythonExecutor.py   |  9 +++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ce40cfc7/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py 
b/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
index a716c84..b6b1c68 100644
--- a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
+++ b/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
@@ -23,7 +23,7 @@ import pprint
 import threading
 from threading import Thread
 from Grep import Grep
-import shell
+import shell, sys
 
 
 logger = logging.getLogger()
@@ -55,7 +55,7 @@ class PythonExecutor:
     """
     tmpout =  open(tmpoutfile, 'w')
     tmperr =  open(tmperrfile, 'w')
-    pythonCommand = self.pythonCommand(script, script_params)
+    pythonCommand = self.python_command(script, script_params)
     logger.info("Running command " + pprint.pformat(pythonCommand))
     process = self.launch_python_subprocess(pythonCommand, tmpout, tmperr)
     logger.debug("Launching watchdog thread")
@@ -92,9 +92,10 @@ class PythonExecutor:
   def isSuccessfull(self, returncode):
     return not self.python_process_has_been_killed and returncode == 0
 
-  def pythonCommand(self, script, script_params):
-    puppetcommand = ['python', script] + script_params
-    return puppetcommand
+  def python_command(self, script, script_params):
+    python_binary = sys.executable
+    python_command = [python_binary, script] + script_params
+    return python_command
 
   def condenseOutput(self, stdout, stderr, retcode):
     grep = self.grep

http://git-wip-us.apache.org/repos/asf/ambari/blob/ce40cfc7/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py 
b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
index c27c0f5..795105c 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
@@ -124,6 +124,15 @@ class TestPythonExecutor(TestCase):
     self.assertFalse(executor.isSuccessfull(1))
 
 
+  def test_python_command(self):
+    executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
+    command = executor.python_command("script", ["script_param1"])
+    self.assertEqual(3, len(command))
+    self.assertTrue("python" in command[0])
+    self.assertEquals("script", command[1])
+    self.assertEquals("script_param1", command[2])
+    pprint.pprint(command)
+
 
   class Subprocess_mockup():
     """

Reply via email to