コード例 #1
0
    def __init__(self, **kwargs):
        """Initialize the record.

    **kwargs keys need to correspond to elements in __slots__.  These arguments
    can be lists:
    - cmd_args
    - cmd_base
    - cmd_line

    If unset, the |username| and |host|  attributes will be determined
    automatically.
    """
        if kwargs.get('username') is None:
            kwargs['username'] = git.GetProjectUserEmail(
                os.path.dirname(__file__))

        if kwargs.get('host') is None:
            kwargs['host'] = cros_build_lib.GetHostName(fully_qualified=True)

        for attr in ('cmd_args', 'cmd_base', 'cmd_line'):
            val = kwargs.get(attr)
            if isinstance(val, (
                    list,
                    tuple,
            )):
                kwargs[attr] = ' '.join(map(repr, val))

        for arg in self.__slots__:
            setattr(self, arg, kwargs.pop(arg, None))
        if kwargs:
            raise TypeError('Unknown options specified %r:' % kwargs)
コード例 #2
0
def WriteBasicMetadata(builder_run):
    """Writes basic metadata that should be known at start of execution.

  This method writes to |build_run|'s metadata instance the basic metadata
  values that should be known at the beginning of the first cbuildbot
  execution, prior to any reexecutions.

  In particular, this method does not write any metadata values that depend
  on the builder config, as the config may be modified by patches that are
  applied before the final reexectuion. (exception: the config's name itself)

  This method is safe to run more than once (for instance, once per cbuildbot
  execution) because it will write the same data each time.

  Args:
    builder_run: The BuilderRun instance for this build.
  """
    start_time = results_lib.Results.start_time
    start_time_stamp = cros_build_lib.UserDateTimeFormat(timeval=start_time)

    metadata = {
        # Data for this build.
        'bot-hostname': cros_build_lib.GetHostName(fully_qualified=True),
        'build-number': builder_run.buildnumber,
        'builder-name': builder_run.GetBuilderName(),
        'buildbot-url': os.environ.get('BUILDBOT_BUILDBOTURL', ''),
        'buildbot-master-name': os.environ.get('BUILDBOT_MASTERNAME', ''),
        'bot-config': builder_run.config['name'],
        'time': {
            'start': start_time_stamp,
        },
        'master_build_id': builder_run.options.master_build_id,
    }

    builder_run.attrs.metadata.UpdateWithDict(metadata)
コード例 #3
0
ファイル: goma_util.py プロジェクト: msisov/chromium68
  def __init__(self, goma_log_dir, today=None, dry_run=False):
    """Initializes the uploader.

    Args:
      goma_log_dir: path to the directory containing goma's INFO log files.
      today: datetime.date instance representing today. This is for testing
        purpose, because datetime.date is unpatchable. In real use case,
        this must be None.
      dry_run: If True, no actual upload. This is for testing purpose.
    """
    self._goma_log_dir = goma_log_dir
    logging.info('Goma log directory is: %s', self._goma_log_dir)

    # Set log upload destination.
    if today is None:
      today = datetime.date.today()
    self.dest_path = '%s/%s' % (
        today.strftime('%Y/%m/%d'), cros_build_lib.GetHostName())
    self._remote_dir = 'gs://%s/%s' % (GomaLogUploader._BUCKET, self.dest_path)
    logging.info('Goma log upload destination: %s', self._remote_dir)

    # Build metadata to be annotated to log files.
    # Use OrderedDict for json output stabilization.
    builder_info = json.dumps(collections.OrderedDict([
        ('builder', os.environ.get('BUILDBOT_BUILDERNAME', '')),
        ('master', os.environ.get('BUILDBOT_MASTERNAME', '')),
        ('slave', os.environ.get('BUILDBOT_SLAVENAME', '')),
        ('clobber', bool(os.environ.get('BUILDBOT_CLOBBER'))),
        ('os', 'chromeos'),
    ]))
    logging.info('BuilderInfo: %s', builder_info)
    self._headers = ['x-goog-meta-builderinfo:' + builder_info]

    self._gs_context = gs.GSContext(dry_run=dry_run)
コード例 #4
0
ファイル: gclient.py プロジェクト: xiicloud/chromite
def _UseGoloMirror():
  """Check whether to use the golo.chromium.org mirrors.

  This function returns whether or not we should use the mirrors from
  golo.chromium.org, which are only accessible from within that subdomain.
  """
  return cros_build_lib.GetHostName(fully_qualified=True).endswith(
      '.golo.chromium.org')
コード例 #5
0
def GetParser():
    """Return a command line parser"""
    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument('-n',
                        '--dry-run',
                        default=False,
                        action='store_true',
                        help='Show what would be uploaded')
    parser.add_argument('--url',
                        default=perf_uploader.LOCAL_DASHBOARD_URL,
                        help='Dashboard to send results to')

    group = parser.add_argument_group('Bot Details')
    group.add_argument('-m',
                       '--master',
                       default=MASTER_NAME,
                       help='The buildbot master field')
    group.add_argument(
        '-b',
        '--bot',
        default=cros_build_lib.GetHostName(fully_qualified=True),
        help='The bot name (e.g. buildbot config)')

    group = parser.add_argument_group('Version Options (X-axis)')
    group.add_argument('--revision', default=None, help='Revision number')
    group.add_argument('--cros-version',
                       default=None,
                       help='Chrome OS version (X.Y.Z)')
    group.add_argument('--chrome-version',
                       default=None,
                       help='Chrome version (M.X.Y.Z)')

    group = parser.add_argument_group('Data Options')
    group.add_argument('-t',
                       '--test',
                       default=TEST_NAME,
                       help='The test name field')
    group.add_argument('--higher-is-better',
                       default=False,
                       action='store_true',
                       help='Whether higher values are better than lower')
    group.add_argument('-u',
                       '--units',
                       default='',
                       help='Units for the perf data (e.g. percent, bytes)')
    group.add_argument('-g',
                       '--graph',
                       help='Graph name (to group multiple tests)')
    group.add_argument('-d',
                       '--description',
                       default='data',
                       help='Name for this data series')
    group.add_argument('--stdio-uri',
                       help='Custom log page to link data point to')
    group.add_argument('data', help='Data point (int or float)')

    return parser
コード例 #6
0
ファイル: goma_util.py プロジェクト: zhangjiayun/chromium.bb
    def __init__(self,
                 goma_log_dir,
                 today=None,
                 dry_run=False,
                 cbb_config_name=''):
        """Initializes the uploader.

    Args:
      goma_log_dir: path to the directory containing goma's INFO log files.
      today: datetime.date instance representing today. This is for testing
        purpose, because datetime.date is unpatchable. In real use case,
        this must be None.
      dry_run: If True, no actual upload. This is for testing purpose.
      cbb_config_name: Name of cbb_config.
    """
        self._goma_log_dir = goma_log_dir
        logging.info('Goma log directory is: %s', self._goma_log_dir)

        # Set log upload destination.
        if today is None:
            today = datetime.date.today()
        self.dest_path = '%s/%s' % (today.strftime('%Y/%m/%d'),
                                    cros_build_lib.GetHostName())
        self._remote_dir = 'gs://%s/%s' % (GomaLogUploader._BUCKET,
                                           self.dest_path)
        logging.info('Goma log upload destination: %s', self._remote_dir)

        # HACK(yyanagisawa): I suppose LUCI do not set BUILDBOT_BUILDERNAME.
        is_luci = not bool(os.environ.get('BUILDBOT_BUILDERNAME'))
        # Build metadata to be annotated to log files.
        # Use OrderedDict for json output stabilization.
        builder_info = collections.OrderedDict([
            ('builder', os.environ.get('BUILDBOT_BUILDERNAME', '')),
            ('master', os.environ.get('BUILDBOT_MASTERNAME', '')),
            ('slave', os.environ.get('BUILDBOT_SLAVENAME', '')),
            ('clobber', bool(os.environ.get('BUILDBOT_CLOBBER'))),
            ('os', 'chromeos'),
            ('is_luci', is_luci),
            ('cbb_config_name', cbb_config_name),
        ])
        if is_luci:
            # TODO(yyanagisawa): will adjust to valid value if needed.
            builder_info['builder_id'] = collections.OrderedDict([
                ('project', 'chromeos'),
                ('builder', 'Prod'),
                ('bucket', 'general'),
            ])
        builder_info_json = json.dumps(builder_info)
        logging.info('BuilderInfo: %s', builder_info_json)
        self._headers = ['x-goog-meta-builderinfo:' + builder_info_json]

        self._gs_context = gs.GSContext(dry_run=dry_run)
コード例 #7
0
 def _SendPreCQInfraAlertMessageIfNeeded(self):
   """Send alerts on Pre-CQ infra failures."""
   msg = completion_stages.CreateBuildFailureMessage(
       self._run.config.overlays,
       self._run.config.name,
       self._run.ConstructDashboardURL())
   pre_cq = self._run.config.pre_cq
   if pre_cq and msg.HasFailureType(failures_lib.InfrastructureFailure):
     name = self._run.config.name
     title = 'pre-cq infra failures'
     body = ['%s failed on %s' % (name, cros_build_lib.GetHostName()),
             '%s' % msg]
     extra_fields = {'X-cbuildbot-alert': 'pre-cq-infra-alert'}
     tree_status.SendHealthAlert(self._run, title, '\n\n'.join(body),
                                 extra_fields=extra_fields)
コード例 #8
0
def WriteTagMetadata(builder_run):
    """Add a 'tags' sub-dict to metadata.

  This is a proof of concept for using tags to help find commonality
  in failures.

  TODO(crbug.com/653342): Refactor to more appropriate locations, and add a lot
  more data. Especially board family, and builder-type.
  """
    # Yes, these values match general metadata values, but they are just
    # proof of concept, so far.
    tags = {
        'bot-hostname': cros_build_lib.GetHostName(fully_qualified=True),
        'build-number': builder_run.buildnumber,
        'builder-name': builder_run.GetBuilderName(),
        'buildbot-url': os.environ.get('BUILDBOT_BUILDBOTURL', ''),
        'buildbot-master-name': os.environ.get('BUILDBOT_MASTERNAME', ''),
        'bot-config': builder_run.config['name'],
        'master_build_id': builder_run.options.master_build_id,
    }

    # Look up the git version.
    try:
        cmd_result = cros_build_lib.RunCommand(['git', '--version'],
                                               capture_output=True)
        tags['git_version'] = cmd_result.output
    except cros_build_lib.RunCommandError:
        pass  # If we fail, just don't include the tag.

    # Look up the repo version.
    try:
        cmd_result = cros_build_lib.RunCommand(['repo', '--version'],
                                               capture_output=True)

        # Convert the following output into 'v1.12.17-cr3':
        #
        # repo version v1.12.17-cr3
        #        (from https://chromium.googlesource.com/external/repo.git)
        # repo launcher version 1.21
        #        (from /usr/local/google/home/dgarrett/sand/depot_tools/repo)
        # git version 2.8.0.rc3.226.g39d4020
        # Python 2.7.6 (default, Jun 22 2015, 17:58:13)
        # [GCC 4.8.2]
        tags['repo_version'] = cmd_result.output.splitlines()[0].split(' ')[-1]
    except (cros_build_lib.RunCommandError, IndexError):
        pass  # If we fail, just don't include the tag.

    builder_run.attrs.metadata.UpdateKeyDictWithDict('testing-tags', tags)
コード例 #9
0
ファイル: goma_util.py プロジェクト: zhangjiayun/chromium.bb
    def _UploadNinjaLog(self, compiler_proxy_path):
        """Uploads .ninja_log file and its related metadata.

    This uploads the .ninja_log file generated by ninja to build Chrome.
    Also, it appends some related metadata at the end of the file following
    '# end of ninja log' marker.

    Args:
      compiler_proxy_path: Path to the compiler proxy, which will be contained
        in the metadata.

    Returns:
      The name of the uploaded file.
    """
        ninja_log_path = os.path.join(self._goma_log_dir, 'ninja_log')
        if not os.path.exists(ninja_log_path):
            logging.warning('ninja_log is not found: %s', ninja_log_path)
            return None
        ninja_log_content = osutils.ReadFile(ninja_log_path)

        try:
            st = os.stat(ninja_log_path)
            ninja_log_mtime = datetime.datetime.fromtimestamp(st.st_mtime)
        except OSError:
            logging.exception('Failed to get timestamp: %s', ninja_log_path)
            return None

        ninja_log_info = self._BuildNinjaInfo(compiler_proxy_path)

        # Append metadata at the end of the log content.
        ninja_log_content += '# end of ninja log\n' + json.dumps(
            ninja_log_info)

        # Aligned with goma_utils in chromium bot.
        pid = os.getpid()

        upload_ninja_log_path = os.path.join(
            self._goma_log_dir, 'ninja_log.%s.%s.%s.%d' %
            (getpass.getuser(), cros_build_lib.GetHostName(),
             ninja_log_mtime.strftime('%Y%m%d-%H%M%S'), pid))
        osutils.WriteFile(upload_ninja_log_path, ninja_log_content)
        uploaded_filename = os.path.basename(upload_ninja_log_path) + '.gz'
        self._gs_context.CopyInto(upload_ninja_log_path,
                                  self._remote_dir,
                                  filename=uploaded_filename,
                                  auto_compress=True,
                                  headers=self._headers)
        return uploaded_filename
コード例 #10
0
 def _SendPreCQInfraAlertMessageIfNeeded(self):
     """Send alerts on Pre-CQ infra failures."""
     msg = self.GetBuildFailureMessage()
     pre_cq = self._run.config.pre_cq
     if (pre_cq and msg.HasExceptionCategories({
             constants.EXCEPTION_CATEGORY_INFRA,
             constants.EXCEPTION_CATEGORY_LAB
     })):
         name = self._run.config.name
         title = 'pre-cq infra failures'
         body = [
             '%s failed on %s' % (name, cros_build_lib.GetHostName()),
             '%s' % msg
         ]
         extra_fields = {'X-cbuildbot-alert': 'pre-cq-infra-alert'}
         alerts.SendHealthAlert(self._run,
                                title,
                                '\n\n'.join(body),
                                extra_fields=extra_fields)
コード例 #11
0
def _ParseArguments(argv):
  parser = commandline.ArgumentParser(description=__doc__)

  parser.add_argument('--app_id', default=None,
                      help='The APP_ID to install.')
  parser.add_argument('--board', help='The board name.', required=True)
  parser.add_argument('--models',
                      help='Models supported by this board, space-separated')
  parser.add_argument('--sysroot', required=True, type='path',
                      help='The sysroot to install the lsb-release file into.')
  parser.add_argument('--version_string', required=True,
                      help='The image\'s version string.')
  parser.add_argument('--builder_path', default=None,
                      help='The image\'s builder path.')
  parser.add_argument('--auserver', default=None,
                      help='The auserver url to use.')
  parser.add_argument('--devserver', default=None,
                      help='The devserver url to use.')
  parser.add_argument('--official', action='store_true',
                      help='Whether or not to populate with fields for an '
                      'official image.')
  parser.add_argument('--buildbot_build', default='N/A',
                      help='The build number, for use with the continuous '
                      'builder.')
  parser.add_argument('--track', default='developer-build',
                      help='The type of release track.')
  parser.add_argument('--branch_number', default='0',
                      help='The branch number.')
  parser.add_argument('--build_number', default='0',
                      help='The build number.')
  parser.add_argument('--chrome_milestone', default='0',
                      help='The Chrome milestone.')
  parser.add_argument('--patch_number', default='0',
                      help='The patch number for the given branch.')
  parser.add_argument('--arc_version', default=None,
                      help='Android revision number of ARC.')
  parser.add_argument('--arc_android_sdk_version', default=None,
                      help='Android SDK version of ARC.')

  opts = parser.parse_args(argv)

  # If the auserver or devserver isn't specified or is set to blank, set it
  # to the host's hostname.
  hostname = cros_build_lib.GetHostName(fully_qualified=True)

  if not opts.auserver:
    opts.auserver = 'http://%s:8080/update' % hostname

  if not opts.devserver:
    opts.devserver = 'http://%s:8080' % hostname

  opts.Freeze()

  if not os.path.isdir(opts.sysroot):
    cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)

  if not opts.version_string:
    cros_build_lib.Die('version_string must not be empty.  Was '
                       'chromeos_version.sh sourced correctly in the calling '
                       'script?')

  return opts
コード例 #12
0
 def testGetHostNameBadDns(self):
     """Do not fail when the user's dns is bad"""
     self.gethostbyaddr_mock.side_effect = socket.gaierror(
         'should be caught')
     self.assertEqual(cros_build_lib.GetHostName(), 'm!!n')
コード例 #13
0
 def testGetHostNameFullyQualified(self):
     """Verify fully qualified behavior"""
     self.assertEqual(cros_build_lib.GetHostName(fully_qualified=True),
                      'm!!n.google.com')
コード例 #14
0
 def testGetHostNameNonQualified(self):
     """Verify non-qualified behavior"""
     self.assertEqual(cros_build_lib.GetHostName(), 'm!!n')
コード例 #15
0
    def testNinjaLogArchive(self):
        """Test successful archive of ninja logs."""
        self._CreateLogFile('compiler_proxy',
                            datetime.datetime(2017, 8, 21, 12, 0, 0))
        self._CreateLogFile('compiler_proxy-subproc',
                            datetime.datetime(2017, 8, 21, 12, 0, 0))

        ninja_log_path = os.path.join(self.goma_log_dir, 'ninja_log')
        osutils.WriteFile(ninja_log_path, 'Ninja Log Content\n')
        timestamp = datetime.datetime(2017, 8, 21, 12, 0, 0)
        mtime = time.mktime(timestamp.timetuple())
        os.utime(ninja_log_path, ((time.time(), mtime)))

        osutils.WriteFile(os.path.join(self.goma_log_dir, 'ninja_command'),
                          'ninja_command')
        osutils.WriteFile(os.path.join(self.goma_log_dir, 'ninja_cwd'),
                          'ninja_cwd')
        osutils.WriteFile(os.path.join(self.goma_log_dir, 'ninja_env'),
                          'key1=value1\0key2=value2\0')
        osutils.WriteFile(os.path.join(self.goma_log_dir, 'ninja_exit'), '0')

        archiver = goma_lib.LogsArchiver(self.goma_log_dir,
                                         dest_dir=self.dest_dir)
        archived_tuple = archiver.Archive()

        username = getpass.getuser()
        pid = os.getpid()
        hostname = cros_build_lib.GetHostName()
        ninjalog_filename = 'ninja_log.%s.%s.20170821-120000.%d.gz' % (
            username, hostname, pid)
        # Verify the archived files in the dest_dir
        archived_files = os.listdir(self.dest_dir)
        self.assertCountEqual(archived_files, [
            ninjalog_filename,
            'compiler_proxy-subproc.host.log.INFO.20170821-120000.000000.gz',
            'compiler_proxy.host.log.INFO.20170821-120000.000000.gz'
        ])
        # Verify the archived_tuple result.
        self.assertFalse(archived_tuple.counterz_file)
        self.assertFalse(archived_tuple.stats_file)
        self.assertCountEqual(archived_tuple.log_files, [
            'compiler_proxy.host.log.INFO.20170821-120000.000000.gz',
            'compiler_proxy-subproc.host.log.INFO.20170821-120000.000000.gz',
            ninjalog_filename
        ])

        # Verify content of ninja_log file.
        ninjalog_path = os.path.join(self.dest_dir, ninjalog_filename)

        with gzip.open(ninjalog_path, 'rt') as gzip_file:
            ninja_log_content = gzip_file.read()

        content, eof, metadata_json = ninja_log_content.split('\n', 3)
        self.assertEqual('Ninja Log Content', content)
        self.assertEqual('# end of ninja log', eof)
        metadata = json.loads(metadata_json)
        self.assertEqual(
            metadata, {
                'platform':
                'chromeos',
                'cmdline': ['ninja_command'],
                'cwd':
                'ninja_cwd',
                'exit':
                0,
                'env': {
                    'key1': 'value1',
                    'key2': 'value2'
                },
                'compiler_proxy_info':
                'compiler_proxy.host.log.INFO.20170821-120000.000000'
            })
コード例 #16
0
def WriteTagMetadata(builder_run):
    """Add a 'tags' sub-dict to metadata.

  This is a proof of concept for using tags to help find commonality
  in failures.
  """
    build_identifier, _ = builder_run.GetCIDBHandle()
    build_id = build_identifier.cidb_id

    # Yes, these values match general metadata values, but they are just
    # proof of concept, so far.
    tags = {
        'bot_config': builder_run.config['name'],
        'bot_hostname': cros_build_lib.GetHostName(fully_qualified=True),
        'build_id': build_id,
        'build_number': builder_run.buildnumber,
        'builder_name': builder_run.GetBuilderName(),
        'buildbot_master_name': os.environ.get('BUILDBOT_MASTERNAME', ''),
        'id': ('Build', build_id),
        'master_build_id': builder_run.options.master_build_id,
        'important': builder_run.config['important'],
    }

    # Guess type of bot.
    tags['bot_type'] = 'unknown'
    if '.golo.' in tags['bot_hostname']:
        tags['bot_type'] = 'golo'
    else:
        gce_types = ['beefy', 'standard', 'wimpy']
        for t in gce_types:
            host_string = 'cros-%s' % t
            if host_string in tags['bot_hostname']:
                tags['bot_type'] = 'gce-%s' % t
                break

    # Look up the git version.
    try:
        cmd_result = cros_build_lib.run(['git', '--version'],
                                        capture_output=True,
                                        encoding='utf-8')
        tags['git_version'] = cmd_result.output.strip()
    except cros_build_lib.RunCommandError:
        pass  # If we fail, just don't include the tag.

    # Look up the repo version.
    try:
        cmd_result = cros_build_lib.run(['repo', '--version'],
                                        capture_output=True,
                                        encoding='utf-8')

        # Convert the following output into 'v1.12.17-cr3':
        #
        # repo version v1.12.17-cr3
        #        (from https://chromium.googlesource.com/external/repo.git)
        # repo launcher version 1.21
        #        (from /usr/local/google/home/dgarrett/sand/depot_tools/repo)
        # git version 2.8.0.rc3.226.g39d4020
        # Python 2.7.6 (default, Jun 22 2015, 17:58:13)
        # [GCC 4.8.2]
        tags['repo_version'] = cmd_result.output.splitlines()[0].split(' ')[-1]
    except (cros_build_lib.RunCommandError, IndexError):
        pass  # If we fail, just don't include the tag.

    builder_run.attrs.metadata.UpdateKeyDictWithDict(constants.METADATA_TAGS,
                                                     tags)