diff --git a/.kci-dev.toml.example b/.kci-dev.toml.example index 53ea36e..31ff78e 100644 --- a/.kci-dev.toml.example +++ b/.kci-dev.toml.example @@ -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" diff --git a/kci-dev/kci-dev.py b/kci-dev/kci-dev.py index 006d68b..817ee25 100755 --- a/kci-dev/kci-dev.py +++ b/kci-dev/kci-dev.py @@ -3,7 +3,7 @@ import click from libs.common import * -from subcommands import commit, patch +from subcommands import commit, patch, results @click.group( @@ -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() diff --git a/kci-dev/subcommands/commit.py b/kci-dev/subcommands/commit.py index d7c2a9b..f44114c 100644 --- a/kci-dev/subcommands/commit.py +++ b/kci-dev/subcommands/commit.py @@ -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") diff --git a/kci-dev/subcommands/results.py b/kci-dev/subcommands/results.py new file mode 100644 index 0000000..960c01c --- /dev/null +++ b/kci-dev/subcommands/results.py @@ -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() diff --git a/tests/test_kcidev.py b/tests/test_kcidev.py index f7dc030..22640ea 100644 --- a/tests/test_kcidev.py +++ b/tests/test_kcidev.py @@ -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") @@ -65,6 +95,8 @@ def test_kcidev_commit(): "poetry", "run", "kci-dev", + "--instance", + "staging_api", "commit", "--repository", "linux-next", @@ -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():