예제 #1
0
def send_email(bug, bug_template):
    """Send email to the owner and cc's to notify the TestBug.

    @param bug: TestBug instance.
    @param bug_template: A template dictionary specifying the default bug
                         filing options for failures in this suite.
    """
    autotest_stats.Counter(EMAIL_COUNT_KEY % 'total').increment()
    to_set = set(bug.cc) if bug.cc else set()
    if bug.owner:
        to_set.add(bug.owner)
    if bug_template.get('cc'):
        to_set = to_set.union(bug_template.get('cc'))
    if bug_template.get('owner'):
        to_set.add(bug_template.get('owner'))
    recipients = ', '.join(to_set)
    try:
        gmail_lib.send_email(
            recipients,
            bug.title(),
            bug.summary(),
            retry=False,
            creds_path=site_utils.get_creds_abspath(EMAIL_CREDS_FILE))
    except Exception:
        autotest_stats.Counter(EMAIL_COUNT_KEY % 'fail').increment()
        raise
예제 #2
0
def send_email(bug, bug_template):
    """Send email to the owner and cc's to notify the TestBug.

    @param bug: TestBug instance.
    @param bug_template: A template dictionary specifying the default bug
                         filing options for failures in this suite.
    """
    to_set = set(bug.cc) if bug.cc else set()
    if bug.owner:
        to_set.add(bug.owner)
    if bug_template.get('cc'):
        to_set = to_set.union(bug_template.get('cc'))
    if bug_template.get('owner'):
        to_set.add(bug_template.get('owner'))
    recipients = ', '.join(to_set)
    if not recipients:
        logging.warning('No owner/cc found. Will skip sending a mail.')
        return
    success = False
    try:
        gmail_lib.send_email(
            recipients,
            bug.title(),
            bug.summary(),
            retry=False,
            creds_path=site_utils.get_creds_abspath(EMAIL_CREDS_FILE))
        success = True
    finally:
        (metrics.Counter('chromeos/autotest/errors/send_bug_email').increment(
            fields={'success': success}))
예제 #3
0
    def get_creds_abspath(cls):
        """Returns the abspath of the bug filer credentials file.

        @return: A path to the oauth2 credentials file.
        """
        return site_utils.get_creds_abspath(cls._oauth_credentials)
예제 #4
0
def parse_args():
    """Parse args."""
    # build up our options parser and parse sys.argv
    parser = optparse.OptionParser()
    parser.add_option("-m",
                      help="Send mail for FAILED tests",
                      dest="mailit",
                      action="store_true")
    parser.add_option("-r",
                      help="Reparse the results of a job",
                      dest="reparse",
                      action="store_true")
    parser.add_option("-o",
                      help="Parse a single results directory",
                      dest="singledir",
                      action="store_true")
    parser.add_option("-l",
                      help=("Levels of subdirectories to include "
                            "in the job name"),
                      type="int",
                      dest="level",
                      default=1)
    parser.add_option("-n",
                      help="No blocking on an existing parse",
                      dest="noblock",
                      action="store_true")
    parser.add_option("-s",
                      help="Database server hostname",
                      dest="db_host",
                      action="store")
    parser.add_option("-u",
                      help="Database username",
                      dest="db_user",
                      action="store")
    parser.add_option("-p",
                      help="Database password",
                      dest="db_pass",
                      action="store")
    parser.add_option("-d",
                      help="Database name",
                      dest="db_name",
                      action="store")
    parser.add_option("--dry-run",
                      help="Do not actually commit any results.",
                      dest="dry_run",
                      action="store_true",
                      default=False)
    parser.add_option("--write-pidfile",
                      help="write pidfile (.parser_execute)",
                      dest="write_pidfile",
                      action="store_true",
                      default=False)
    parser.add_option("--record-duration",
                      help="Record timing to metadata db",
                      dest="record_duration",
                      action="store_true",
                      default=False)
    parser.add_option(
        "--suite-report",
        help=("Allows parsing job to attempt to create a suite "
              "timeline report, if it detects that the job being "
              "parsed is a suite job."),
        dest="suite_report",
        action="store_true",
        default=False)
    parser.add_option("--datastore-creds",
                      help=("The path to gcloud datastore credentials file, "
                            "which will be used to upload suite timeline "
                            "report to gcloud. If not specified, the one "
                            "defined in shadow_config will be used."),
                      dest="datastore_creds",
                      action="store",
                      default=None)
    parser.add_option(
        "--export-to-gcloud-path",
        help=("The path to export_to_gcloud script. Please find "
              "chromite path on your server. The script is under "
              "chromite/bin/."),
        dest="export_to_gcloud_path",
        action="store",
        default=None)
    options, args = parser.parse_args()

    # we need a results directory
    if len(args) == 0:
        tko_utils.dprint("ERROR: at least one results directory must "
                         "be provided")
        parser.print_help()
        sys.exit(1)

    if not options.datastore_creds:
        gcloud_creds = global_config.global_config.get_config_value(
            'GCLOUD', 'cidb_datastore_writer_creds', default=None)
        options.datastore_creds = (site_utils.get_creds_abspath(gcloud_creds)
                                   if gcloud_creds else None)

    if not options.export_to_gcloud_path:
        export_script = 'chromiumos/chromite/bin/export_to_gcloud'
        # If it is a lab server, the script is under ~chromeos-test/
        if os.path.exists(
                os.path.expanduser('~chromeos-test/%s' % export_script)):
            path = os.path.expanduser('~chromeos-test/%s' % export_script)
        # If it is a local workstation, it is probably under ~/
        elif os.path.exists(os.path.expanduser('~/%s' % export_script)):
            path = os.path.expanduser('~/%s' % export_script)
        # If it is not found anywhere, the default will be set to None.
        else:
            path = None
        options.export_to_gcloud_path = path

    # pass the options back
    return options, args