-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testretry): Add testretry command
Add command to retry some tests, in case test are flaky and we need to make sure it is not some glitch or hardware issue, by re-running the test. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
- Loading branch information
1 parent
b64b8b9
commit 67d53e9
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
|
||
import click | ||
import requests | ||
from git import Repo | ||
from libs.common import * | ||
|
||
|
||
def api_connection(host): | ||
click.secho("api connect: " + host, fg="green") | ||
return host | ||
|
||
|
||
def display_api_error(response): | ||
click.secho(f"API response error code: {response.status_code}", fg="red") | ||
try: | ||
click.secho(response.json(), fg="red") | ||
except json.decoder.JSONDecodeError: | ||
click.secho(f"No JSON response. Plain text: {response.text}", fg="yellow") | ||
return | ||
|
||
|
||
def send_jobretry(baseurl, jobid, token): | ||
url = baseurl + "api/jobretry" | ||
headers = { | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Authorization": f"{token}", | ||
} | ||
data = {"nodeid": jobid} | ||
jdata = json.dumps(data) | ||
try: | ||
response = requests.post(url, headers=headers, data=jdata) | ||
except requests.exceptions.RequestException as e: | ||
click.secho(f"API connection error: {e}", fg="red") | ||
return | ||
|
||
if response.status_code != 200: | ||
display_api_error(response) | ||
return None | ||
return response.json() | ||
|
||
|
||
@click.command(help="Retry a test(job) on KernelCI") | ||
@click.option( | ||
"--nodeid", | ||
help="define the node id of the (test)job to retry", | ||
required=True, | ||
) | ||
@click.pass_context | ||
def testretry(ctx, nodeid): | ||
cfg = ctx.obj.get("CFG") | ||
instance = ctx.obj.get("INSTANCE") | ||
url = api_connection(cfg[instance]["host"]) | ||
resp = send_jobretry(url, nodeid, cfg[instance]["token"]) | ||
if resp and "message" in resp: | ||
click.secho(resp["message"], fg="green") | ||
|
||
|
||
if __name__ == "__main__": | ||
main_kcidev() |