From 3a8721bb51d3ddb37b3a154c51fd953cae4c8b77 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Sat, 30 Nov 2013 07:56:26 -0500 Subject: [PATCH] method extraction for readability extract out methods for readability, so the code has logical flow and the details about each conditional can be encapsulated in its own method. Change-Id: I5b62842346e0e3774d8e0586ff6b2c6969602a07 --- elastic_recheck/elasticRecheck.py | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/elastic_recheck/elasticRecheck.py b/elastic_recheck/elasticRecheck.py index 147580d3..ea0fca05 100755 --- a/elastic_recheck/elasticRecheck.py +++ b/elastic_recheck/elasticRecheck.py @@ -57,27 +57,41 @@ class Stream(object): if thread: self.gerrit.startWatching() - def _is_unit_test(self, line): - return "FAILURE" in line and ("python2" in line or "pep8" in line) + def _is_jenkins_failure(self, event): + """Is this comment a jenkins failure comment.""" + if event.get('type', '') != 'comment-added': + return False + + username = event['author'].get('username', '') + if (username != 'jenkins'): + return False + + return ("Build failed. For information on how to proceed" in + event['comment']) + + def _failed_unit_tests(self, line): + """Did we fail unit tests? If so not a valid failure.""" + fail = ("FAILURE" in line and ("python2" in line or "pep8" in line)) + if fail: + self.log.debug("Failed unit tests, skipping this result") + return fail + + def _valid_failure(self, line): + """Is this the kind of failure we track.""" + return "FAILURE" in line and "tempest-devstack" in line def get_failed_tempest(self): self.log.debug("entering get_failed_tempest") while True: event = self.gerrit.getEvent() - if event.get('type', '') != 'comment-added': - continue - username = event['author'].get('username', '') - if (username == 'jenkins' and - "Build failed. For information on how to proceed" in - event['comment']): + if self._is_jenkins_failure(event): self.log.debug("potential failed_tempest") found = False for line in event['comment'].split('\n'): - if self._is_unit_test(line): - # Unit Test Failure + if self._failed_unit_tests(line): found = False break - if "FAILURE" in line and "tempest-devstack" in line: + if self._valid_failure(line): url = [x for x in line.split() if "http" in x][0] if RequiredFiles.files_at_url(url): self.log.debug("All file present")