-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from nuclearcat/add-test-retry
feat(testretry): Add testretry command
- Loading branch information
Showing
4 changed files
with
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,73 @@ | ||
# kci-dev | ||
|
||
kci-dev is a cmdline tool for interact with a enabled KernelCI server | ||
Purpose of this tool to provide a easy way to use features of KernelCI Pipeline instance. | ||
|
||
## Installation | ||
|
||
Using poetry and virtualenv | ||
```sh | ||
virtualenv .venv | ||
source .venv/bin/activate | ||
pip install poetry | ||
poetry install | ||
poetry run kci-dev | ||
``` | ||
|
||
## Configuration | ||
|
||
kci-dev uses a configuration file .kci-dev.toml in the program directory. | ||
```toml | ||
default_instance="staging" | ||
[local] | ||
host="https://127.0.0.1" | ||
token="example" | ||
|
||
[staging] | ||
host="https://staging.kernelci.org:9100/" | ||
token="SOMEVERYSECRETTOKEN" | ||
|
||
[production] | ||
host="https://kernelci-pipeline.westus3.cloudapp.azure.com/" | ||
token="example" | ||
``` | ||
|
||
Where `default_instance` is the default instance to use, if not provided in the command line. | ||
In section `local`, `staging`, `production` you can provide the host and token for the available instances. | ||
host is the URL of the KernelCI Pipeline API endpoint, and token is the API token to use for authentication. | ||
If you are using KernelCI Pipeline instance, you can get the token from the project maintainers. | ||
If it is a local instance, you can generate your token using kernelci-pipeline/tools/jwt_generator.py script. | ||
|
||
## Options | ||
|
||
### instance | ||
You can provide the instance name to use for the command. | ||
|
||
Example: | ||
```sh | ||
kci-dev --instance staging | ||
``` | ||
|
||
### settings | ||
|
||
You can provide the configuration file path to use for the command. | ||
|
||
Example: | ||
```sh | ||
kci-dev --settings /path/to/.kci-dev.toml | ||
``` | ||
|
||
## Commands | ||
|
||
### testretry | ||
|
||
This command will retry the failed tests. In some cases tests may fail due to network issues, hardware problems, | ||
nature of test (flaky), etc. This command will retry the failed tests, and create additional test jobs for the failed tests. | ||
After observing the results, you can decide if test results were reliable, not, or maybe even test need improvement. | ||
|
||
Example: | ||
```sh | ||
kci-dev testretry --nodeid <testnodeid> | ||
``` | ||
|
||
testnodeid is the node id of the test job, which you can get from the KernelCI dashboard. Usually it is hexadecimal string. |
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() |
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