Repository: ambari Updated Branches: refs/heads/branch-2.2 d24e3d02f -> e540e5c60
AMBARI-16199. Improve output of command execution retry logic on agents. (Daniel Gergely via stoader) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e540e5c6 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e540e5c6 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e540e5c6 Branch: refs/heads/branch-2.2 Commit: e540e5c606c67a00bafc62b89a1aaedaa36f8172 Parents: d24e3d0 Author: Daniel Gergely <[email protected]> Authored: Tue May 3 07:13:54 2016 +0200 Committer: Toader, Sebastian <[email protected]> Committed: Tue May 3 07:13:54 2016 +0200 ---------------------------------------------------------------------- .../src/main/python/ambari_agent/ActionQueue.py | 7 ++++++- .../src/test/python/ambari_agent/TestActionQueue.py | 14 +++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e540e5c6/ambari-agent/src/main/python/ambari_agent/ActionQueue.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py index 0734bd7..d73f5a1 100644 --- a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py +++ b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py @@ -171,7 +171,7 @@ class ActionQueue(threading.Thread): t.start() else: self.process_command(command) - break; + break pass pass except (Queue.Empty): @@ -315,12 +315,17 @@ class ActionQueue(threading.Thread): if delay > retryDuration: delay = retryDuration retryDuration -= delay # allow one last attempt + commandresult['stderr'] += "\n\nCommand failed. Retrying command execution ...\n\n" logger.info("Retrying command id {cid} after a wait of {delay}".format(cid=taskId, delay=delay)) time.sleep(delay) continue else: break + # final result to stdout + commandresult['stdout'] += '\n\nCommand completed successfully!\n' if status == self.COMPLETED_STATUS else '\n\nCommand failed after ' + str(numAttempts) + ' tries\n' + logger.info('Command {cid} completed successfully!'.format(cid=taskId) if status == self.COMPLETED_STATUS else 'Command {cid} failed after {attempts} tries'.format(cid=taskId, attempts=numAttempts)) + roleResult = self.commandStatuses.generate_report_template(command) roleResult.update({ 'stdout': commandresult['stdout'], http://git-wip-us.apache.org/repos/asf/ambari/blob/e540e5c6/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py index ffb6419..c146782 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py +++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py @@ -371,7 +371,7 @@ class TestActionQueue(TestCase): expected = {'status': 'COMPLETED', 'configurationTags': {'global': {'tag': 'v123'}}, 'stderr': 'stderr', - 'stdout': 'out', + 'stdout': 'out\n\nCommand completed successfully!\n', 'clusterName': u'cc', 'structuredOut': '""', 'roleCommand': u'CUSTOM_COMMAND', @@ -540,7 +540,7 @@ class TestActionQueue(TestCase): configname = os.path.join(tempdir, 'config.json') expected = {'status': 'COMPLETED', 'stderr': 'stderr', - 'stdout': 'out', + 'stdout': 'out\n\nCommand completed successfully!\n', 'clusterName': u'cc', 'structuredOut': '""', 'roleCommand': u'INSTALL', @@ -579,7 +579,7 @@ class TestActionQueue(TestCase): # check report expected = {'status': 'FAILED', 'stderr': 'stderr', - 'stdout': 'out', + 'stdout': 'out\n\nCommand completed successfully!\n\n\nCommand failed after 1 tries\n', 'clusterName': u'cc', 'structuredOut': '""', 'roleCommand': u'INSTALL', @@ -611,7 +611,7 @@ class TestActionQueue(TestCase): # check report expected = {'status': 'COMPLETED', 'stderr': 'stderr', - 'stdout': 'out', + 'stdout': 'out\n\nCommand completed successfully!\n\n\nCommand failed after 1 tries\n\n\nCommand completed successfully!\n', 'clusterName': 'clusterName', 'structuredOut': '""', 'roleCommand': 'UPGRADE', @@ -655,7 +655,7 @@ class TestActionQueue(TestCase): expected = {'status': 'COMPLETED', 'configurationTags': {'global': {'tag': 'v123'}}, 'stderr': 'stderr', - 'stdout': 'out', + 'stdout': 'out\n\nCommand completed successfully!\n', 'clusterName': u'cc', 'structuredOut': '""', 'roleCommand': u'CUSTOM_COMMAND', @@ -697,7 +697,7 @@ class TestActionQueue(TestCase): expected = {'status': 'COMPLETED', 'configurationTags': {'global': {'tag': 'v123'}}, 'stderr': 'stderr', - 'stdout': 'out', + 'stdout': 'out\n\nCommand completed successfully!\n', 'clusterName': u'cc', 'structuredOut': '""', 'roleCommand': u'CUSTOM_COMMAND', @@ -988,7 +988,7 @@ class TestActionQueue(TestCase): 'structuredOut': '', 'status': 'FAILED' } - time_mock.side_effect = [4, 8, 10, 14, 18, 22] + time_mock.side_effect = [4, 8, 10, 14, 18, 22, 26] def side_effect(command, tmpoutfile, tmperrfile, override_output_files=True, retry=False): return python_execution_result_dict
