Exemplo n.º 1
0
resultd.close()

summary = Summary(verbose=args.verbose)

bugzilla_user = yamlconfig["bugzilla"]["user"]
bugzilla_password = yamlconfig["bugzilla"]["password"]
bzid = bugzilla.RHBugzilla(url=args.bugzilla_url, user=bugzilla_user, password=bugzilla_password)
if not bzid:
    print "Failed to connect to bugzilla!"
    sys.exit(1)

for ami in result:
    ami_fd = tempfile.NamedTemporaryFile()
    ami_fd.write(yaml.safe_dump(ami))
    ami_fd.seek(0)
    overall_result, bug_summary, bug_description = valid_result.get_overall_result(ami)

    if args.test:
        summary.add(ami['ami'], status='fail')
        print bug_description
    else:
        BZ_Object = bzid.createbug(product=args.bugzilla_product, component=args.bugzilla_component, version="RHEL" + ami["version"], rep_platform=ami["arch"], summary=bug_summary, op_sys="Linux")
        if not BZ_Object:
            print "Failed to create bug in bugzilla!"
            sys.exit(1)

        bugid = str(BZ_Object.bug_id)
        attach_name = ami["ami"] + ".yaml"
        res = bzid.attachfile(bugid, ami_fd, attach_name, filename=attach_name, contenttype="text/yaml", ispatch=False)
        bug = bzid.getbug(bugid)
        if bug:
Exemplo n.º 2
0
def main():
    """ Main """

    argparser = argparse.ArgumentParser(description='Report validation result to bugzilla')
    argparser.add_argument('--bugzilla-component',
                           default="images", help='use specified bugzilla component')
    argparser.add_argument('--bugzilla-product',
                           default="Cloud Image Validation", help='use specified bugzilla product')
    argparser.add_argument('--bugzilla-url',
                           default="https://bugzilla.redhat.com/xmlrpc.cgi", help='use specified bugzilla xmlrpc url')
    argparser.add_argument('--config',
                           default="/etc/validation.yaml", help='use supplied yaml config file')
    argparser.add_argument('--debug', action='store_const', const=True,
                           default=False, help='debug mode')
    argparser.add_argument('--result', help='yaml file with validation result', required=True)
    argparser.add_argument('--test', action='store_const', const=True,
                           default=False, help='report to stdout instead of bugzilla')
    argparser.add_argument('-y', '--yaml-summary', help='provide info in yaml',
                           action='store_const', default=False, const=True)
    argparser.add_argument('-a', '--all-commands', help='show all commands in bugzillas not just failed',
                           action='store_true')

    args = argparser.parse_args()

    resultd = open(args.result, 'r')
    try:
        from yaml import CLoader as Loader
    except ImportError:
        from yaml import Loader
    result = yaml.load(resultd, Loader=Loader)
    resultd.close()

    summary = Summary(yaml_summary=args.yaml_summary)

    if not args.test:
        confd = open(args.config, 'r')
        yamlconfig = yaml.load(confd)
        confd.close()

        bugzilla_user = yamlconfig["bugzilla"]["user"]
        bugzilla_password = yamlconfig["bugzilla"]["password"]
        bzid = bugzilla.RHBugzilla(url=args.bugzilla_url, user=bugzilla_user, password=bugzilla_password)
        if not bzid:
            print "Failed to connect to bugzilla!"
            sys.exit(1)

    for ami in result:
        ami_fd = tempfile.NamedTemporaryFile()
        ami_fd.write(yaml.safe_dump(ami))
        ami_fd.seek(0)
        overall_result, bug_summary, info, bug_description = valid_result.get_overall_result(ami, verbose=args.all_commands)
        bugnr = None

        if not args.test:
            bzobject = bzid.createbug(product=args.bugzilla_product,
                                       component=args.bugzilla_component,
                                       version="RHEL" + ami["version"],
                                       rep_platform=ami["arch"],
                                       summary=bug_summary,
                                       op_sys="Linux",
                                       keywords=["TestOnly"])
            if not bzobject:
                print "Failed to create bug in bugzilla!"
                sys.exit(1)

            bugid = str(bzobject.bug_id)
            attach_name = ami["ami"] + ".yaml"
            bzid.attachfile(bugid, ami_fd, attach_name, filename=attach_name, contenttype="text/yaml", ispatch=False)
            # FIXME: check previous call result
            bug = None
            for ntry in xrange(10):
                try:
                    bug = bzid.getbug(bugid)
                    break
                except:
                    # bug not found, retry
                    time.sleep(10)
            if bug:
                bugnr = bug.id
                for comment in bug_description:
                    bug.addcomment(comment)
                bug.setstatus("VERIFIED" if overall_result == "succeeded" else "ON_QA")
        else:
            print info
            print '\n'.join(bug_description)

        summary.add(ami['ami'], bug=bugnr, status='pass' if overall_result == "succeeded" else 'fail')
        ami_fd.close()
    print summary
Exemplo n.º 3
0
 def report_results(self):
     """
     Looking if we can report some transactions
     """
     with resultdic_lock:
         """ Dictionary is now locked """
         for transaction_id in resultdic.keys():
             """ Checking all transactions """
             report_ready = True
             for ami in resultdic[transaction_id].keys():
                 """ Checking all amis: they should be finished """
                 if resultdic[transaction_id][ami]['ninstances'] != len(resultdic[transaction_id][ami]['instances']):
                     """ Still have some jobs running ..."""
                     logging.debug('WatchmanThread: ' + transaction_id + ': ' + ami + ':  waiting for ' + str(resultdic[transaction_id][ami]['ninstances']) + ' results, got ' + str(len(resultdic[transaction_id][ami]['instances'])))
                     report_ready = False
             if report_ready:
                 resfile = resdir + '/' + transaction_id + '.yaml'
                 result = []
                 data = resultdic[transaction_id]
                 emails = None
                 subject = None
                 for ami in data.keys():
                     result_item = {'ami': data[ami]['instances'][0]['ami'],
                                    'product': data[ami]['instances'][0]['product'],
                                    'version': data[ami]['instances'][0]['version'],
                                    'arch': data[ami]['instances'][0]['arch'],
                                    'region': data[ami]['instances'][0]['region'],
                                    'console_output': {},
                                    'result': {}}
                     for instance in data[ami]['instances']:
                         if not instance['instance_type'] in result_item['result'].keys():
                             result_item['result'][instance['instance_type']] = instance['result'].copy()
                         else:
                             result_item['result'][instance['instance_type']].update(instance['result'])
                         # we're interested in latest console output only, overwriting
                         result_item['console_output'][instance['instance_type']] = instance['console_output']
                     result.append(result_item)
                     if 'emails' in data[ami].keys():
                         emails = data[ami]['emails']
                     if 'subject' in data[ami].keys():
                         subject = data[ami]['subject']
                 result_yaml = yaml.safe_dump(result)
                 with resultdic_yaml_lock:
                     resultdic_yaml[transaction_id] = result_yaml
                 try:
                     result_fd = open(resfile, 'w')
                     result_fd.write(result_yaml)
                     result_fd.close()
                     if emails:
                         for ami in result:
                             overall_result, bug_summary, bug_description = valid_result.get_overall_result(ami)
                             msg = MIMEMultipart()
                             msg.preamble = 'Validation result'
                             if subject:
                                 msg['Subject'] = "[" + overall_result + "] " + subject
                             else:
                                 msg['Subject'] = "[" + overall_result + "] " + bug_summary
                             msg['From'] = mailfrom
                             msg['To'] = emails
                             txt = MIMEText(bug_description + '\n')
                             msg.attach(txt)
                             txt = MIMEText(yaml.safe_dump(ami), 'yaml')
                             msg.attach(txt)
                             s = smtplib.SMTP('localhost')
                             s.sendmail(mailfrom, emails.split(','), msg.as_string())
                             s.quit()
                 except Exception, e:
                     logging.error('WatchmanThread: saving result failed, %s' % e)
                 logging.info('Transaction ' + transaction_id + ' finished. Result: ' + resfile)
                 resultdic.pop(transaction_id)
Exemplo n.º 4
0
 def report_results(self):
     """
     Looking if we can report some transactions
     """
     with self.shareddata.resultdic_lock:
         for transaction_id in self.shareddata.resultdic.keys():
             # Checking all transactions
             transaction_dict = self.shareddata.resultdic[transaction_id].copy()
             # if the transaction progress ratio is equal to 1.0 the transaction is finished
             if self.transaction_progress(transaction_id, transaction_dict) == 1.0:
                 resfile = self.shareddata.resdir + "/" + transaction_id + ".yaml"
                 result = []
                 data = transaction_dict
                 emails = None
                 subject = None
                 for ami in data.keys():
                     result_item = {
                         "ami": data[ami]["instances"][0]["ami"],
                         "product": data[ami]["instances"][0]["product"],
                         "version": data[ami]["instances"][0]["version"],
                         "arch": data[ami]["instances"][0]["arch"],
                         "region": data[ami]["instances"][0]["region"],
                         "console_output": {},
                         "result": {},
                     }
                     for instance in data[ami]["instances"]:
                         if not instance["instance_type"] in result_item["result"].keys():
                             result_item["result"][instance["instance_type"]] = instance["result"].copy()
                         else:
                             result_item["result"][instance["instance_type"]].update(instance["result"])
                         # we're interested in latest console output only, overwriting
                         result_item["console_output"][instance["instance_type"]] = instance["console_output"]
                     result.append(result_item)
                     # setting shareddata.last_testing_exitstatus, valid_runner script will return this exit status
                     overall_result, _, _, _ = valid_result.get_overall_result(result_item)
                     if overall_result == "succeeded":
                         self.shareddata.last_testing_exitstatus.set(0)
                     else:
                         self.shareddata.last_testing_exitstatus.set(1)
                     if "emails" in data[ami].keys():
                         emails = data[ami]["emails"]
                     if "subject" in data[ami].keys():
                         subject = data[ami]["subject"]
                 result_yaml = yaml.safe_dump(result)
                 self.shareddata.resultdic_yaml[transaction_id] = result_yaml
                 try:
                     result_fd = open(resfile, "w")
                     result_fd.write(result_yaml)
                     result_fd.close()
                     if emails:
                         for ami in result:
                             overall_result, bug_summary, bug_description = valid_result.get_overall_result(ami)
                             msg = MIMEMultipart()
                             msg.preamble = "Validation result"
                             if subject:
                                 msg["Subject"] = "[" + overall_result + "] " + subject
                             else:
                                 msg["Subject"] = "[" + overall_result + "] " + bug_summary
                             msg["From"] = self.shareddata.mailfrom
                             msg["To"] = emails
                             txt = MIMEText(bug_description + "\n")
                             msg.attach(txt)
                             txt = MIMEText(yaml.safe_dump(ami), "yaml")
                             msg.attach(txt)
                             smtp = smtplib.SMTP("localhost")
                             smtp.sendmail(self.shareddata.mailfrom, emails.split(","), msg.as_string())
                             smtp.quit()
                 # pylint: disable=broad-except
                 except Exception, err:
                     self.logger.error("WatchmanProcess: saving result failed, %s", err)
                 # pylint: disable=maybe-no-member
                 self.logger.progress("Transaction " + transaction_id + " finished. Result: " + resfile)
                 self.shareddata.resultdic.pop(transaction_id)