From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 36F46B5A2 for ; Mon, 16 Feb 2015 06:02:29 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 15 Feb 2015 21:02:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,585,1418112000"; d="scan'208";a="528008337" Received: from kmsmsx152.gar.corp.intel.com ([172.21.73.87]) by orsmga003.jf.intel.com with ESMTP; 15 Feb 2015 20:53:55 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by KMSMSX152.gar.corp.intel.com (172.21.73.87) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 16 Feb 2015 13:02:21 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.192]) by shsmsx102.ccr.corp.intel.com ([169.254.2.62]) with mapi id 14.03.0195.001; Mon, 16 Feb 2015 13:02:20 +0800 From: "Qiu, Michael" To: "Liu, Yong" , "dts@dpdk.org" Thread-Topic: [dts] [PATCH 1/2] framework: add new module to create email report Thread-Index: AQHQSaNqn02t0LJv/Ui78OPx2bekxw== Date: Mon, 16 Feb 2015 05:02:19 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286CEA215@SHSMSX101.ccr.corp.intel.com> References: <1424061918-9106-1-git-send-email-yong.liu@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH 1/2] framework: add new module to create email report X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Feb 2015 05:02:30 -0000 On 2/16/2015 12:45 PM, Yong Liu wrote:=0A= > This module will parse excel result file and create email like below.=0A= >=0A= > Summary: Run XXX cases (PASS-Count FAIL-Count BLOCK-Count)=0A= > Latest commit log:=0A= > Kernel Version:=0A= > CPU info:=0A= > GCC Version:=0A= =0A= Here I don't see any place try to show this field=0A= =0A= Thanks,=0A= Michael=0A= > Target: x86_64-native-linuxapp-gcc FAIL:XXX/YYY=0A= > Detail information of failed cases:=0A= > Target: x86_64-native-linuxapp-gcc=0A= > Test Case Result=0A= > Case name FAILED=0A= >=0A= > Signed-off-by: Marvinliu =0A= >=0A= > diff --git a/framework/email_report.py b/framework/email_report.py=0A= > new file mode 100644=0A= > index 0000000..38e390c=0A= > --- /dev/null=0A= > +++ b/framework/email_report.py=0A= > @@ -0,0 +1,132 @@=0A= > +import argparse # prase arguments module=0A= > +import smtplib # send email module=0A= > +from email.mime.text import MIMEText=0A= > +from email.mime.multipart import MIMEMultipart=0A= > +=0A= > +from excel_reporter import ExcelReporter # excel parse module=0A= > +from texttable import Texttable # formatted output module=0A= > +=0A= > +rece_maillist =3D ["dts@dpdk.org"]=0A= > +from_maillist =3D "sys_stv@intel.com"=0A= > +=0A= > +# Global variable=0A= > +total_target =3D 0=0A= > +global os_type=0A= > +global test_type=0A= > +global git_commit=0A= > +global dut_config=0A= > +dut_config =3D []=0A= > +os_type =3D ""=0A= > +test_type =3D ""=0A= > +git_commit =3D ""=0A= > +=0A= > +=0A= > +# Format of Email=0A= > +class Email():=0A= > +=0A= > + def __init__(self, excel):=0A= > + self.subject_format =3D "%s %s Test Report"=0A= > + self.summary_format =3D "Summary: Run %d cases (PASS-%d FAIL-%d = BLOCK-%d)"=0A= > + self.result_summary_format =3D "Target: %-30s FAIL= :%d/%d\r\n"=0A= > + excel =3D ExcelReporter(excel)=0A= > + self.result =3D excel.load()=0A= > + self.smtp =3D smtplib.SMTP()=0A= > + self.smtp.connect("mail.intel.com", 25)=0A= > +=0A= > + def subject(self):=0A= > + return self.subject_format % (os_type, test_type)=0A= > +=0A= > + def summary(self):=0A= > + total =3D 0=0A= > + passed =3D 0=0A= > + fail =3D 0=0A= > + block =3D 0=0A= > + for dut in self.result.all_duts():=0A= > + targets =3D self.result.all_targets(dut)=0A= > + for target in targets:=0A= > + suites =3D self.result.get_target_suites(dut, target)=0A= > + results =3D self.result.get_suites_status(suites)=0A= > + total +=3D len(results)=0A= > + passed +=3D results.count("PASSED")=0A= > + fail +=3D results.count("FAILED")=0A= > + block +=3D results.count("BLOCKED")=0A= > +=0A= > + return self.summary_format % (total, passed, fail, block)=0A= > +=0A= > + def target_summary(self):=0A= > + summary =3D ""=0A= > + for dut in self.result.all_duts():=0A= > + targets =3D self.result.all_targets(dut)=0A= > + for target in targets:=0A= > + suites =3D self.result.get_target_suites(dut, target)=0A= > + results =3D self.result.get_suites_status(suites)=0A= > + summary +=3D self.result_summary_format % (target, resul= ts.count("FAILED"), len(results))=0A= > + return summary=0A= > +=0A= > + def failed_case_summary(self):=0A= > + summary =3D ""=0A= > + for dut in self.result.all_duts():=0A= > + targets =3D self.result.all_targets(dut)=0A= > + for target in targets:=0A= > + summary +=3D "Target: %s\r\n" % (target)=0A= > + table =3D Texttable()=0A= > + table.set_deco(Texttable.HEADER)=0A= > + table.set_cols_align(["l", "l"])=0A= > + table.set_cols_width([50, 10])=0A= > + table.add_row(["Test Case", "Result"])=0A= > + suites =3D self.result.get_target_suites(dut, target)=0A= > + failed =3D self.result.get_cases_by_status(suites, 'FAIL= ED')=0A= > + blocked =3D self.result.get_cases_by_status(suites, 'BLO= CKED')=0A= > + for case in failed:=0A= > + table.add_row([case, 'FAILED'])=0A= > + for case in blocked:=0A= > + table.add_row([case, 'BLOCKED'])=0A= > + summary +=3D table.draw()=0A= > + summary +=3D "\r\n\r\n"=0A= > +=0A= > + return summary=0A= > +=0A= > + def send(self, _from, _to, attachment):=0A= > + content =3D ""=0A= > + msg =3D MIMEMultipart('alternative')=0A= > + msg['Subject'] =3D self.subject()=0A= > + msg['From'] =3D _from=0A= > + msg['To'] =3D ", ".join(_to)=0A= > + content +=3D self.summary()=0A= > + content +=3D "\r\n\r\n"=0A= > + content +=3D git_commit=0A= > + content +=3D "\r\n\r\n"=0A= > + content +=3D "".join(dut_config)=0A= > + content +=3D "\r\n\r\n"=0A= > + content +=3D self.target_summary()=0A= > + content +=3D "\r\n\r\n"=0A= > + content +=3D "Detail information of failed cases:\r\n"=0A= > + content +=3D self.failed_case_summary()=0A= > + part2 =3D MIMEText(content, "plain", "utf-8")=0A= > + msg.attach(part2)=0A= > + fp =3D open(attachment, 'r')=0A= > + part1 =3D MIMEText(fp.read(), 'base64', 'utf-8')=0A= > + part1['Content-type'] =3D 'application/octet-stream'=0A= > + part1['Content-Disposition'] =3D 'attachment;filename=3D"output.= zip"'=0A= > + fp.close()=0A= > + msg.attach(part1)=0A= > + self.smtp.sendmail(=0A= > + _from, _to, msg.as_string())=0A= > + self.smtp.quit()=0A= > +=0A= > +if __name__ =3D=3D '__main__':=0A= > + parser =3D argparse.ArgumentParser(description=3D"DTS Email Report M= odule")=0A= > + parser.add_argument("-o", "--os_type", default=3D"Fedora20")=0A= > + parser.add_argument("-t", "--test_type", default=3D"Functional")=0A= > + parser.add_argument(=0A= > + "-e", "--excel_file", default=3D"output/test_results.xls")=0A= > + parser.add_argument("-g", "--git_commit", default=3D"test commit")= =0A= > + args =3D parser.parse_args()=0A= > + os_type =3D args.os_type=0A= > + test_type =3D args.test_type=0A= > + git_commit =3D args.git_commit=0A= > + email =3D Email(args.excel_file)=0A= > + print email.subject()=0A= > + print email.summary()=0A= > + print email.target_summary()=0A= > + print email.failed_case_summary()=0A= =0A=