Skip to content

Commit

Permalink
run teuthology-kill cmd instead of teuthology.kill.main
Browse files Browse the repository at this point in the history
This commit also removes "--user" from schemas/base.py

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Feb 12, 2024
1 parent 212fa44 commit 309422e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ SESSION_SECRET_KEY=my-secret-key

# Path where all logs for teuthology-suite or teuthology-kill would be collected
ARCHIVE_DIR=/archive_dir/
PATH_TO_TEUTHOLOGY=/teuthology
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ Example
"--suite-repo": "https://github.com/ceph/ceph-ci.git",
"--teuthology-branch": "main",
"--verbose": "1",
"--user": "example"
"<config_yaml>": ["/teuthology/containerized_node.yaml"]
"--owner": "example",
}'
Note: "--user" in data body should be same as your github username (case sensitive). Otherwise, you wouldn't have permission to kill jobs/run.
Note: "--owner" in data body should be same as your github username (case sensitive). Otherwise, you wouldn't have permission to kill jobs/run.
xxx
1 change: 1 addition & 0 deletions src/teuthology_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class APISettings(BaseSettings):

session_secret_key: str = ""
archive_dir: str = ""
path_to_teuthology: str = ""

model_config = SettingsConfigDict(
env_file=".env", env_file_encoding="utf-8", extra="ignore"
Expand Down
2 changes: 1 addition & 1 deletion src/teuthology_api/routes/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def create_run(
or else it will SyntaxError: non-dafault
argument follows default argument error.
"""
args = args.model_dump(by_alias=True)
args = args.model_dump(by_alias=True, exclude_unset=True)
return run(args, logs, access_token, request)
6 changes: 4 additions & 2 deletions src/teuthology_api/routes/suite.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging

from fastapi import APIRouter, HTTPException, Depends
from fastapi import APIRouter, HTTPException, Depends, Request

from teuthology_api.services.suite import run
from teuthology_api.services.helpers import get_token
from teuthology_api.services.helpers import get_token, get_username
from teuthology_api.schemas.suite import SuiteArgs

log = logging.getLogger(__name__)
Expand All @@ -17,10 +17,12 @@

@router.post("/", status_code=200)
def create_run(
request: Request,
args: SuiteArgs,
access_token: str = Depends(get_token),
dry_run: bool = False,
logs: bool = False,
):
args = args.model_dump(by_alias=True)
args["--user"] = get_username(request)
return run(args, dry_run, logs, access_token)
1 change: 0 additions & 1 deletion src/teuthology_api/schemas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ class BaseArgs(BaseModel):
non_interactive: Union[bool, None] = Field(default=False, alias="--non-interactive")
verbose: Union[int, None] = Field(default=1, alias="--verbose")
help: Union[bool, None] = Field(default=False, alias="--help")
user: str = Field(alias="--user", description="Sepia username")
26 changes: 20 additions & 6 deletions src/teuthology_api/services/kill.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import teuthology.kill
import logging
import subprocess

from fastapi import HTTPException, Request

from teuthology_api.services.helpers import logs_run, get_username, get_run_details
from teuthology_api.config import settings
from teuthology_api.services.helpers import get_username, get_run_details


PATH_TO_TEUTHOLOGY = settings.path_to_teuthology
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -39,11 +41,23 @@ def run(args, send_logs: bool, access_token: str, request: Request):
status_code=401, detail="You don't have permission to kill this run/job"
)
try:
kill_cmd = [f"{PATH_TO_TEUTHOLOGY}/virtualenv/bin/teuthology-kill"]
for (flag, flag_value) in args.items():
if isinstance(flag_value, bool):
flag_value = int(flag_value)
kill_cmd += [flag, str(flag_value)]
log.info(kill_cmd)
proc = subprocess.Popen(
kill_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
stdout, stderr = proc.communicate()
returncode = proc.wait()
if returncode != 0:
log.info(stdout)
raise Exception(stdout)
if send_logs:
logs = logs_run(teuthology.kill.main, args)
return {"logs": logs}
teuthology.kill.main(args)
return {"kill": "success", "logs": stdout}
return {"kill": "success"}
except Exception as exc:
log.error("teuthology.kill.main failed with the error: %s", repr(exc))
log.error("teuthology-kill command failed with the error: %s", repr(exc))
raise HTTPException(status_code=500, detail=repr(exc)) from exc

0 comments on commit 309422e

Please sign in to comment.