Exemplo n.º 1
0
def _SetupConnections(options, build_config):
    """Set up CIDB connections using the appropriate Setup call.

  Args:
    options: Command line options structure.
    build_config: Config object for this build.
  """
    # Outline:
    # 1) Based on options and build_config, decide whether we are a production
    # run, debug run, or standalone run.
    # 2) Set up cidb instance accordingly.
    # 3) Update topology info from cidb, so that any other service set up can use
    # topology.
    # 4) Set up any other services.
    run_type = _GetRunEnvironment(options, build_config)

    if run_type == _ENVIRONMENT_PROD:
        cidb.CIDBConnectionFactory.SetupProdCidb()
        context = ts_mon_config.SetupTsMonGlobalState(
            'cbuildbot', indirect=True, task_num=options.ts_mon_task_num)
    elif run_type == _ENVIRONMENT_DEBUG:
        cidb.CIDBConnectionFactory.SetupDebugCidb()
        context = ts_mon_config.TrivialContextManager()
    else:
        cidb.CIDBConnectionFactory.SetupNoCidb()
        context = ts_mon_config.TrivialContextManager()

    db = cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder()
    topology.FetchTopologyFromCIDB(db)

    return context
 def setUp(self):
   self._build = 'test-build'
   self._board = 'test-board'
   self._suite = 'test-suite'
   self._pool = 'test-pool'
   self._num = 42
   self._file_bugs = True
   self._wait_for_results = True
   self._priority = 'test-priority'
   self._timeout_mins = 23
   self._retry = False
   self._max_retries = 3
   self._minimum_duts = 2
   self._suite_min_duts = 2
   self._subsystems = {'light', 'network'}
   self.create_cmd = None
   self.wait_cmd = None
   self.json_dump_cmd = None
   self.temp_json_path = os.path.join(self.tempdir, 'temp_summary.json')
   # Bot died
   self.retriable_swarming_code = 80
   self.internal_failure_exit_code = 1
   # A random code that's not retriable.
   self.swarming_code = 10
   topology.FetchTopologyFromCIDB(None)
Exemplo n.º 3
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.º 4
0
def FakeFetchTopologyFromCIDB(keyvals=None):
    """Setup topology without the need for a DB

  args:
    keyvals: optional dictionary to populate topology
  """
    keyvals = keyvals if keyvals != None else {}

    topology.FetchTopologyFromCIDB(None)
    topology.topology.update(keyvals)
    topology.topology.unlock()
Exemplo n.º 5
0
  def testPerformStage(self):
    """Tests that we correctly generate a tarball and archive it."""
    # pylint: disable=protected-access

    topology.FetchTopologyFromCIDB(None)
    self._PatchJson()
    stage = self.ConstructStage()
    stage.PerformStage()
    cmd = ['site_utils/autoupdate/full_release_test.py', '--npo', '--dump',
           '--archive_url', self.archive_stage.upload_url,
           self.archive_stage.release_tag, self._current_board]
    self.assertCommandContains(cmd)
    # pylint: disable=W0212
    self.assertCommandContains([swarming_lib._SWARMING_PROXY_CLIENT,
                                commands._RUN_SUITE_PATH, self.suite])
Exemplo n.º 6
0
def main(argv):
    parser = GetParser()
    options = parser.parse_args(argv)

    # Determine which hosts to connect to.
    db = cidb.CIDBConnection(options.cred_dir)
    topology.FetchTopologyFromCIDB(db)

    if options.json_file:
        # Use the specified alerts.
        logging.info('Using JSON file %s', options.json_file)
        with open(options.json_file) as f:
            summary_json = f.read()
            print(summary_json)
    else:
        builds = [tuple(x.split(',')) for x in options.builds]
        if not builds:
            builds = constants.SOM_BUILDS[options.som_tree]

        # Generate the set of alerts to send.
        logdog_client = logdog.LogdogClient(options.service_acct_json,
                                            host=options.logdog_host)
        milo_client = milo.MiloClient(options.service_acct_json,
                                      host=options.milo_host)
        summary_json = GenerateAlertsSummary(
            db,
            builds=builds,
            logdog_client=logdog_client,
            milo_client=milo_client,
            allow_experimental=options.allow_experimental)
        if options.output_json:
            with open(options.output_json, 'w') as f:
                logging.info('Writing JSON file %s', options.output_json)
                f.write(summary_json)

    # Authenticate and send the alerts.
    som_client = som.SheriffOMaticClient(options.service_acct_json,
                                         insecure=options.som_insecure,
                                         host=options.som_host)
    som_client.SendAlerts(summary_json, tree=options.som_tree)
Exemplo n.º 7
0
 def testWithoutDB(self):
     topology.FetchTopologyFromCIDB(None)
     self.assertEqual(topology.topology.get('/foo'), None)
Exemplo n.º 8
0
 def testWithDB(self):
     fake_db = fake_cidb.FakeCIDBConnection(fake_keyvals={'/foo': 'bar'})
     topology.FetchTopologyFromCIDB(fake_db)
     self.assertEqual(topology.topology.get('/foo'), 'bar')
 def testAbortHWTests(self):
   """Verifies that HWTests are aborted for a specific non-CQ config."""
   topology.FetchTopologyFromCIDB(None)
   commands.AbortHWTests('my_config', 'my_version', debug=False)
   self.assertCommandContains(['-i', 'my_config/my_version'])