Skip to content

Commit

Permalink
kci-dev: Add results subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Arisu Tachibana <[email protected]>
  • Loading branch information
aliceinwire committed Oct 2, 2024
1 parent febd12e commit 92fcab0
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .kci-dev.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ token="example"
host="https://staging.kernelci.org:9100/"
token="example"

[staging_api]
host="https://staging.kernelci.org:9000/latest/"
token="example"

[production]
host="https://kernelci-pipeline.westus3.cloudapp.azure.com/"
token="example"
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, results


@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(results.results)
cli()


Expand Down
10 changes: 7 additions & 3 deletions kci-dev/subcommands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ def send_build(url, patch, branch, treeurl, token):
"kbuildname": "example",
"testname": "example",
}
response = requests.post(url, headers=headers, files={"patch": patch}, data=values)
click.secho(response.status_code, fg="green")
click.secho(response.json(), fg="green")
# temporary disabled as API not working yet
click.secho(url, fg="green")
click.secho(headers, fg="green")
click.secho(values, fg="green")
# response = requests.post(url, headers=headers, files={"patch": patch}, data=values)
# click.secho(response.status_code, fg="green")
# click.secho(response.json(), fg="green")


@click.command(help="Test commits from a local Kernel repository")
Expand Down
44 changes: 44 additions & 0 deletions kci-dev/subcommands/results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
import pprint

import click
import requests
import toml
from git import Repo


def api_connection(host):
click.secho("api connect: " + host, fg="green")
return host


def get_node(url, nodeid):
headers = {
"Content-Type": "application/json; charset=utf-8",
}
url = url + "/node/" + nodeid
click.secho(url)
response = requests.get(url, headers=headers)
click.secho(response.status_code, fg="green")
click.secho(pprint.pprint(response.json()), fg="green")


@click.command(help="Get results")
@click.option(
"--nodeid",
required=True,
help="select node_id",
)
@click.pass_context
def results(ctx, nodeid):
config = ctx.obj.get("CFG")
instance = ctx.obj.get("INSTANCE")
url = api_connection(config[instance]["host"])
get_node(url, nodeid)


if __name__ == "__main__":
main_kcidev()
34 changes: 33 additions & 1 deletion tests/test_kcidev.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ def test_kcidev_patch_help():
assert result.returncode == 0


def test_kcidev_results_help():
command = ["poetry", "run", "kci-dev", "results", "--help"]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout)
print("#### stderr ####")
print(result.stderr)
assert result.returncode == 0


def test_kcidev_results_tests():
command = [
"poetry",
"run",
"kci-dev",
"--instance",
"staging_api",
"results",
"--nodeid",
"65a1355ee98651d0fe81e41d",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout)
print("#### stderr ####")
print(result.stderr)


def test_create_repo():
repo_dir = os.path.join("my-new-repo")
file_name = os.path.join(repo_dir, "new-file")
Expand All @@ -65,6 +95,8 @@ def test_kcidev_commit():
"poetry",
"run",
"kci-dev",
"--instance",
"staging_api",
"commit",
"--repository",
"linux-next",
Expand All @@ -81,7 +113,7 @@ def test_kcidev_commit():
print(result.stdout)
print("#### stderr ####")
print(result.stderr)
assert result.returncode == 1
assert result.returncode == 0


def test_main():
Expand Down

0 comments on commit 92fcab0

Please sign in to comment.