ambari git commit: AMBARI-9341 Failing to register hosts on Centos5
Repository: ambari Updated Branches: refs/heads/trunk 45d67f60f -> 5ff857cd2 AMBARI-9341 Failing to register hosts on Centos5 sys.exit() should never be braced in a try/except. The behavior changed in Python 2.5. See the doc. Replaced sys.exit() calls with return statements. Normalized the return data structures. Fixed unit tests Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5ff857cd Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5ff857cd Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5ff857cd Branch: refs/heads/trunk Commit: 5ff857cd2259c91286934ed522f54502d4f15fae Parents: 45d67f6 Author: Florian Barca Authored: Tue Feb 3 14:56:02 2015 -0800 Committer: Florian Barca Committed: Tue Feb 3 14:56:02 2015 -0800 -- ambari-server/src/main/python/setupAgent.py | 90 + ambari-server/src/test/python/TestSetupAgent.py | 190 +++ 2 files changed, 161 insertions(+), 119 deletions(-) -- http://git-wip-us.apache.org/repos/asf/ambari/blob/5ff857cd/ambari-server/src/main/python/setupAgent.py -- diff --git a/ambari-server/src/main/python/setupAgent.py b/ambari-server/src/main/python/setupAgent.py index b2c2d25..3595e2f 100755 --- a/ambari-server/src/main/python/setupAgent.py +++ b/ambari-server/src/main/python/setupAgent.py @@ -63,11 +63,13 @@ def configureAgent(server_hostname, user_run_as): """ Configure the agent so that it has all the configs knobs properly installed """ osCommand = ["sed", "-i.bak", "s/hostname=localhost/hostname=" + server_hostname + "/g", "/etc/ambari-agent/conf/ambari-agent.ini"] - execOsCommand(osCommand) + ret = execOsCommand(osCommand) + if ret['exitstatus'] != 0: +return ret osCommand = ["sed", "-i.bak", "s/run_as_user=.*$/run_as_user=" + user_run_as + "/g", "/etc/ambari-agent/conf/ambari-agent.ini"] - execOsCommand(osCommand) - return + ret = execOsCommand(osCommand) + return ret def runAgent(passPhrase, expected_hostname, user_run_as, verbose): os.environ[AMBARI_PASSPHRASE_VAR] = passPhrase @@ -75,18 +77,21 @@ def runAgent(passPhrase, expected_hostname, user_run_as, verbose): if verbose: vo = " -v" cmd = "su - %1s -c '/usr/sbin/ambari-agent restart --expected-hostname=%2s %3s'" % (user_run_as, expected_hostname, vo) - agent_retcode = subprocess.call(cmd, shell=True) + log = "" + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + p.communicate() + agent_retcode = p.returncode for i in range(3): time.sleep(1) ret = execOsCommand(["tail", "-20", "/var/log/ambari-agent/ambari-agent.log"]) -if (not ret is None) and (0 == ret['exitstatus']): +if (0 == ret['exitstatus']): try: log = ret['log'] except Exception: log = "Log not found" print log - return agent_retcode - return agent_retcode + break + return {"exitstatus": agent_retcode, "log": log} def tryStopAgent(): verbose = False @@ -160,15 +165,14 @@ def checkServerReachability(host, port): ret = {} s = socket.socket() try: - s.connect((host, port)) - return +s.connect((host, port)) +ret = {"exitstatus": 0, "log": ""} except Exception: - ret["exitstatus"] = 1 - ret["log"] = "Host registration aborted. Ambari Agent host cannot reach Ambari Server '" +\ +ret["exitstatus"] = 1 +ret["log"] = "Host registration aborted. Ambari Agent host cannot reach Ambari Server '" +\ host+":"+str(port) + "'. " +\ "Please check the network connectivity between the Ambari Agent host and the Ambari Server" - sys.exit(ret) - pass + return ret # Command line syntax help @@ -183,10 +187,10 @@ def checkServerReachability(host, port): def parseArguments(argv=None): if argv is None: # make sure that arguments was passed - sys.exit(1) +return {"exitstatus": 2, "log": "No arguments were passed"} args = argv[1:] # shift path to script if len(args) < 3: -sys.exit({"exitstatus": 1, "log": "Was passed not all required arguments"}) +return {"exitstatus": 1, "log": "Not all required arguments were passed"} expected_hostname = args[0] passPhrase = args[1] @@ -204,48 +208,62 @@ def parseArguments(argv=None): except (Exception): server_port = 8080 - return expected_hostname, passPhrase, hostname, user_run_as, projectVersion, server_port + parsed_args = (expected_hostname, passPhrase, hostname, user_run_as, projectVersion, server_port) + return {"exitstatus": 0, "log": "", "parsed_args": parsed_args} def run_setup(argv=None): # Parse passed arguments - expected_hostname, passPhrase, hostname, use
ambari git commit: AMBARI-9341 Failing to register hosts on Centos5
Repository: ambari Updated Branches: refs/heads/trunk 4cbf3a876 -> f27c22b0c AMBARI-9341 Failing to register hosts on Centos5 +Fixed the ambari_commons imports to only include the bare minimum required to function +Fixed the incompartibilities with Python 2.4 Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f27c22b0 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f27c22b0 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f27c22b0 Branch: refs/heads/trunk Commit: f27c22b0c57c1b48ba372abb0c0fa6b74f6eda0e Parents: 4cbf3a8 Author: Florian Barca Authored: Tue Jan 27 15:17:23 2015 -0800 Committer: Florian Barca Committed: Tue Jan 27 15:17:23 2015 -0800 -- .../src/main/python/ambari_agent/HostInfo.py| 22 +++- .../test/python/ambari_agent/TestHostInfo.py| 4 ++-- .../python/ambari_agent/TestRegistration.py | 2 +- .../src/main/python/ambari_commons/__init__.py | 5 + .../libraries/functions/packages_analyzer.py| 4 ++-- ambari-server/src/main/python/bootstrap.py | 15 +++-- ambari-server/src/main/python/setupAgent.py | 10 +++-- .../src/test/python/TestAmbariServer.py | 3 ++- 8 files changed, 30 insertions(+), 35 deletions(-) -- http://git-wip-us.apache.org/repos/asf/ambari/blob/f27c22b0/ambari-agent/src/main/python/ambari_agent/HostInfo.py -- diff --git a/ambari-agent/src/main/python/ambari_agent/HostInfo.py b/ambari-agent/src/main/python/ambari_agent/HostInfo.py index 7a1dbb7..2c707b2 100644 --- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py +++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py @@ -18,23 +18,25 @@ See the License for the specific language governing permissions and limitations under the License. ''' -import os import glob +import hostname import logging +import os import re -import time -import subprocess -import threading import shlex -import platform -import hostname -from HostCheckReportFileHandler import HostCheckReportFileHandler -from Hardware import Hardware -from ambari_commons import OSCheck, OSConst, Firewall -from resource_management.libraries.functions import packages_analyzer import socket +import subprocess +import time + +from ambari_commons import OSCheck, OSConst +from ambari_commons.firewall import Firewall from ambari_commons.os_family_impl import OsFamilyImpl +from resource_management.libraries.functions import packages_analyzer +from ambari_agent.Hardware import Hardware +from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler + + logger = logging.getLogger() # service cmd http://git-wip-us.apache.org/repos/asf/ambari/blob/f27c22b0/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py -- diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py index adeb798..c1b93d6 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py +++ b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py @@ -39,14 +39,14 @@ else: os_distro_value = ('win2012serverr2','6.3','WindowsServer') with patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)): + from ambari_commons.firewall import Firewall + from ambari_commons.os_check import OSCheck, OSConst from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler from ambari_agent.HostInfo import HostInfo, HostInfoLinux from ambari_agent.Hardware import Hardware from ambari_agent.AmbariConfig import AmbariConfig from resource_management.core.system import System - from ambari_commons import OSCheck, Firewall, FirewallChecks, OSConst from resource_management.libraries.functions import packages_analyzer - import ambari_commons @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)) class TestHostInfo(TestCase): http://git-wip-us.apache.org/repos/asf/ambari/blob/f27c22b0/ambari-agent/src/test/python/ambari_agent/TestRegistration.py -- diff --git a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py index 92e4b36..b7a7f89 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py +++ b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py @@ -26,9 +26,9 @@ from mock.mock import MagicMock from only_for_platform import not_for_platform, PLATFORM_WINDOWS with patch("platform.linux_distribution", return_value = ('Suse','11','Final')): + from ambari_commons.os_check import OSCheck