Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for API endpoints #17

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
SESSION_SECRET_KEY = os.getenv("SESSION_SECRET_KEY")

log = logging.getLogger(__name__)
app = FastAPI()
app = FastAPI(
title="Teuthology API", description="REST API for executing Teuthology commands"
)


@app.get("/")
Expand Down
59 changes: 54 additions & 5 deletions src/routes/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,68 @@
)


@router.post("/", status_code=200)
@router.post(
"/",
status_code=200,
responses={
200: {
"description": "Run killed successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"log": {
"type": "array",
"description": "List of logs while executing teuthology-kill",
"items": {"type": "string"},
},
"kill": {
"type": "array",
"description": "Teuthology-kill executed successfully",
"items": {"type": "string"},
},
},
"example": '{"kill": "success"}',
}
}
},
},
400: {
"description": "Missing argument(s) in request body",
"content": {
"application/json": {
"schema": {
"type": "string",
"example": "--run is a required argument",
}
}
},
},
401: {
"description": "Authorization error: Either user is not logged in or doesn't have the permission to kill the run",
"content": {
"application/json": {
"schema": {"type": "string", "example": "You need to be logged in"}
}
},
},
500: {
"description": "Error while executing teuthology command",
"content": {"application/json": {"schema": {"type": "string"}}},
},
},
)
def create_run(
request: Request,
args: KillArgs,
logs: bool = False,
access_token: str = Depends(get_token),
):
"""
POST route for killing a run or a job.
Endpoint for killing a run or a job.

Note: I needed to put `request` before `args`
or else it will SyntaxError: non-dafault
argument follows default argument error.
Requires user's GitHub `access_token` for authorization.
"""
args = args.dict(by_alias=True)
return run(args, logs, access_token, request)
17 changes: 17 additions & 0 deletions src/schemas/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ class KillArgs(BaseArgs):
jobspec: Union[str, None] = Field(default=None, alias="--jobspec")
machine_type: Union[str, None] = Field(default="default", alias="--machine-type")
archive: Union[str, None] = Field(default=None, alias="--archive")

model_config = {
"json_schema_extra": {
"examples": [
{
"--dry-run": False,
"--non-interactive": False,
"--verbose": 1,
"--help": False,
"--user": "<sepia_username>",
"--run": "<run_title>",
"--job": [1, 2],
"--machine-type": "smithi",
}
]
}
}