You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2014/03/19 14:59:25 UTC
git commit: AMBARI-5138. Ambari deploy and unit test fails on Python
2.6.9 (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/trunk 0887d94eb -> b3408e387
AMBARI-5138. Ambari deploy and unit test fails on Python 2.6.9 (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b3408e38
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b3408e38
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b3408e38
Branch: refs/heads/trunk
Commit: b3408e38786cf1c269644ac9a17e2d9ee0862261
Parents: 0887d94
Author: Andrew Onischuk <ao...@hortonworks.com>
Authored: Sun Mar 16 12:48:20 2014 -0700
Committer: Andrew Onischuk <ao...@hortonworks.com>
Committed: Sun Mar 16 12:48:20 2014 -0700
----------------------------------------------------------------------
.../resource_management/core/exceptions.py | 2 ++
.../core/providers/system.py | 4 +--
.../python/resource_management/core/shell.py | 38 ++++++++++++++------
3 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/b3408e38/ambari-agent/src/main/python/resource_management/core/exceptions.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/exceptions.py b/ambari-agent/src/main/python/resource_management/core/exceptions.py
index 6a447d7..3c001cc 100644
--- a/ambari-agent/src/main/python/resource_management/core/exceptions.py
+++ b/ambari-agent/src/main/python/resource_management/core/exceptions.py
@@ -23,6 +23,8 @@ Ambari Agent
class Fail(Exception):
pass
+class ExecuteTimeoutException(Exception):
+ pass
class InvalidArgument(Fail):
pass
http://git-wip-us.apache.org/repos/asf/ambari/blob/b3408e38/ambari-agent/src/main/python/resource_management/core/providers/system.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/providers/system.py b/ambari-agent/src/main/python/resource_management/core/providers/system.py
index fee24be..33b9ad9 100644
--- a/ambari-agent/src/main/python/resource_management/core/providers/system.py
+++ b/ambari-agent/src/main/python/resource_management/core/providers/system.py
@@ -27,9 +27,9 @@ import os
import pwd
import time
import shutil
-from subprocess import TimeoutExpired
from resource_management.core import shell
from resource_management.core.base import Fail
+from resource_management.core import ExecuteTimeoutException
from resource_management.core.providers import Provider
from resource_management.core.logger import Logger
@@ -240,7 +240,7 @@ class ExecuteProvider(Provider):
else:
Logger.info("Retrying after %d seconds. Reason: %s" % (self.resource.try_sleep, str(ex)))
time.sleep(self.resource.try_sleep)
- except TimeoutExpired:
+ except ExecuteTimeoutException:
err_msg = ("Execution of '%s' was killed due timeout after %d seconds") % (self.resource.command, self.resource.timeout)
if self.resource.on_timeout:
http://git-wip-us.apache.org/repos/asf/ambari/blob/b3408e38/ambari-agent/src/main/python/resource_management/core/shell.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/shell.py b/ambari-agent/src/main/python/resource_management/core/shell.py
index 77f2a9c..63547e6 100644
--- a/ambari-agent/src/main/python/resource_management/core/shell.py
+++ b/ambari-agent/src/main/python/resource_management/core/shell.py
@@ -22,10 +22,12 @@ Ambari Agent
__all__ = ["checked_call", "call"]
-import subprocess
import pipes
-from subprocess import TimeoutExpired
+import subprocess
+import threading
+from multiprocessing import Queue
from exceptions import Fail
+from exceptions import ExecuteTimeoutException
from resource_management.core.logger import Logger
def checked_call(command, logoutput=False,
@@ -35,8 +37,7 @@ def checked_call(command, logoutput=False,
def call(command, logoutput=False,
cwd=None, env=None, preexec_fn=None, user=None, wait_for_finish=True, timeout=None):
return _call(command, logoutput, False, cwd, env, preexec_fn, user, wait_for_finish, timeout)
-
-
+
def _call(command, logoutput=False, throw_on_failure=True,
cwd=None, env=None, preexec_fn=None, user=None, wait_for_finish=True, timeout=None):
"""
@@ -65,13 +66,20 @@ def _call(command, logoutput=False, throw_on_failure=True,
if not wait_for_finish:
return None, None
-
- try:
- out = proc.communicate(timeout=timeout)[0].strip('\n')
- except TimeoutExpired as ex:
- proc.terminate()
- raise ex
+ if timeout:
+ q = Queue()
+ t = threading.Timer( timeout, on_timeout, [proc, q] )
+ t.start()
+ out = proc.communicate()[0].strip('\n')
+
+ if timeout:
+ if q.empty():
+ t.cancel()
+ # timeout occurred
+ else:
+ raise ExecuteTimeoutException()
+
code = proc.returncode
if logoutput and out:
@@ -81,4 +89,12 @@ def _call(command, logoutput=False, throw_on_failure=True,
err_msg = ("Execution of '%s' returned %d. %s") % (command[-1], code, out)
raise Fail(err_msg)
- return code, out
\ No newline at end of file
+ return code, out
+
+def on_timeout(proc, q):
+ q.put(True)
+ if proc.poll() == None:
+ try:
+ proc.terminate()
+ except:
+ pass
\ No newline at end of file