Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 65e87e692 -> 101666b03


AMBARI-13795. Ambari Agent cannot talk to server if "test -w" command hangs 
(aonishuk)


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

Branch: refs/heads/branch-2.1
Commit: 101666b031a0040fa246e21e3123d237e9b9d753
Parents: 65e87e6
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Mon Nov 9 18:58:47 2015 +0200
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Mon Nov 9 18:58:47 2015 +0200

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/Hardware.py    | 11 +++++++----
 .../src/main/python/ambari_agent/main.py        | 20 +++++++++-----------
 .../src/test/python/ambari_agent/TestMain.py    |  4 ++--
 3 files changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/101666b0/ambari-agent/src/main/python/ambari_agent/Hardware.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Hardware.py 
b/ambari-agent/src/main/python/ambari_agent/Hardware.py
index 36b4f4b..17acdf2 100644
--- a/ambari-agent/src/main/python/ambari_agent/Hardware.py
+++ b/ambari-agent/src/main/python/ambari_agent/Hardware.py
@@ -21,6 +21,8 @@ limitations under the License.
 import os.path
 import logging
 import subprocess
+from resource_management.core.shell import call
+from resource_management.core.exceptions import ExecuteTimeoutException
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 from ambari_commons.shell import shellRunner
 from Facter import Facter
@@ -99,11 +101,12 @@ class Hardware:
 
   @staticmethod
   def _chk_mount(mountpoint):
-    if subprocess.call("{0} test -w '{1}'".format(AMBARI_SUDO_BINARY, 
mountpoint), shell=True) == 0:
-      return True
-    else:
+    try:
+      return call(['test', '-w', mountpoint], sudo=True, 
timeout=int(Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_DEFAULT)/2)[0] == 0
+    except ExecuteTimeoutException:
+      logger.exception("Exception happened while checking mount 
{0}".format(mountpoint))
       return False
-
+    
   @staticmethod
   @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
   def osdisks(config = None):

http://git-wip-us.apache.org/repos/asf/ambari/blob/101666b0/ambari-agent/src/main/python/ambari_agent/main.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py 
b/ambari-agent/src/main/python/ambari_agent/main.py
index fb5b4b1..b4ee0e2 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -45,6 +45,7 @@ from ambari_commons import shell
 import HeartbeatHandlers
 from HeartbeatHandlers import bind_signal_handlers
 from ambari_commons.constants import AMBARI_SUDO_BINARY
+from resource_management.core.logger import Logger
 logger = logging.getLogger()
 
 formatstr = "%(levelname)s %(asctime)s %(filename)s:%(lineno)d - %(message)s"
@@ -58,20 +59,15 @@ SYSLOG_FORMAT_STRING = ' ambari_agent - %(filename)s - 
[%(process)d] - %(name)s
 SYSLOG_FORMATTER = logging.Formatter(SYSLOG_FORMAT_STRING)
 
 
-def setup_logging(verbose):
+def setup_logging(logging_level):
   formatter = logging.Formatter(formatstr)
   rotateLog = 
logging.handlers.RotatingFileHandler(AmbariConfig.AmbariConfig.getLogFile(), 
"a", 10000000, 25)
   rotateLog.setFormatter(formatter)
   logger.addHandler(rotateLog)
       
-  if verbose:
-    logging.basicConfig(format=formatstr, level=logging.DEBUG, 
filename=AmbariConfig.AmbariConfig.getLogFile())
-    logger.setLevel(logging.DEBUG)
-    logger.info("loglevel=logging.DEBUG")
-  else:
-    logging.basicConfig(format=formatstr, level=logging.INFO, 
filename=AmbariConfig.AmbariConfig.getLogFile())
-    logger.setLevel(logging.INFO)
-    logger.info("loglevel=logging.INFO")
+  logging.basicConfig(format=formatstr, level=logging_level, 
filename=AmbariConfig.AmbariConfig.getLogFile())
+  logger.setLevel(logging_level)
+  
logger.info("loglevel=logging.{0}".format(logging._levelNames[logging_level]))
     
   global is_logger_setup
   is_logger_setup = True
@@ -237,8 +233,10 @@ def main(heartbeat_stop_callback=None):
   expected_hostname = options.expected_hostname
 
   current_user = getpass.getuser()
-
-  setup_logging(options.verbose)
+  
+  logging_level = logging.DEBUG if options.verbose else logging.INFO
+  setup_logging(logging_level)
+  Logger.initialize_logger('resource_management', logging_level=logging_level)
 
   default_cfg = {'agent': {'prefix': '/home/ambari'}}
   config.load(default_cfg)

http://git-wip-us.apache.org/repos/asf/ambari/blob/101666b0/ambari-agent/src/test/python/ambari_agent/TestMain.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestMain.py 
b/ambari-agent/src/test/python/ambari_agent/TestMain.py
index 8c8d347..3ffe4ab 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -86,7 +86,7 @@ class TestMain(unittest.TestCase):
   @patch("logging.basicConfig")
   def test_setup_logging(self, basicConfig_mock, rfh_mock, setLevel_mock, 
addHandler_mock):
     # Testing silent mode
-    main.setup_logging(False)
+    main.setup_logging(20)
     self.assertTrue(addHandler_mock.called)
     setLevel_mock.assert_called_with(logging.INFO)
 
@@ -94,7 +94,7 @@ class TestMain(unittest.TestCase):
     setLevel_mock.reset_mock()
 
     # Testing verbose mode
-    main.setup_logging(True)
+    main.setup_logging(10)
     self.assertTrue(addHandler_mock.called)
     setLevel_mock.assert_called_with(logging.DEBUG)
 

Reply via email to