def testRetries(self, mock_fetch):
        mock_fetch.side_effect = urlfetch.Error()
        with self.assertRaises(urlfetch.Error):
            gitiles_service.FileContents('repo', 'commit_hash', 'path')

        mock_fetch.side_effect = urlfetch.Error(), mock.MagicMock(
            content='aGVsbG8=', status_code=200)
        self.assertEqual(
            gitiles_service.FileContents('repo', 'commit_hash', 'path'),
            'hello')

        mock_fetch.side_effect = Exception(), mock.MagicMock(
            content='aGVsbG8=', status_code=200)
        with self.assertRaises(Exception):
            gitiles_service.FileContents('repo', 'commit_hash', 'path')
Ejemplo n.º 2
0
    def Deps(self):
        """Return the DEPS of this Dep as a frozenset of Deps."""
        # Download and execute DEPS file.
        deps_file_contents = gitiles_service.FileContents(
            self.repository_url, self.git_hash, 'DEPS')
        deps_data = {'Var': lambda variable: deps_data['vars'][variable]}
        exec deps_file_contents in deps_data  # pylint: disable=exec-used

        # Pull out deps dict, including OS-specific deps.
        deps_dict = deps_data['deps']
        for deps_os in deps_data.get('deps_os', {}).itervalues():
            deps_dict.update(deps_os)

        # Convert deps strings to Dep objects.
        deps = []
        for dep_string in deps_dict.itervalues():
            dep_string_parts = dep_string.split('@')
            if len(dep_string_parts) < 2:
                continue  # Dep is not pinned to any particular revision.
            if len(dep_string_parts) > 2:
                raise NotImplementedError('Unknown DEP format: ' + dep_string)

            repository_url, git_hash = dep_string_parts
            repository = _Repository(repository_url)
            if not repository:
                _AddRepository(repository_url)
                repository = _Repository(repository_url)
            deps.append(Dep(repository, git_hash))

        return frozenset(deps)
Ejemplo n.º 3
0
    def Deps(self):
        """Return the DEPS of this Commit as a frozenset of Commits."""
        # Download and execute DEPS file.
        try:
            deps_file_contents = gitiles_service.FileContents(
                self.repository_url, self.git_hash, 'DEPS')
        except gitiles_service.NotFoundError:
            return frozenset()  # No DEPS file => no DEPS.

        deps_data = {'Var': lambda variable: deps_data['vars'][variable]}
        exec deps_file_contents in deps_data  # pylint: disable=exec-used

        # Pull out deps dict, including OS-specific deps.
        deps_dict = deps_data['deps']
        for deps_os in deps_data.get('deps_os', {}).itervalues():
            deps_dict.update(deps_os)

        # Convert deps strings to Commit objects.
        commits = []
        for dep_string in deps_dict.itervalues():
            dep_string_parts = dep_string.split('@')
            if len(dep_string_parts) < 2:
                continue  # Dep is not pinned to any particular revision.
            if len(dep_string_parts) > 2:
                raise NotImplementedError('Unknown DEP format: ' + dep_string)

            repository_url, git_hash = dep_string_parts
            repository = repository_module.Repository(repository_url,
                                                      add_if_missing=True)
            commits.append(Commit(repository, git_hash))

        return frozenset(commits)
Ejemplo n.º 4
0
    def testCache(self):
        self._request_json.return_value = {'log': []}
        self._request.return_value = 'aGVsbG8='

        repository = 'https://chromium.googlesource.com/repo'
        git_hash = '3a44bc56c4efa42a900a1c22b001559b81e457e9'

        gitiles_service.CommitInfo(repository, git_hash)
        self._request_json.assert_called_with(
            '%s/+/%s?format=JSON' % (repository, git_hash),
            use_cache=True,
            use_auth=True,
            scope=gerrit_service.GERRIT_SCOPE)

        gitiles_service.CommitRange(repository, git_hash, git_hash)
        self._request_json.assert_called_with(
            '%s/+log/%s..%s?format=JSON' % (repository, git_hash, git_hash),
            use_cache=True,
            use_auth=True,
            scope=gerrit_service.GERRIT_SCOPE)

        gitiles_service.FileContents(repository, git_hash, 'path')
        self._request.assert_called_with('%s/+/%s/path?format=TEXT' %
                                         (repository, git_hash),
                                         use_cache=True,
                                         use_auth=True,
                                         scope=gerrit_service.GERRIT_SCOPE)
Ejemplo n.º 5
0
def _PerformPerfTryJob(perf_job):
    """Performs the perf try job on the try bot.

  This creates a patch, uploads it, then tells Rietveld to try the patch.

  Args:
    perf_job: TryJob entity with initialized bot name and config.

  Returns:
    A dictionary containing the result; if successful, this dictionary contains
    the field "issue_id", otherwise it contains "error".
  """
    assert perf_job.bot and perf_job.config

    if not perf_job.key:
        perf_job.put()

    bot = perf_job.bot
    email = perf_job.email

    config_dict = perf_job.GetConfigDict()
    config_dict['try_job_id'] = perf_job.key.id()
    perf_job.config = utils.BisectConfigPythonString(config_dict)

    # Get the base config file contents and make a patch.
    try:
        base_config = gitiles_service.FileContents(
            'https://chromium.googlesource.com/chromium/src', 'master',
            _PERF_CONFIG_PATH)
    except (urlfetch.Error, gitiles_service.NotFoundError):
        base_config = None

    if not base_config:
        return {'error': 'Error downloading base config'}
    patch, base_checksum, base_hashes = _CreatePatch(base_config,
                                                     perf_job.config,
                                                     _PERF_CONFIG_PATH)

    # Upload the patch to Rietveld.
    server = rietveld_service.RietveldService()
    subject = 'Perf Try Job on behalf of %s' % email
    issue_id, patchset_id = server.UploadPatch(subject, patch, base_checksum,
                                               base_hashes, base_config,
                                               _PERF_CONFIG_PATH)

    if not issue_id:
        return {'error': 'Error uploading patch to rietveld_service.'}
    url = 'https://codereview.chromium.org/%s/' % issue_id

    # Tell Rietveld to try the patch.
    master = 'tryserver.chromium.perf'
    trypatch_success = server.TryPatch(master, issue_id, patchset_id, bot)
    if trypatch_success:
        # Create TryJob entity. The update_bug_with_results and auto_bisect
        # cron jobs will be tracking, or restarting the job.
        perf_job.rietveld_issue_id = int(issue_id)
        perf_job.rietveld_patchset_id = int(patchset_id)
        perf_job.SetStarted()
        return {'issue_id': issue_id}
    return {'error': 'Error starting try job. Try to fix at %s' % url}
 def testCustomHostname(self, mock_fetch):
     mock_fetch.return_value = mock.MagicMock(content='aGVsbG8=',
                                              status_code=200)
     gitiles_service.FileContents('repo',
                                  'commit_hash',
                                  'path',
                                  hostname='https://example.com')
     mock_fetch.assert_called_once_with(
         'https://example.com/repo/+/commit_hash/path?format=TEXT')
 def testFileContents(self, mock_fetch):
     mock_fetch.return_value = mock.MagicMock(content='aGVsbG8=',
                                              status_code=200)
     self.assertEqual(
         gitiles_service.FileContents('repo', 'commit_hash', 'path'),
         'hello')
     mock_fetch.assert_called_once_with(
         'https://chromium.googlesource.com/repo/+/commit_hash/path?format=TEXT'
     )
Ejemplo n.º 8
0
    def Deps(self):
        """Return the DEPS of this Commit.

    Returns Dep namedtuples with repository URLs instead of Commit objects,
    because Commit objects must have their repositories verified in the
    datastore, and we'd like to do that more lazily.

    Returns:
      A frozenset of Dep (repository_url, git_hash) namedtuples.
    """
        # Download and execute DEPS file.
        try:
            deps_file_contents = gitiles_service.FileContents(
                self.repository_url, self.git_hash, 'DEPS')
        except gitiles_service.NotFoundError:
            return frozenset()  # No DEPS file => no DEPS.

        deps_data = {'Var': lambda variable: deps_data['vars'][variable]}
        exec(deps_file_contents, deps_data)  # pylint: disable=exec-used

        # Pull out deps dict, including OS-specific deps.
        deps_dict = deps_data.get('deps', {})
        if not deps_dict:
            return frozenset()

        for deps_os in deps_data.get('deps_os', {}).values():
            deps_dict.update(deps_os)

        # Pull out vars dict to format brace variables.
        vars_dict = deps_data.get('vars', {})

        # Convert deps strings to repository and git hash.
        commits = []
        for dep_value in deps_dict.values():
            if isinstance(dep_value, basestring):
                dep_string = dep_value
            else:
                if 'url' not in dep_value:
                    # We don't support DEPS that are CIPD packages.
                    continue
                dep_string = dep_value['url']
                if 'revision' in dep_value:
                    dep_string += '@' + dep_value['revision']

            dep_string_parts = dep_string.format(**vars_dict).split('@')
            if len(dep_string_parts) < 2:
                continue  # Dep is not pinned to any particular revision.
            if len(dep_string_parts) > 2:
                raise NotImplementedError('Unknown DEP format: ' + dep_string)

            repository_url, git_hash = dep_string_parts
            if repository_url.endswith('.git'):
                repository_url = repository_url[:-4]
            commits.append(Dep(repository_url, git_hash))

        return frozenset(commits)
Ejemplo n.º 9
0
    def Deps(self):
        """Return the DEPS of this Commit.

    Returns Dep namedtuples with repository URLs instead of Commit objects,
    because Commit objects must have their repositories verified in the
    datastore, and we'd like to do that more lazily.

    Returns:
      A frozenset of Dep (repository_url, git_hash) namedtuples.
    """
        # Download and execute DEPS file.
        git_hash = str(self.git_hash).strip()
        try:
            deps_file_contents = gitiles_service.FileContents(
                self.repository_url,
                git_hash,
                'DEPS',
            )
        except gitiles_service.NotFoundError:
            return frozenset()  # No DEPS file => no DEPS.

        try:
            deps_data = gclient_eval.Parse(
                deps_file_contents, '{}@{}/DEPS'.format(
                    self.repository_url,
                    git_hash,
                ))
        except gclient_eval.Error:
            return frozenset()  # Invalid/unparseable DEPS file => no DEPS.

        # Pull out deps dict, including OS-specific deps.
        deps_dict = deps_data.get('deps', {})
        if not deps_dict:
            return frozenset()

        # Convert deps strings to repository and git hash.
        commits = []
        for dep_value in deps_dict.values():
            if dep_value.get('dep_type') != 'git':
                # We don't support DEPS that are CIPD packages.
                continue

            dep_string = dep_value.get('url', '')

            dep_string_parts = dep_string.split('@')
            if len(dep_string_parts) < 2:
                continue  # Dep is not pinned to any particular revision.
            if len(dep_string_parts) > 2:
                raise NotImplementedError('Unknown DEP format: ' + dep_string)

            repository_url, dep_git_hash = dep_string_parts
            if repository_url.endswith('.git'):
                repository_url = repository_url[:-4]
            commits.append(Dep(repository_url, dep_git_hash.strip()))

        return frozenset(commits)
Ejemplo n.º 10
0
 def testFileContents(self):
     self._request.return_value = 'aGVsbG8='
     self.assertEqual(
         gitiles_service.FileContents(
             'https://chromium.googlesource.com/repo', 'commit_hash',
             'path'), 'hello')
     self._request.assert_called_once_with(
         'https://chromium.googlesource.com/repo/+/commit_hash/path?format=TEXT',
         use_cache=False,
         use_auth=False)
Ejemplo n.º 11
0
 def testNotFound(self, mock_fetch):
     mock_fetch.side_effect = gitiles_service.NotFoundError()
     with self.assertRaises(gitiles_service.NotFoundError):
         gitiles_service.FileContents('repo', 'commit_hash', 'path')
Ejemplo n.º 12
0
 def testNotFound(self, mock_fetch):
     mock_fetch.side_effect = gitiles_service.NotFoundError()
     with self.assertRaises(gitiles_service.NotFoundError):
         gitiles_service.FileContents(
             'https://chromium.googlesource.com/repo', 'commit_hash',
             'path')
Ejemplo n.º 13
0
 def testFileContents(self, mock_fetch):
   mock_fetch.return_value = mock.MagicMock(
       content='aGVsbG8=', status_code=200)
   self.assertEqual(
       gitiles_service.FileContents('repo', 'commit_hash', 'path'),
       'hello')