Repository: ambari Updated Branches: refs/heads/trunk 5994e0ad0 -> ea894ef80
AMBARI-15594. Enabling logging of commands breaks execution commands (magyari_sandor) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ea894ef8 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ea894ef8 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ea894ef8 Branch: refs/heads/trunk Commit: ea894ef80f7400c4e583673a1f75f66008975f7e Parents: 5994e0a Author: Sandor Magyari <smagy...@hortonworks.com> Authored: Sat Mar 26 17:09:24 2016 +0200 Committer: Sandor Magyari <smagy...@hortonworks.com> Committed: Mon Mar 28 23:41:41 2016 +0300 ---------------------------------------------------------------------- .../src/main/python/ambari_agent/ActionQueue.py | 11 ++--- .../main/python/ambari_agent/AmbariConfig.py | 3 ++ .../test/python/ambari_agent/TestActionQueue.py | 43 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/ea894ef8/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 f29250b..6f98661 100644 --- a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py +++ b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py @@ -313,19 +313,20 @@ class ActionQueue(threading.Thread): 'status': status, }) - if self.config.has_option("logging","log_command_executes"): + if self.config.has_option("logging","log_command_executes") and int(self.config.get("logging", + "log_command_executes")) == 1: if roleResult['stdout'] != '': - logger.info("Begin command output log for command with id = " + command['taskId'] + ", role = " + logger.info("Begin command output log for command with id = " + str(command['taskId']) + ", role = " + command['role'] + ", roleCommand = " + command['roleCommand']) logger.info(roleResult['stdout']) - logger.info("End command output log for command with id = " + command['taskId'] + ", role = " + logger.info("End command output log for command with id = " + str(command['taskId']) + ", role = " + command['role'] + ", roleCommand = " + command['roleCommand']) if roleResult['stderr'] != '': - logger.info("Begin command stderr log for command with id = " + command['taskId'] + ", role = " + logger.info("Begin command stderr log for command with id = " + str(command['taskId']) + ", role = " + command['role'] + ", roleCommand = " + command['roleCommand']) logger.info(roleResult['stderr']) - logger.info("End command stderr log for command with id = " + command['taskId'] + ", role = " + logger.info("End command stderr log for command with id = " + str(command['taskId']) + ", role = " + command['role'] + ", roleCommand = " + command['roleCommand']) if roleResult['stdout'] == '': http://git-wip-us.apache.org/repos/asf/ambari/blob/ea894ef8/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py index 7ce5b2b..f849fd1 100644 --- a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py +++ b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py @@ -63,6 +63,9 @@ state_interval = 6 dirs={ps}etc{ps}hadoop,{ps}etc{ps}hadoop{ps}conf,{ps}var{ps}run{ps}hadoop,{ps}var{ps}log{ps}hadoop log_lines_count=300 +[logging] +log_command_executes = 0 + """.format(ps=os.sep) http://git-wip-us.apache.org/repos/asf/ambari/blob/ea894ef8/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 aa9533a..56ba263 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py +++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py @@ -317,6 +317,49 @@ class TestActionQueue(TestCase): self.assertTrue(print_exc_mock.called) @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)) + @patch.object(CustomServiceOrchestrator, "runCommand") + @patch("CommandStatusDict.CommandStatusDict") + @patch.object(ActionQueue, "status_update_callback") + def test_log_execution_commands(self, status_update_callback_mock, + command_status_dict_mock, + cso_runCommand_mock): + custom_service_orchestrator_execution_result_dict = { + 'stdout': 'out', + 'stderr': 'stderr', + 'structuredOut' : '', + 'exitcode' : 0 + } + cso_runCommand_mock.return_value = custom_service_orchestrator_execution_result_dict + + config = AmbariConfig() + tempdir = tempfile.gettempdir() + config.set('agent', 'prefix', tempdir) + config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache") + config.set('agent', 'tolerate_download_failures', "true") + config.set('logging', 'log_command_executes', 1) + dummy_controller = MagicMock() + actionQueue = ActionQueue(config, dummy_controller) + actionQueue.execute_command(self.datanode_restart_command) + report = actionQueue.result() + expected = {'status': 'COMPLETED', + 'configurationTags': {'global': {'tag': 'v123'}}, + 'stderr': 'stderr', + 'stdout': 'out', + 'clusterName': u'cc', + 'structuredOut': '""', + 'roleCommand': u'CUSTOM_COMMAND', + 'serviceName': u'HDFS', + 'role': u'DATANODE', + 'actionId': '1-1', + 'taskId': 9, + 'customCommand': 'RESTART', + 'exitCode': 0} + # Agent caches configurationTags if custom_command RESTART completed + self.assertEqual(len(report['reports']), 1) + self.assertEqual(expected, report['reports'][0]) + + + @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)) @patch("__builtin__.open") @patch.object(ActionQueue, "status_update_callback") def test_auto_execute_command(self, status_update_callback_mock, open_mock):