def test_run_on_linux(self):
        host = MockHost(os_name='linux')
        host.filesystem.maybe_make_directory(
            '/mock-checkout/third_party/depot_tools')

        luci_auth = LuciAuth(host)
        luci_auth.get_access_token()
        self.assertListEqual(
            host.executive.calls,
            [['/mock-checkout/third_party/depot_tools/luci-auth', 'token']])
Esempio n. 2
0
 def _check_luci_auth(self):
     try:
         LuciAuth(self._host).get_access_token()
     except Exception as ex:
         _log.exception('Caught an exception when checking luci '
                        'authentication. Please run `luci-auth login` '
                        'before trying again.')
         raise ex
Esempio n. 3
0
 def _get_monorail_api(self, service_account_key_json):
     if service_account_key_json:
         return self._monorail_api(
             service_account_key_json=service_account_key_json)
     token = LuciAuth(self.host).get_access_token()
     return self._monorail_api(access_token=token)
Esempio n. 4
0
    def fetch_raw_try_job_results(self, issue_number, patchset=None):
        """Gets try job results for the specified CL from buildbucket.

        This uses the SearchBuilds rpc format specified in
        https://cs.chromium.org/chromium/infra/go/src/go.chromium.org/luci/buildbucket/proto/rpc.proto

        The response is a list of dicts of the following form:
        {
            "builds": [
                {
                    "status": <status>
                    "builder": {
                        "builder": <builder_name>
                    },
                    "number": <build_number>,
                    "tags": [
                        {
                            "key": <tag key>
                            "value": <tag value>
                        },
                        ... more tags
                    ]
                },
                ... more builds
        }

        This method returns the JSON representation of the above response.
        """
        if not patchset:
            patchset = self._get_latest_patchset()

        luci_token = LuciAuth(self._host).get_access_token()
        hed = {
            'Authorization': 'Bearer ' + luci_token,
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        }
        data = {
            'predicate': {
                'gerritChanges': [{
                    'host': 'chromium-review.googlesource.com',
                    'project': 'chromium/src',
                    'change': issue_number,
                    'patchset': patchset
                }]
            },
            'fields':
            'builds.*.builder.builder,builds.*.status,builds.*.tags,builds.*.number'
        }
        url = 'https://cr-buildbucket.appspot.com/prpc/buildbucket.v2.Builds/SearchBuilds'
        req_body = json.dumps(data)
        _log.debug("Sending SearchBuilds request. Url: %s with Body: %s" %
                   (url, req_body))
        response = self._host.web.request('POST',
                                          url,
                                          data=req_body,
                                          headers=hed)
        if response.getcode() == 200:
            response_body = response.read()
            if response_body.startswith(SEARCHBUILDS_RESPONSE_PREFIX):
                response_body = response_body[len(SEARCHBUILDS_RESPONSE_PREFIX
                                                  ):]
            return json.loads(response_body)

        _log.error(
            "Failed to fetch tryjob results from buildbucket (status=%s)" %
            response.status)
        _log.debug("Full SearchBuilds response: %s" % str(response))
        return None