def test_update(proj, build_id, run, test): r = _get_run(proj, build_id, run) _authenticate_runner(r) t = Test.query.filter_by(name=test).filter(Test.run.has(Run.id == r.id)) context = request.args.get("context") if context: t = t.filter(Test.context == context) t = t.first_or_404() json = request.get_json() if json: msg = json.get("message") status = json.get("status") results = json.get("results", []) storage = Storage() if msg: with storage.console_logfd(r, "a") as f: f.write(msg) if results: for tr in results: create_test_result(t, tr) db.session.commit() if status: run_status = t.set_status(status) db.session.commit() if run_status in (BuildStatus.PASSED, BuildStatus.FAILED): storage.copy_log(r) if run_status is not None: with r.build.locked(): t.run.set_status(run_status) if r.complete: _handle_triggers(storage, r) return jsendify({"complete": t.run.complete})
def run_update(proj, build_id, run): r = _get_run(proj, build_id, run) _authenticate_runner(r) storage = Storage() if request.data: with storage.console_logfd(r, 'ab') as f: f.write(request.data) metadata = request.headers.get('X-RUN-METADATA') if metadata: r.meta = metadata db.session.commit() status = request.headers.get('X-RUN-STATUS') if status: status = BuildStatus[status] if r.status != status: if status in (BuildStatus.PASSED, BuildStatus.FAILED): if _running_tests(r): status = BuildStatus.RUNNING if _failed_tests(storage, r): status = BuildStatus.FAILED storage.copy_log(r) with r.build.locked(): r.set_status(status) if r.complete: _handle_triggers(storage, r) resp = jsendify({}) if r.status == BuildStatus.CANCELLING: resp.headers['X-JOBSERV-CANCEL'] = '1' return resp
def _fail_unexpected(build, exception): r = Run(build, "build-failure") db.session.add(r) r.set_status(BuildStatus.FAILED) db.session.commit() storage = Storage() with storage.console_logfd(r, "a") as f: f.write("Unexpected error prevented build from running:\n") f.write(str(exception)) storage.copy_log(r) if BUILD_URL_FMT: url = BUILD_URL_FMT.format(project=build.project.name, build=build.build_id) else: url = url_for( "api_run.run_get_artifact", proj=build.project.name, build_id=build.build_id, run=r.name, path="console.log", ) exception = ApiError(500, str(exception)) exception.resp.headers.extend({"Location": url}) return exception