Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 55fe5c494 -> b30b49be4


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/b30b49be
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b30b49be
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b30b49be

Branch: refs/heads/branch-2.2
Commit: b30b49be478c7048b1eaf34fe8af43fc42966090
Parents: 55fe5c4
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:33:54 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/b30b49be/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 b914064..4d4103e 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/b30b49be/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 55b2f8f..43d878b 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/b30b49be/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 719d05d..466c3a8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
@@ -322,6 +322,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):

Reply via email to