Updated Branches: refs/heads/trunk dd33e55e5 -> 5317b35d0
AMBARI-3068. Warning messages not cleared when task fails. (Artem Baranchuk via odiachenko) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/5317b35d Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/5317b35d Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/5317b35d Branch: refs/heads/trunk Commit: 5317b35d0f1e9efef316ff3cb1b4a7fcac8ad279 Parents: dd33e55 Author: Oleksandr Diachenko <[email protected]> Authored: Mon Sep 2 17:25:55 2013 +0300 Committer: Oleksandr Diachenko <[email protected]> Committed: Mon Sep 2 17:25:55 2013 +0300 ---------------------------------------------------------------------- ambari-agent/src/main/python/ambari_agent/Grep.py | 11 ++++++++++- .../src/main/python/ambari_agent/PuppetExecutor.py | 2 ++ ambari-agent/src/test/python/TestGrep.py | 9 +++++++++ ambari-agent/src/test/python/TestPuppetExecutor.py | 8 ++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/5317b35d/ambari-agent/src/main/python/ambari_agent/Grep.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/Grep.py b/ambari-agent/src/main/python/ambari_agent/Grep.py index 936b2f1..fcd7b1f 100644 --- a/ambari-agent/src/main/python/ambari_agent/Grep.py +++ b/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. http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/5317b35d/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py b/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py index eb74472..f7afc8a 100644 --- a/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py +++ b/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 http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/5317b35d/ambari-agent/src/test/python/TestGrep.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/TestGrep.py b/ambari-agent/src/test/python/TestGrep.py index 108f22a..5163312 100644 --- a/ambari-agent/src/test/python/TestGrep.py +++ b/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.') + http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/5317b35d/ambari-agent/src/test/python/TestPuppetExecutor.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/TestPuppetExecutor.py b/ambari-agent/src/test/python/TestPuppetExecutor.py index dc60e84..5c029cb 100644 --- a/ambari-agent/src/test/python/TestPuppetExecutor.py +++ b/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())
