Exemple #1
0
    def get(self, build_id):
        """Return logs stored by the given build."""
        build_log, = build_aggregator.retrieve_build_data(build_id,
                                                          log_only=True)

        # TODO: return the whole doc or just the build log?
        return request_ok(payload=build_log)
Exemple #2
0
    def put(self, build_id: str = None):  # pragma: no cover
        """Trigger build completion hook."""
        log_level: int = request.args.get('log_level', DEFAULT_OC_LOG_LEVEL)

        # TODO: run all of the following ops asynchronously
        # get stored build info
        build_info: BuildInfo
        _, build_info = build_aggregator.retrieve_build_data(build_id)

        build_schema = BuildInfoSchema()

        build_data: dict = request.json
        build_info.build_status = build_data['build_status']
        build_info.build_log_url = url_for('build_build_log_resource',
                                           build_id=build_id,
                                           _external=True)

        # get build log
        build_log: str = build_aggregator.get_build_log(
            build_id,
            namespace=build_info.ocp_info.namespace,
            log_level=log_level)

        # TODO: handle validation errors
        build_doc, validation_errors = build_schema.dump(build_info)
        build_doc['build_log'] = build_log

        # store in Ceph
        build_aggregator.store_build_data(build_doc)

        return request_accepted(errors=validation_errors)
Exemple #3
0
    def get(self, build_id):
        """Return complete information stored about given build."""

        schema = BuildInfoSchema()
        _, build_info = build_aggregator.retrieve_build_data(build_id)

        return request_ok(payload=schema.dump(build_info))
Exemple #4
0
def _on_build_completed(build_id: str,
                        build_data: dict,
                        get_build_log=False,
                        log_level: int = DEFAULT_OC_LOG_LEVEL):
    """Update Ceph build data.

    :returns: validation errors produced by BuildInfoSchema schema validation.
    """
    # TODO: run all of the following ops asynchronously
    build_schema = BuildInfoSchema()

    build_info: BuildInfo
    try:
        _, build_info = build_aggregator.retrieve_build_data(build_id)

        build_info.build_status = build_data['build_status']
    except NotFoundError:
        # store the document even if there is no previous build started record
        # this can happen if the observer is deployed into running environment
        build_data.update({'build_id': build_id})
        build_info = build_schema.load(build_data)

    build_info.build_log_url = url_for('build_build_log_resource',
                                       build_id=build_id,
                                       _external=True)

    build_doc, validation_errors = build_schema.dump(build_info)

    if get_build_log:
        # get build log from relevant pod (requires OpenShift authentication)
        build_log: str = build_aggregator.get_build_log(
            build_id,
            namespace=build_info.ocp_info.namespace,
            log_level=log_level)

        build_doc['build_log'] = build_log

    # store in Ceph
    build_aggregator.store_build_data(build_doc)

    return validation_errors
Exemple #5
0
    def put(self, build_id):
        """Store logs for the given build in Ceph."""
        build_log, build_info = build_aggregator.retrieve_build_data(build_id)

        if build_log is not None and not int(request.args.get('force', 1)):

            return bad_request(
                errors={
                    'BuildLogExists':
                    f"Build log `{build_id}` already exists"
                    " and `force` is not specified."
                })

        build_doc, _ = BuildInfoSchema().dump(build_info)

        build_log_schema = BuildLogSchema()
        build_log, validation_errors = build_log_schema.load(request.json)

        if not build_info.build_complete():
            resp = bad_request(errors={
                'BuildNotCompleted':
                "Build has not been completed yet.",
            },
                               validation_errors=validation_errors)

        else:
            if 'build_id' not in build_log['metadata']:
                build_log['metadata']['build_id'] = build_id

            build_doc['build_log'] = build_log

            build_aggregator.store_build_data(build_doc)

            resp = request_ok()

        return resp
Exemple #6
0
    def get(self, build_id):
        """Return status of the given build."""
        _, build_info = build_aggregator.retrieve_build_data(build_id)

        return request_ok(payload={'build_status': build_info.build_status})