Repository: ambari Updated Branches: refs/heads/trunk 1b0387953 -> 7360a79b7
AMBARI-5957. Bootstrap API call says bootstrap is running even though all agents have installed and registered (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7360a79b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7360a79b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7360a79b Branch: refs/heads/trunk Commit: 7360a79b7add328d6befdebabe0a9d7009ac02ef Parents: 1b03879 Author: Lisnichenko Dmitro <[email protected]> Authored: Fri May 30 18:26:21 2014 +0300 Committer: Lisnichenko Dmitro <[email protected]> Committed: Fri May 30 18:27:08 2014 +0300 ---------------------------------------------------------------------- ambari-server/src/main/python/setupAgent.py | 26 ++++++++------------ ambari-server/src/test/python/TestSetupAgent.py | 8 +++++- 2 files changed, 17 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7360a79b/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 28651e7..17a1552 100755 --- a/ambari-server/src/main/python/setupAgent.py +++ b/ambari-server/src/main/python/setupAgent.py @@ -66,23 +66,17 @@ def runAgent(passPhrase, expected_hostname): os.environ[AMBARI_PASSPHRASE_VAR] = passPhrase agent_retcode = subprocess.call("/usr/sbin/ambari-agent restart --expected-hostname=" + expected_hostname, shell=True) - # need this, because, very rarely, - # main.py(ambari-agent) starts a bit later then it should be started - time.sleep(1) - try: + for i in range(3): + time.sleep(1) ret = execOsCommand(["tail", "-20", "/var/log/ambari-agent/ambari-agent.log"]) - try: - log = ret['log'] - except Exception: - log = "Log not found" - print log - if not 0 == ret['exitstatus']: - return ret['exitstatus'] - - return agent_retcode - except (Exception): - return 1 - + if (not ret is None) and (0 == ret['exitstatus']): + try: + log = ret['log'] + except Exception: + log = "Log not found" + print log + return agent_retcode + return agent_retcode def getOptimalVersion(initialProjectVersion): optimalVersion = initialProjectVersion http://git-wip-us.apache.org/repos/asf/ambari/blob/7360a79b/ambari-server/src/test/python/TestSetupAgent.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestSetupAgent.py b/ambari-server/src/test/python/TestSetupAgent.py index 508ae3f..0f5f5b7 100644 --- a/ambari-server/src/test/python/TestSetupAgent.py +++ b/ambari-server/src/test/python/TestSetupAgent.py @@ -67,18 +67,24 @@ class TestSetupAgent(TestCase): self.assertTrue(expected_hostname in cmdStr) self.assertEqual(ret, 0) self.assertTrue(sleep_mock.called) + self.assertEqual(execOsCommand_mock.call_count, 1) + execOsCommand_mock.reset_mock() # Key 'log' not found execOsCommand_mock.return_value = None ret = setup_agent.runAgent(passphrase, expected_hostname) cmdStr = str(call_mock.call_args_list[0][0]) self.assertTrue(expected_hostname in cmdStr) - self.assertEqual(ret, 1) + self.assertEqual(ret, 0) + self.assertEqual(execOsCommand_mock.call_count, 3) + execOsCommand_mock.reset_mock() # Retcode id not 0 + call_mock.return_value = 2 execOsCommand_mock.return_value = {'log': 'log', 'exitstatus': 2} ret = setup_agent.runAgent(passphrase, expected_hostname) cmdStr = str(call_mock.call_args_list[0][0]) self.assertTrue(expected_hostname in cmdStr) self.assertEqual(ret, 2) + execOsCommand_mock.reset_mock() @patch.object(setup_agent, 'getAvaliableAgentPackageVersions') @patch('common_functions.OSCheck.is_suse_family')
