Skip to content

Commit

Permalink
feat(testretry): Add testretry command
Browse files Browse the repository at this point in the history
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
nuclearcat committed Sep 12, 2024
1 parent fbf72dc commit 719f294
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kci-dev/kci-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import click
from libs.common import *
from subcommands import commit, patch
from subcommands import commit, patch, testretry


@click.group(
Expand Down Expand Up @@ -31,6 +31,7 @@ def cli(ctx, settings, instance):
def run():
cli.add_command(commit.commit)
cli.add_command(patch.patch)
cli.add_command(testretry.testretry)
cli()


Expand Down
63 changes: 63 additions & 0 deletions kci-dev/subcommands/testretry.py
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()

0 comments on commit 719f294

Please sign in to comment.