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 2016/04/07 17:46:06 UTC
ambari git commit: AMBARI-15767. Ambari should report about slow sudo
hosts (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/trunk d17ea8be3 -> 73472dc1c
AMBARI-15767. Ambari should report about slow sudo hosts (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/73472dc1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/73472dc1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/73472dc1
Branch: refs/heads/trunk
Commit: 73472dc1cea0fdf00afa88d802048269483e2f91
Parents: d17ea8b
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Thu Apr 7 18:45:57 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Thu Apr 7 18:45:57 2016 +0300
----------------------------------------------------------------------
.../src/main/python/ambari_agent/main.py | 23 ++++++++++++++++++++
.../src/test/python/ambari_agent/TestMain.py | 4 +++-
2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/73472dc1/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 8146859..a448748 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -125,6 +125,27 @@ def resolve_ambari_config():
except Exception, err:
logger.warn(err)
+def check_sudo():
+ # don't need to check sudo for root.
+ if os.geteuid() == 0:
+ return
+
+ runner = shellRunner()
+ test_command = [AMBARI_SUDO_BINARY, '/usr/bin/test', '/']
+ test_command_str = ' '.join(test_command)
+
+ start_time = time.time()
+ res = runner.run(test_command)
+ end_time = time.time()
+ run_time = end_time - start_time
+
+ if res['exitCode'] != 0:
+ raise Exception("Please check your sudo configurations.\n" + test_command_str + " failed with " + res['error'] + res['output']) # bad sudo configurations
+
+ if run_time > 2:
+ logger.warn(("Sudo commands on this host are running slowly ('{0}' took {1} seconds).\n" +
+ "This will create a significant slow down for ambari-agent service tasks.").format(test_command_str, run_time))
+
def perform_prestart_checks(expected_hostname):
# Check if current hostname is equal to expected one (got from the server
@@ -158,6 +179,8 @@ def perform_prestart_checks(expected_hostname):
logger.error(msg)
print(msg)
sys.exit(1)
+
+ check_sudo()
def daemonize():
http://git-wip-us.apache.org/repos/asf/ambari/blob/73472dc1/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 c7cfb0a..23cdb13 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -155,12 +155,14 @@ class TestMain(unittest.TestCase):
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+ @patch("ambari_commons.shell.shellRunnerLinux.run")
@patch("sys.exit")
@patch("os.path.isfile")
@patch("os.path.isdir")
@patch("hostname.hostname")
- def test_perform_prestart_checks(self, hostname_mock, isdir_mock, isfile_mock, exit_mock):
+ def test_perform_prestart_checks(self, hostname_mock, isdir_mock, isfile_mock, exit_mock, shell_mock):
main.config = AmbariConfig().getConfig()
+ shell_mock.return_value = {"exitCode": 0}
# Check expected hostname test
hostname_mock.return_value = "test.hst"