浏览代码

AMBARI-3068. Warning messages not cleared when task fails. (Artem Baranchuk via odiachenko)

Oleksandr Diachenko 11 年之前
父节点
当前提交
5317b35d0f

+ 10 - 1
ambari-agent/src/main/python/ambari_agent/Grep.py

@@ -54,7 +54,16 @@ class Grep:
       result = lines[first_occurence - bound_a : first_occurence + after + 1]
     return "".join(result).strip()
 
-
+  def cleanByTemplate(self, string, template):
+    if string is not None:
+      stripped_string = string.strip()
+      lines = stripped_string.splitlines(True)
+      for line in lines[:]:
+        if template.lower() in line.lower():
+          lines.remove(line)
+      return "".join(lines).strip()
+    else:
+      return string
   def tail(self, string, n):
     """
     Copies last n lines from string to result. Also, string trim is performed.

+ 2 - 0
ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py

@@ -114,8 +114,10 @@ class PuppetExecutor:
       result = grep.tail(stdout, grep.OUTPUT_LAST_LINES)
     else:
       result = grep.grep(stdout, "fail", grep.ERROR_LAST_LINES_BEFORE, grep.ERROR_LAST_LINES_AFTER)
+      result = grep.cleanByTemplate(result, "warning")
       if result is None: # Second try
        result = grep.grep(stdout, "err", grep.ERROR_LAST_LINES_BEFORE, grep.ERROR_LAST_LINES_AFTER)
+       result = grep.cleanByTemplate(result, "warning")
     filteredresult = grep.filterMarkup(result)
     return filteredresult
 

+ 9 - 0
ambari-agent/src/test/python/TestGrep.py

@@ -105,4 +105,13 @@ debug: Processing report from ambari-dmi with processor Puppet::Reports::Store
   def tearDown(self):
     pass
 
+  def test_cleanByTemplate(self):
+    fragment = self.grep.cleanByTemplate(self.string_bad, "debug")
+    desired = """
+info: Applying configuration version '1352127563'
+err: /Stage[main]//Exec[command_good]/returns: change from notrun to 0 failed: wget e432423423xample.com/badurl444111 returned 4 instead of one of [0] at /root/puppet-learn/2-bad.pp:5
+notice: Finished catalog run in 0.23 seconds
+""".strip()
+    self.assertEquals(fragment, desired, 'Grep cleanByTemplate function should return string without debug lines.')
+
 

+ 6 - 2
ambari-agent/src/test/python/TestPuppetExecutor.py

@@ -163,11 +163,13 @@ class TestPuppetExecutor(TestCase):
     stripped_string = string_err.strip()
     lines = stripped_string.splitlines(True)
     d = lines[1:6]
+    d = grep.cleanByTemplate("".join(d).strip(), "warning").splitlines(True)
     result_check = True
     for l in d:
       result_check &= grep.filterMarkup(l) in result
     self.assertEquals(result_check, True, "Failed to condence fail log")
-    self.assertEquals(len(result.splitlines(True)), 6, "Failed to condence fail log")
+    self.assertEquals(('warning' in result.lower()), False, "Failed to condence fail log")
+    self.assertEquals(len(result.splitlines(True)), 5, "Failed to condence fail log")
 
   def test_condense_bad3(self):
     puppetexecutor = PuppetExecutor("/tmp", "/x", "/y", "/z", AmbariConfig().getConfig())
@@ -179,11 +181,13 @@ class TestPuppetExecutor(TestCase):
     lines = stripped_string.splitlines(True)
     #sys.stderr.write(result)
     d = lines[0:31]
+    d = grep.cleanByTemplate("".join(d).strip(), "warning").splitlines(True)
     result_check = True
     for l in d:
       result_check &= grep.filterMarkup(l) in result
     self.assertEquals(result_check, True, "Failed to condence fail log")
-    self.assertEquals(len(result.splitlines(True)), 33, "Failed to condence fail log")
+    self.assertEquals(('warning' in result.lower()), False, "Failed to condence fail log")
+    self.assertEquals(len(result.splitlines(True)), 19, "Failed to condence fail log")
 
   def test_condense_good(self):
     puppetexecutor = PuppetExecutor("/tmp", "/x", "/y", "/z", AmbariConfig().getConfig())