Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hardware subcommand #148

Merged
merged 2 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ Example:
kci-dev results build --id 'maestro:67d409f9f378f0c5986dc7df' --download-logs --json
```

### hardware

Displays hardware related information

#### list

List all available hardware for the given origin (Maestro by default), for the last 7 days

Example:

```sh
kci-dev results hardware list --origin maestro --json
```

## Common parameters

### --origin
Expand Down
13 changes: 13 additions & 0 deletions kcidev/libs/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import urllib
from datetime import datetime, timedelta

import requests

Expand Down Expand Up @@ -109,3 +110,15 @@ def dashboard_fetch_tree_list(origin, use_json):
"origin": origin,
}
return dashboard_api_fetch("tree-fast", params, use_json)


def dashboard_fetch_hardware_list(origin, use_json):
# TODO: add date filter
now = datetime.today()
last_week = now - timedelta(days=7)
params = {
"origin": origin,
"endTimeStampInSeconds": int(now.timestamp()),
"startTimestampInSeconds": int(last_week.timestamp()),
}
return dashboard_api_fetch("hardware/", params, use_json)
103 changes: 11 additions & 92 deletions kcidev/subcommands/results/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
dashboard_fetch_tests,
)
from libs.git_repo import set_giturl_branch_commit
from subcommands.results.hardware import hardware
from subcommands.results.options import (
builds_and_tests_options,
common_options,
results_display_options,
single_build_and_test_options,
)
from subcommands.results.parser import (
cmd_builds,
cmd_list_trees,
Expand All @@ -22,98 +29,10 @@
)


def results_display_options(func):
@click.option("--json", "use_json", is_flag=True, help="Displays results as json")
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def common_options(func):
@click.option(
"--origin",
help="Select KCIDB origin",
default="maestro",
)
@click.option(
"--giturl",
help="Git URL of kernel tree ",
)
@click.option(
"--branch",
help="Branch to get results for",
)
@click.option(
"--git-folder",
help="Path of git repository folder",
)
@click.option(
"--commit",
help="Commit or tag to get results for",
)
@click.option(
"--latest",
is_flag=True,
help="Select latest results available",
)
@click.option("--arch", help="Filter by arch")
@results_display_options
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def builds_and_tests_options(func):
@click.option(
"--download-logs",
is_flag=True,
help="Select desired results action",
)
@click.option(
"--status",
type=click.Choice(["all", "pass", "fail", "inconclusive"], case_sensitive=True),
help="Status of test result",
default="all",
)
@click.option(
"--filter",
type=click.File("r"),
help="Pass filter file for builds, boot and tests results.",
)
@click.option(
"--count", is_flag=True, help="Display the number of matching results"
)
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def single_build_and_test_options(func):
@click.option(
"--id",
"op_id",
required=True,
help="Pass an id filter to get specific results",
)
@click.option(
"--download-logs",
is_flag=True,
help="Select desired results action",
)
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


@click.group(help="[Experimental] Get results from the dashboard")
@click.group(
help="[Experimental] Get results from the dashboard",
commands={"hardware": hardware},
)
def results():
"""Commands related to results."""
pass
Expand Down
18 changes: 18 additions & 0 deletions kcidev/subcommands/results/hardware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import click
from libs.dashboard import dashboard_fetch_hardware_list
from subcommands.results.options import results_display_options
from subcommands.results.parser import cmd_hardware_list


@click.group(chain=True, help="Get hardware related information from the dashboard")
def hardware():
"""Commands related to hardware"""
pass


@hardware.command()
@click.option("--origin", default="maestro", help="Select KCIDB origin")
@results_display_options
def list(origin, use_json):
data = dashboard_fetch_hardware_list(origin, use_json)
cmd_hardware_list(data, use_json)
94 changes: 94 additions & 0 deletions kcidev/subcommands/results/options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from functools import wraps

import click


def results_display_options(func):
@click.option("--json", "use_json", is_flag=True, help="Displays results as json")
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def common_options(func):
@click.option(
"--origin",
help="Select KCIDB origin",
default="maestro",
)
@click.option(
"--giturl",
help="Git URL of kernel tree ",
)
@click.option(
"--branch",
help="Branch to get results for",
)
@click.option(
"--git-folder",
help="Path of git repository folder",
)
@click.option(
"--commit",
help="Commit or tag to get results for",
)
@click.option(
"--latest",
is_flag=True,
help="Select latest results available",
)
@click.option("--arch", help="Filter by arch")
@results_display_options
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def builds_and_tests_options(func):
@click.option(
"--download-logs",
is_flag=True,
help="Select desired results action",
)
@click.option(
"--status",
type=click.Choice(["all", "pass", "fail", "inconclusive"], case_sensitive=True),
help="Status of test result",
default="all",
)
@click.option(
"--filter",
type=click.File("r"),
help="Pass filter file for builds, boot and tests results.",
)
@click.option(
"--count", is_flag=True, help="Display the number of matching results"
)
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def single_build_and_test_options(func):
@click.option(
"--id",
"op_id",
required=True,
help="Pass an id filter to get specific results",
)
@click.option(
"--download-logs",
is_flag=True,
help="Select desired results action",
)
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper
19 changes: 19 additions & 0 deletions kcidev/subcommands/results/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,22 @@ def cmd_single_build(build, download_logs, use_json):
kci_msg(create_build_json(build, log_path))
else:
print_build(build, log_path)


def cmd_hardware_list(data, use_json):
if use_json:
hardware = [
{"name": hardware["hardware_name"], "compatibles": hardware["platform"]}
for hardware in data["hardware"]
]
kci_msg(hardware)
else:
for hardware in data["hardware"]:
kci_msg_nonl("- name: ")
kci_msg_cyan_nonl(hardware["hardware_name"])
kci_msg("")

kci_msg_nonl(" compatibles: ")
kci_msg_cyan_nonl(hardware["platform"])
kci_msg("")
kci_msg("")