Esempio n. 1
0
    def put(self, build_id: str = None):  # pragma: no cover
        """Trigger build start hook."""

        # TODO: run all of the following ops asynchronously
        errors = {}

        build_schema = BuildInfoSchema()
        build_data: dict = request.json
        build_data['build_log'] = None

        if not any([build_data, build_id]):
            errors['build_data'] = "Invalid or missing build data."

        validation_errors = build_schema.validate(build_data)

        if validation_errors.get('build_id', None) and not build_id:
            # build_id is not provided at all
            errors['build_id'] = "Invalid or missing `build_id`."

        if not errors:  # validation errors other than build_id are permitted for now
            # store in Ceph
            build_aggregator.store_build_data(build_data)

            return request_accepted(errors=validation_errors)

        else:
            errors.update(validation_errors)

            return bad_request(errors=errors)
Esempio n. 2
0
def handle_schema_validation_error(error: ValidationError):
    """Handle exceptions caused by OC CLI."""
    error_dct = error.messages

    app.logger.error(traceback.format_exc())

    resp, code = bad_request(errors=error_dct)
    return jsonify(resp), code
Esempio n. 3
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
Esempio n. 4
0
    def put(self, build_id: str = None):  # pragma: no cover
        """Trigger build start hook."""
        # TODO: run all of the following ops asynchronously
        errors = {}

        build_schema = BuildInfoSchema()
        build_data: dict = request.json

        if build_data['build_id'] != build_id:
            errors['build_data'] = "`build_id` field does not match given url."

        validation_errors = build_schema.validate(build_data)

        if not errors:  # validation errors other than build_id are permitted for now
            # store in Ceph
            build_data['build_log'] = None
            build_aggregator.store_build_data(build_data)

            return request_accepted(errors=validation_errors)

        else:
            errors.update(validation_errors)

            return bad_request(errors=errors)