Exemple #1
0
    def testFetchMissingPieces(self, mocked_fetch):
        response_pb = rpc_pb2.SearchBuildsResponse()
        build_pb = response_pb.builds.add()
        build_pb.number = 123
        build_pb.status = common_pb2.SCHEDULED
        mocked_fetch.return_value = response_pb

        builds = lkgr_lib.FetchBuildbucketBuildsForBuilder(
            'project1/bucket1', 'builder1')
        self.assertEquals(builds, [])
Exemple #2
0
    def testFetchBuildFailed(self, mocked_fetch):
        response_pb = rpc_pb2.SearchBuildsResponse()
        build_pb = response_pb.builds.add()
        build_pb.number = 123
        build_pb.status = common_pb2.FAILURE
        build_pb.input.gitiles_commit.id = 'a' * 40
        mocked_fetch.return_value = response_pb

        builds = lkgr_lib.FetchBuildbucketBuildsForBuilder(
            'project1/bucket1', 'builder1')
        self.assertEquals(
            builds, [lkgr_lib.Build(123, lkgr_lib.STATUS.FAILURE, 'a' * 40)])
Exemple #3
0
def _FetchFromBuildbucketImpl(project,
                              bucket_name,
                              builder,
                              service_account_file=None):  # pragma: no cover
    request_pb = rpc_pb2.SearchBuildsRequest()
    request_pb.predicate.builder.project = project
    request_pb.predicate.builder.bucket = bucket_name
    request_pb.predicate.builder.builder = builder
    request_pb.predicate.status = common_pb2.ENDED_MASK
    request_pb.fields.paths.extend([
        'builds.*.number',
        'builds.*.status',
        'builds.*.input.gitiles_commit.id',
    ])

    headers = {
        'Accept': 'application/prpc; encoding=binary',
        'Content-Type': 'application/prpc; encoding=binary',
    }

    http = httplib2.Http(timeout=300)
    creds = None
    if service_account_file:
        creds = infra_libs.get_signed_jwt_assertion_credentials(
            service_account_file, scope=OAUTH_SCOPES)
    elif luci_auth.available():
        creds = luci_auth.LUCICredentials(scopes=OAUTH_SCOPES)
    if creds:
        creds.authorize(http)

    resp, content = http.request(_BUILDBUCKET_SEARCH_ENDPOINT_V2.format(
        buildbucket_instance=_DEFAULT_BUILDBUCKET_INSTANCE),
                                 method='POST',
                                 headers=headers,
                                 body=request_pb.SerializeToString())
    grpc_code = resp.get('X-Prpc-Grpc-Code'.lower())
    if grpc_code != '0':
        raise httplib2.HttpLib2Error('Invalid GRPC exit code: %s\n%s' %
                                     (grpc_code, content))
    response_pb = rpc_pb2.SearchBuildsResponse()
    response_pb.ParseFromString(content)

    return response_pb