From a99510882a0945073a3dff205417007b176e456f Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Jun 20 2019 21:36:34 +0000 Subject: compose-tracker: support finding task id for failed failable tasks If a single arch of an image build fails (i.e. the image build fails for ppc64le, but succeeds for others) and that arch is failable then we'd never get the task ID in the opened issue because the task ID wasn't on the next line in the output. With this patch we parse through until we find the task ID and then return that. --- diff --git a/compose_tracker.py b/compose_tracker.py index f72cd6d..7d4b5d2 100755 --- a/compose_tracker.py +++ b/compose_tracker.py @@ -77,17 +77,47 @@ class Consumer(object): # Used for printing out a value when the day has changed self.date = datetime.date.today() - def get_supporting_text(self, line): + def get_supporting_text(self, lines): """ given a log file line determine if it has a koji task ID in it or not and give back an appropriate message """ - r = re.search('.*failed: (\d{8}).*', line) - if r: - taskid = r.group(1) - text = "- [%s](%s%s)\n" % (taskid, KOJI_TASK_URL, taskid) - else: + for line in lines: + line = line[20:] # trim date off log lines + + # If the form is a failed image build that is not failable + # then we'll get: + # [FAIL] Image build (variant AtomicHost, arch *, subvariant AtomicHost) failed, but going on anyway. + # ImageBuild task failed: 35659757. See /mnt/koji/compose/updates/Fedora-29-updates-testing-20190620.1/ + r = re.search('.*failed: (\d{8}).*', line) + if r: + taskid = r.group(1) + text = "- [%s](%s%s)" % (taskid, KOJI_TASK_URL, taskid) + break + + # If the form is a filed build that is failable will have to go + # through quite a few lines before we find the koji task id: + # [ERROR ] [FAIL] Image build (variant AtomicHost, arch ppc64le, subvariant AtomicHost) failed, but going on anyway. + # [IMAGE_BUILD ] [INFO ] Hardlinking /mnt/koji/packages/Fedora-AtomicHost/29_Update/20190620.1/... + # [IMAGE_BUILD ] [INFO ] Hardlinking /mnt/koji/packages/Fedora-AtomicHost/29_Update/20190620.1/... + # [IMAGE_BUILD ] [INFO ] Hardlinking /mnt/koji/packages/Fedora-AtomicHost/29_Update/20190620.1/... + # [IMAGE_BUILD ] [INFO ] [DONE ] Creating image (formats: qcow2-raw-xz, arches: aarch64-ppc64le-x86_64, variant: AtomicHost, subvariant: AtomicHost) (task id: 35659753) + r = re.search('.*\[DONE \].*task id: (\d{8}).*', line) + if r: + taskid = r.group(1) + text = "- [%s](%s%s)" % (taskid, KOJI_TASK_URL, taskid) + break + + # If we get to an end of a phase then stop searching + # [INFO ] [DONE ] ---------- PHASE: IMAGE_BUILD ---------- + r = re.search('.*\[DONE \] ---------- PHASE.*', line) + if r: + break + + kojitaskline = line + if not text: text = "- No Task ID, look at log statement\n" - return text + kojitaskline = None + return kojitaskline, text def __call__(self, message: fedora_messaging.api.Message): logger.debug(message.topic) @@ -142,14 +172,16 @@ class Consumer(object): # next line and add them in markdown format. Also grab # the taskid if we can and print a hyperlink to koji if re.search('\[FAIL\]', line): - content+= self.get_supporting_text(nextline) - content+= "```\n%s\n%s\n```\n\n" % (line, nextline) + kojitaskline, text = self.get_supporting_text(lines[x-1:]) + content+=f'{text}\n' + content+= "```\n%s\n%s\n```\n\n" % \ + (line, kojitaskline or nextline) # If this is the Compose run failed line, then add it # to the description too if re.search('.*Compose run failed.*', line): - content+= ("- Compose run failed because: %s\n" % - self.get_supporting_text(line)) + kojitaskline, text = self.get_supporting_text([line]) + content+= f'- Compose run failed because: {text}\n' content+= "```\n%s\n```\n" % (line) logger.debug(content)