Exemplo n.º 1
0
    def Run(self):
        """Run cros uprevchrome.

    Raises:
      Exception if the PFQ build_id is not valid.
      Exception if UprevChrome raises exceptions.
    """
        self.options.Freeze()

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        cidb_creds = self.options.cred_dir
        if cidb_creds is None:
            try:
                cidb_creds = cros_cidbcreds.CheckAndGetCIDBCreds()
            except:
                logging.error('Failed to download CIDB creds from gs.\n'
                              'Can try obtaining your credentials at '
                              'go/cros-cidb-admin and manually passing it in '
                              'with --cred-dir.')
                raise

        db = cidb.CIDBConnection(cidb_creds)

        build_number = self.ValidatePFQBuild(self.options.pfq_build, db)

        with osutils.TempDir(prefix='uprevchrome_',
                             delete=self.options.wipe) as work_dir:
            self.UprevChrome(work_dir, self.options.pfq_build, build_number)
            logging.info('Used working directory: %s', work_dir)
Exemplo n.º 2
0
def main(argv):
    # Parse command line arguments.
    parser = GetParser()
    options = parser.parse_args(argv)

    # Set up clients.
    credentials = options.cred_dir or cros_cidbcreds.CheckAndGetCIDBCreds()
    db = cidb.CIDBConnection(credentials)
    topology.FetchTopologyFromCIDB(db)
    milo_client = milo.MiloClient(options.service_acct_json,
                                  host=options.milo_host)

    builds = []

    # Add explicitly requested builds.
    if options.build_ids:
        for build_id in options.build_ids:
            builds.append(
                MakeBuildEntry(db,
                               milo_client,
                               build_id,
                               no_suites=options.no_suites))

    # Search for builds by build config.
    if options.build_config:
        masters = db.GetBuildHistory(options.build_config,
                                     options.num_builds,
                                     final=True)
        for master in masters:
            builds.append(
                MakeBuildEntry(db,
                               milo_client,
                               master['id'],
                               master,
                               no_suites=options.no_suites))
            statuses = db.GetSlaveStatuses(master['id'])
            for slave in statuses:
                builds.append(
                    MakeBuildEntry(db,
                                   milo_client,
                                   slave['id'],
                                   slave,
                                   no_suites=options.no_suites))

    if not options.allow_empty and not options.no_suites:
        builds = [b for b in builds if len(b.get('suite_ids', []))]

    # Output results.
    with open(options.output, 'w') if options.output else sys.stdout as f:
        if options.json:
            output = {
                'builds': builds,
            }
            json.dump(output, f)
        else:
            for b in builds:
                f.write(StringifyBuildEntry(b))
                f.write('\n')
Exemplo n.º 3
0
def main(argv):
  parser = GetParser()
  options = parser.parse_args(argv)

  if not _CheckOptions(options):
    sys.exit(1)

  credentials = options.cred_dir
  if not credentials:
    credentials = cros_cidbcreds.CheckAndGetCIDBCreds()

  db = cidb.CIDBConnection(credentials)

  if options.end_date:
    end_date = options.end_date
  else:
    end_date = datetime.datetime.now().date()

  # Determine the start date to use, which is required.
  if options.start_date:
    start_date = options.start_date
  else:
    assert options.past_month or options.past_week or options.past_day
    # Database search results will include both the starting and ending
    # days.  So, the number of days to subtract is one less than the
    # length of the search period.
    #
    # For instance, the starting day for the week ending 2014-04-21
    # should be 2017-04-15 (date - 6 days).
    if options.past_month:
      start_date = end_date - datetime.timedelta(days=29)
    elif options.past_week:
      start_date = end_date - datetime.timedelta(days=6)
    else:
      start_date = end_date

  if options.build_type == 'cq':
    master_config = constants.CQ_MASTER
  else:
    master_config = constants.PFQ_MASTER

  cl_stats_engine = CLStatsEngine(db)
  cl_stats_engine.Gather(start_date, end_date, master_config)
  summary = cl_stats_engine.Summarize(options.build_type,
                                      options.bad_patch_candidates)

  if options.report_file:
    with open(options.report_file, "w") as f:
      logging.info("Writing report to %s", options.report_file)
      GenerateReport(f, summary)
Exemplo n.º 4
0
    def Run(self):
        """Run cros buildresult."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        credentials = self.options.cred_dir
        if not credentials:
            credentials = cros_cidbcreds.CheckAndGetCIDBCreds(
                force_update=self.options.force_update)

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        db = cidb.CIDBConnection(credentials)

        build_statuses = FetchBuildStatuses(db, self.options)

        if build_statuses:
            # Filter out builds that don't exist in CIDB, or which aren't finished.
            build_statuses = [
                b for b in build_statuses if IsBuildStatusFinished(b)
            ]

        # If we found no builds at all, return a different exit code to help
        # automated scripts know they should try waiting longer.
        if not build_statuses:
            logging.error('No build found. Perhaps not started?')
            return 2

        # Fixup all of the builds we have.
        build_statuses = [FixUpBuildStatus(db, b) for b in build_statuses]

        # Produce our final result.
        if self.options.report == 'json':
            report = ReportJson(build_statuses)
        else:
            report = Report(build_statuses)

        print(report)
Exemplo n.º 5
0
    def Run(self):
        """Run cros uprevchrome.

    Raises:
      Exception if the PFQ build_id is not valid.
      Exception if UprevChrome raises exceptions.
    """
        self.options.Freeze()

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        cidb_creds = self.options.cred_dir
        if cidb_creds is None:
            try:
                cidb_creds = cros_cidbcreds.CheckAndGetCIDBCreds()
            except:
                logging.error('Failed to download CIDB creds from gs.\n'
                              'Can try obtaining your credentials at '
                              'go/cros-cidb-admin and manually passing it in '
                              'with --cred-dir.')
                raise

        db = cidb.CIDBConnection(cidb_creds)

        build_number = self.ValidatePFQBuild(self.options.pfq_build, db)

        chroot_tmp = os.path.join(constants.SOURCE_ROOT,
                                  constants.DEFAULT_CHROOT_DIR, 'tmp')
        tmp_override = None if cros_build_lib.IsInsideChroot() else chroot_tmp
        work_dir = tempfile.mkdtemp(prefix='uprevchrome_', dir=tmp_override)

        try:
            self.UprevChrome(work_dir, self.options.pfq_build, build_number)
        finally:
            if self.options.wipe:
                osutils.RmDir(work_dir)
                logging.info('Removed work_dir %s', work_dir)
            else:
                logging.info('Leaving working directory at %s', work_dir)
Exemplo n.º 6
0
    def Run(self):
        """Run cros build."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        credentials = self.options.cred_dir
        if not credentials:
            credentials = cros_cidbcreds.CheckAndGetCIDBCreds()

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        db = cidb.CIDBConnection(credentials)

        # Timeframe for discovering builds, if options.build_id not used.
        start_date, end_date = self.OptionsToStartEndDates(self.options)

        # Trending is sufficiently different to be handled on it's own.
        if not self.options.trending and self.options.report != 'success':
            assert not self.options.csv, (
                '--csv can only be used with --trending or --report success.')

        # Data about a single build (optional).
        focus_build = None

        if self.options.build_id:
            logging.info('Gathering data for %s', self.options.build_id)
            focus_status = build_time_stats.BuildIdToBuildStatus(
                db, self.options.build_id)
            focus_build = build_time_stats.GetBuildTimings(focus_status)

            build_config = focus_status['build_config']
            builds_statuses = build_time_stats.BuildConfigToStatuses(
                db, build_config, start_date, end_date)
            description = 'Focus %d - %s' % (self.options.build_id,
                                             build_config)

        elif self.options.build_config:
            builds_statuses = build_time_stats.BuildConfigToStatuses(
                db, self.options.build_config, start_date, end_date)
            description = 'Config %s' % self.options.build_config

        elif self.options.build_type:
            builds_statuses = build_time_stats.MasterConfigToStatuses(
                db, BUILD_TYPE_MAP[self.options.build_type], start_date,
                end_date)
            description = 'Type %s' % self.options.build_type

        if not builds_statuses:
            logging.critical('No Builds Found For: %s', description)
            return 1

        if self.options.report == 'success':
            # Calculate per-build success rates and per-stage success rates.
            build_success_rates = build_time_stats.GetBuildSuccessRates(
                builds_statuses)
            stage_success_rates = (
                build_time_stats.GetStageSuccessRates(builds_statuses)
                if self.options.stages else {})
            if self.options.csv:
                build_time_stats.SuccessReportCsv(sys.stdout,
                                                  build_success_rates,
                                                  stage_success_rates)
            else:
                build_time_stats.SuccessReport(sys.stdout, description,
                                               build_success_rates,
                                               stage_success_rates)
            return 0

        # Compute per-build timing.
        builds_timings = [
            build_time_stats.GetBuildTimings(status)
            for status in builds_statuses
        ]

        if not builds_timings:
            logging.critical('No timing results For: %s', description)
            return 1

        # Report results.
        if self.options.report == 'standard':
            build_time_stats.Report(sys.stdout, description, focus_build,
                                    builds_timings, self.options.stages,
                                    self.options.trending, self.options.csv)
        elif self.options.report == 'stability':
            build_time_stats.StabilityReport(sys.stdout, description,
                                             builds_timings)