Esempio n. 1
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)
Esempio n. 2
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. 3
0
    def put(self, build_id: str = None):  # pragma: no cover
        """Trigger build start hook."""
        build_schema = BuildInfoSchema()

        build_data, validation_errors = build_schema.dump(
            BuildInfo.from_resource(request.json, build_id))

        # store in Ceph
        build_data['build_log'] = None
        build_aggregator.store_build_data(build_data)

        return request_accepted(errors=validation_errors)
Esempio n. 4
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)

        build_data: dict = request.json
        validation_errors = _on_build_completed(build_id,
                                                build_data,
                                                get_build_log=request.args.get(
                                                    'mode',
                                                    'remote') == 'cluster',
                                                log_level=log_level)

        return request_accepted(errors=validation_errors)
Esempio n. 5
0
    def put(self, build_id: str = None):  # pragma: no cover
        """Trigger build start hook."""
        build_schema = BuildInfoSchema()

        kube_client = ApiClient()

        event: V1Event = kube_client.deserialize(request,
                                                 response_type='V1Event')
        build_data, validation_errors = build_schema.dump(
            BuildInfo.from_event(event, build_id))

        # store in Ceph
        build_data['build_log'] = None
        build_aggregator.store_build_data(build_data)

        return request_accepted(errors=validation_errors)
Esempio n. 6
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)

        build_schema = BuildInfoSchema()

        build_data, _ = build_schema.dump(
            BuildInfo.from_resource(request.json, build_id))

        # TODO: handle validation errors
        validation_errors = _on_build_completed(build_id,
                                                build_data,
                                                get_build_log=request.args.get(
                                                    'mode',
                                                    'remote') == 'cluster',
                                                log_level=log_level)

        return request_accepted(errors=validation_errors)
Esempio n. 7
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)

        build_schema = BuildInfoSchema()

        kube_client = ApiClient()

        event: V1Event = kube_client.deserialize(request,
                                                 response_type='V1Event')
        build_data, _ = build_schema.dump(BuildInfo.from_event(
            event, build_id))

        # TODO: handle validation errors
        validation_errors = _on_build_completed(build_id,
                                                build_data,
                                                get_build_log=request.args.get(
                                                    'mode',
                                                    'remote') == 'cluster',
                                                log_level=log_level)

        return request_accepted(errors=validation_errors)
Esempio n. 8
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)