blob: 71b73f0940f03935835529715bc2cbf7eda6ec89 [file] [log] [blame]
Patrick Williamsac13d5f2023-11-24 18:59:46 -06001#!/usr/bin/env python3
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# patchtest: execute all unittest test cases discovered for a single patch
6# Note that this script is currently under development and has been
7# hard-coded with default values for testing purposes. This script
8# should not be used without changing the default recipient, at minimum.
9#
10# Copyright (C) 2023 BayLibre Inc.
11#
12# SPDX-License-Identifier: GPL-2.0-only
13#
14
15import argparse
16import boto3
17import configparser
18import mailbox
19import os
20import re
21import sys
22
23greeting = """Thank you for your submission. Patchtest identified one
24or more issues with the patch. Please see the log below for
25more information:\n\n---\n"""
26
27suggestions = """\n---\n\nPlease address the issues identified and
28submit a new revision of the patch, or alternatively, reply to this
29email with an explanation of why the patch should be accepted. If you
30believe these results are due to an error in patchtest, please submit a
31bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category
32under 'Yocto Project Subprojects'). For more information on specific
33failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank
34you!"""
35
36parser = argparse.ArgumentParser(description="Send patchtest results to a submitter for a given patch")
37parser.add_argument("-p", "--patch", dest="patch", required=True, help="The patch file to summarize")
38args = parser.parse_args()
39
40if not os.path.exists(args.patch):
41 print(f"Patch '{args.patch}' not found - did you provide the right path?")
42 sys.exit(1)
43elif not os.path.exists(args.patch + ".testresult"):
44 print(f"Found patch '{args.patch}' but '{args.patch}.testresult' was not present. Have you run patchtest on the patch?")
45 sys.exit(1)
46
47result_file = args.patch + ".testresult"
48result_basename = os.path.basename(args.patch)
49testresult = None
50
51with open(result_file, "r") as f:
52 testresult = f.read()
53
54# we know these patch files will only contain a single patch, so only
55# worry about the first element for getting the subject
56mbox = mailbox.mbox(args.patch)
57mbox_subject = mbox[0]['subject']
58subject_line = f"Patchtest results for {mbox_subject}"
59
60# extract the submitter email address and use it as the reply address
61# for the results
62reply_address = mbox[0]['from']
63
64# extract the message ID and use that as the in-reply-to address
65in_reply_to = re.findall("<(.*)>", mbox[0]['Message-ID'])[0]
66
67# the address the results email is sent from
68from_address = "patchtest@automation.yoctoproject.org"
69
70# mailing list to CC
71cc_address = "openembedded-core@lists.openembedded.org"
72
73if "FAIL" in testresult:
74 reply_contents = None
75 if len(max(open(result_file, 'r'), key=len)) > 220:
76 warning = "Tests failed for the patch, but the results log could not be processed due to excessive result line length."
77 reply_contents = greeting + warning + suggestions
78 else:
79 reply_contents = greeting + testresult + suggestions
80
81 ses_client = boto3.client('ses', region_name='us-west-2')
82 raw_data = 'From: ' + from_address + '\nTo: ' + reply_address + \
83 '\nCC: ' + cc_address + '\nSubject:' + subject_line + \
84 '\nIn-Reply-To:' + in_reply_to + \
85 '\nMIME-Version: 1.0" + \
86 "\nContent-type: Multipart/Mixed;boundary="NextPart"\n\n--NextPart\nContent-Type: text/plain\n\n' + \
87 reply_contents + '\n\n--NextPart'
88 response = ses_client.send_raw_email(
89 Source="patchtest@automation.yoctoproject.org",
90 RawMessage={
91 "Data": raw_data,
92 },
93 )
94
95else:
96 print(f"No failures identified for {args.patch}.")