Beispiel #1
0
  def testContextManagerException(self):
    """Test that we fail when an exception is raised."""
    with self.assertRaises(FakeException):
      with metrics.Presence('fooname'):
        raise FakeException

    self.assertEqual(self._mockMetric.mock_calls, [
        mock.call.set(True, fields=None),
        mock.call.set(False, fields=None),
    ])
Beispiel #2
0
  def testContextManager(self):
    """Test that timing context manager emits a metric."""
    with metrics.Presence('fooname'):
      self.assertEquals(self._mockMetric.mock_calls, [
          mock.call.set(True, fields=None),
      ])

    self.assertEquals(self._mockMetric.mock_calls, [
        mock.call.set(True, fields=None),
        mock.call.set(False, fields=None),
    ])
Beispiel #3
0
    def testContextManagerFields(self):
        """Test that we fail when an exception is raised."""
        with metrics.Presence('fooname', {'foo': 'bar', 'c': 3}):
            pass

        self.assertEqual(self._mockMetric.mock_calls, [
            mock.call.set(True, fields={
                'c': 3,
                'foo': 'bar'
            }),
            mock.call.set(False, fields={
                'c': 3,
                'foo': 'bar'
            }),
        ])
def _main(options, argv):
    """main method of script.

  Args:
    options: preparsed options object for the build.
    argv: All command line arguments to pass as list of strings.

  Returns:
    Return code of cbuildbot as an integer.
  """
    branchname = options.branch or 'master'
    root = options.buildroot
    buildroot = os.path.join(root, 'repository')
    workspace = os.path.join(root, 'workspace')
    depot_tools_path = os.path.join(buildroot, constants.DEPOT_TOOLS_SUBPATH)

    # Does the entire build pass or fail.
    with metrics.Presence(METRIC_ACTIVE), \
         metrics.SuccessCounter(METRIC_COMPLETED) as s_fields:

        # Preliminary set, mostly command line parsing.
        with metrics.SuccessCounter(METRIC_INVOKED):
            if options.enable_buildbot_tags:
                logging.EnableBuildbotMarkers()
            ConfigureGlobalEnvironment()

        # Prepare the buildroot with source for the build.
        with metrics.SuccessCounter(METRIC_PREP):
            manifest_url = config_lib.GetSiteParams().MANIFEST_INT_URL
            repo = repository.RepoRepository(
                manifest_url,
                buildroot,
                branch=branchname,
                git_cache_dir=options.git_cache_dir)
            previous_build_state = GetLastBuildState(root)

            # Clean up the buildroot to a safe state.
            with metrics.SecondsTimer(METRIC_CLEAN):
                build_state = GetCurrentBuildState(options, branchname)
                CleanBuildRoot(root, repo, options.cache_dir, build_state)

            # Get a checkout close enough to the branch that cbuildbot can handle it.
            if options.sync:
                with metrics.SecondsTimer(METRIC_INITIAL):
                    InitialCheckout(repo)

        # Run cbuildbot inside the full ChromeOS checkout, on the specified branch.
        with metrics.SecondsTimer(METRIC_CBUILDBOT), \
             metrics.SecondsInstanceTimer(METRIC_CBUILDBOT_INSTANCE):
            if previous_build_state.is_valid():
                argv.append('--previous-build-state')
                argv.append(
                    base64.b64encode(previous_build_state.to_json().encode(
                        'utf-8')).decode('utf-8'))
            argv.extend(['--workspace', workspace])

            if not options.cache_dir_specified:
                argv.extend(['--cache-dir', options.cache_dir])

            result = Cbuildbot(buildroot, depot_tools_path, argv)
            s_fields['success'] = (result == 0)

            build_state.status = (constants.BUILDER_STATUS_PASSED if result
                                  == 0 else constants.BUILDER_STATUS_FAILED)
            SetLastBuildState(root, build_state)

            with metrics.SecondsTimer(METRIC_CHROOT_CLEANUP):
                CleanupChroot(buildroot)

            return result
Beispiel #5
0
def _main(argv):
    """main method of script.

  Args:
    argv: All command line arguments to pass as list of strings.

  Returns:
    Return code of cbuildbot as an integer.
  """
    options = PreParseArguments(argv)

    branchname = options.branch or 'master'
    root = options.buildroot
    buildroot = os.path.join(root, 'repository')
    depot_tools_path = os.path.join(buildroot, constants.DEPOT_TOOLS_SUBPATH)

    metrics_fields = {
        'branch_name': branchname,
        'build_config': options.build_config_name,
        'tryjob': options.remote_trybot,
    }

    # Does the entire build pass or fail.
    with metrics.Presence(METRIC_ACTIVE, metrics_fields), \
         metrics.SuccessCounter(METRIC_COMPLETED, metrics_fields) as s_fields:

        # Preliminary set, mostly command line parsing.
        with metrics.SuccessCounter(METRIC_INVOKED, metrics_fields):
            if options.enable_buildbot_tags:
                logging.EnableBuildbotMarkers()
            ConfigureGlobalEnvironment()

        # Prepare the buildroot with source for the build.
        with metrics.SuccessCounter(METRIC_PREP, metrics_fields):
            site_config = config_lib.GetConfig()
            manifest_url = site_config.params['MANIFEST_INT_URL']
            repo = repository.RepoRepository(
                manifest_url,
                buildroot,
                branch=branchname,
                git_cache_dir=options.git_cache_dir)
            previous_build_state = GetLastBuildState(root)

            # Clean up the buildroot to a safe state.
            with metrics.SecondsTimer(METRIC_CLEAN, fields=metrics_fields):
                build_state = GetCurrentBuildState(options, branchname)
                CleanBuildRoot(root, repo, metrics_fields, build_state)

            # Get a checkout close enough to the branch that cbuildbot can handle it.
            if options.sync:
                with metrics.SecondsTimer(METRIC_INITIAL,
                                          fields=metrics_fields):
                    InitialCheckout(repo)

            # Get a checkout close enough to the branch that cbuildbot can handle it.
            with metrics.SecondsTimer(METRIC_DEPOT_TOOLS,
                                      fields=metrics_fields):
                DepotToolsEnsureBootstrap(depot_tools_path)

        # Run cbuildbot inside the full ChromeOS checkout, on the specified branch.
        with metrics.SecondsTimer(METRIC_CBUILDBOT, fields=metrics_fields):
            if previous_build_state.is_valid():
                argv.append('--previous-build-state')
                argv.append(base64.b64encode(previous_build_state.to_json()))

            result = Cbuildbot(buildroot, depot_tools_path, argv)
            s_fields['success'] = (result == 0)

            build_state.status = (constants.BUILDER_STATUS_PASSED if result
                                  == 0 else constants.BUILDER_STATUS_FAILED)
            SetLastBuildState(root, build_state)

            CleanupChroot(buildroot)
            return result