Repository: ambari Updated Branches: refs/heads/trunk 9cb0cc07a -> 47ab1426e
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/47ab1426 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/47ab1426 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/47ab1426 Branch: refs/heads/trunk Commit: 47ab1426e6e1f13a794ec0a7e73fdbfec8339192 Parents: 9cb0cc0 Author: Andrew Onishuk <aonis...@hortonworks.com> Authored: Mon Nov 9 18:59:23 2015 +0200 Committer: Andrew Onishuk <aonis...@hortonworks.com> Committed: Mon Nov 9 18:59:23 2015 +0200 ---------------------------------------------------------------------- .../src/main/python/ambari_agent/Hardware.py | 11 ++++++---- .../src/main/python/ambari_agent/main.py | 22 ++++++++++---------- .../src/test/python/ambari_agent/TestMain.py | 4 ++-- 3 files changed, 20 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/47ab1426/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/47ab1426/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 72f9b04..74697c5 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() alerts_logger = logging.getLogger('ambari_alerts') @@ -58,20 +59,16 @@ IS_LINUX = platform.system() == "Linux" SYSLOG_FORMAT_STRING = ' ambari_agent - %(filename)s - [%(process)d] - %(name)s - %(levelname)s - %(message)s' SYSLOG_FORMATTER = logging.Formatter(SYSLOG_FORMAT_STRING) -def setup_logging(logger, filename, verbose): +def setup_logging(logger, filename, logging_level): formatter = logging.Formatter(formatstr) rotateLog = logging.handlers.RotatingFileHandler(filename, "a", 10000000, 25) rotateLog.setFormatter(formatter) logger.addHandler(rotateLog) - if verbose: - logging.basicConfig(format=formatstr, level=logging.DEBUG, filename=filename) - logger.setLevel(logging.DEBUG) - logger.info("loglevel=logging.DEBUG") - else: - logging.basicConfig(format=formatstr, level=logging.INFO, filename=filename) - logger.setLevel(logging.INFO) - logger.info("loglevel=logging.INFO") + logging.basicConfig(format=formatstr, level=logging_level, filename=filename) + logger.setLevel(logging_level) + logger.info("loglevel=logging.{0}".format(logging._levelNames[logging_level])) + def add_syslog_handler(logger): @@ -235,10 +232,13 @@ def main(heartbeat_stop_callback=None): expected_hostname = options.expected_hostname - setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), options.verbose) + logging_level = logging.DEBUG if options.verbose else logging.INFO + + setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), logging_level) global is_logger_setup is_logger_setup = True - setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), options.verbose) + setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), 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/47ab1426/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 d921b54..696e597 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestMain.py +++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py @@ -81,7 +81,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(logging.getLogger(), '/var/log/ambari-agent/ambari-agent.log', False) + main.setup_logging(logging.getLogger(), '/var/log/ambari-agent/ambari-agent.log', 20) self.assertTrue(addHandler_mock.called) setLevel_mock.assert_called_with(logging.INFO) @@ -89,7 +89,7 @@ class TestMain(unittest.TestCase): setLevel_mock.reset_mock() # Testing verbose mode - main.setup_logging(logging.getLogger(), '/var/log/ambari-agent/ambari-agent.log', True) + main.setup_logging(logging.getLogger(), '/var/log/ambari-agent/ambari-agent.log', 10) self.assertTrue(addHandler_mock.called) setLevel_mock.assert_called_with(logging.DEBUG)