forked from VallariAg/teuthology-api
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsuite.py
34 lines (28 loc) · 990 Bytes
/
suite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import logging
from fastapi import APIRouter, HTTPException, Depends, Request
from teuthology_api.services.suite import run
from teuthology_api.services.helpers import get_token, get_username
from teuthology_api.schemas.suite import SuiteArgs
log = logging.getLogger(__name__)
router = APIRouter(
prefix="/suite",
tags=["suite"],
responses={404: {"description": "Not found"}},
)
@router.post("/", status_code=200)
def create_run(
request: Request,
args: SuiteArgs,
access_token: str = Depends(get_token),
logs: bool = False,
):
try:
args = args.model_dump(by_alias=True)
args["--user"] = get_username(request)
return run(args, logs, access_token)
except HTTPException as exc:
log.error(f"HTTP exception occurred: {exc.detail}")
raise
except Exception as exc:
log.error(f"Unexpected error occurred: {repr(exc)}")
raise HTTPException(status_code=500, detail="An unexpected error occurred.")