Ver código fonte

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

Lisnichenko Dmitro 11 anos atrás
pai
commit
ce40cfc7bd

+ 6 - 5
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

+ 9 - 0
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():
     """