Skip to content

Implement command to validate builds #170

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 13 additions & 8 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
import logging
import os
import sys
Expand Down Expand Up @@ -128,17 +129,21 @@ def kci_msg_nonl(content):
click.echo(content, nl=False)


def kci_msg_green_nonl(content):
click.secho(content, fg="green", nl=False)
def kci_msg_green(content, nl=True):
click.secho(content, fg="green", nl=nl)


def kci_msg_red_nonl(content):
click.secho(content, fg="red", nl=False)
def kci_msg_red(content, nl=True):
click.secho(content, fg="red", nl=nl)


def kci_msg_yellow_nonl(content):
click.secho(content, fg="bright_yellow", nl=False)
def kci_msg_yellow(content, nl=True):
click.secho(content, fg="bright_yellow", nl=nl)


def kci_msg_cyan_nonl(content):
click.secho(content, fg="cyan", nl=False)
def kci_msg_cyan(content, nl=True):
click.secho(content, fg="cyan", nl=nl)


def kci_msg_json(content, indent=1):
click.echo(json.dumps(content, indent=indent))
5 changes: 3 additions & 2 deletions kcidev/libs/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from kcidev.libs.common import *

DASHBOARD_API = "https://dashboard.kernelci.org/api/"
DASHBOARD_API = "https://dashboard.kernelci.org:9000/api/"


def _dashboard_request(func):
Expand Down Expand Up @@ -187,9 +187,10 @@ def dashboard_fetch_build(build_id, use_json):
return dashboard_api_fetch(endpoint, {}, use_json)


def dashboard_fetch_tree_list(origin, use_json):
def dashboard_fetch_tree_list(origin, use_json, days=7):
params = {
"origin": origin,
"interval_in_days": days,
}
logging.info(f"Fetching tree list for origin: {origin}")
return dashboard_api_fetch("tree-fast", params, use_json)
Expand Down
24 changes: 19 additions & 5 deletions kcidev/libs/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder)
logging.info(
f"Final parameters - URL: {giturl}, Branch: {branch}, Commit: {commit if commit else 'latest'}"
)
kci_msg("git folder: " + str(git_folder))
kci_msg("tree: " + giturl)
kci_msg("branch: " + branch)
logging.info("git folder: " + str(git_folder))
logging.info("tree: " + giturl)
logging.info("branch: " + branch)
if commit:
kci_msg("commit: " + commit)
logging.info("commit: " + commit)
# If commit looks like a tag or short hash (not 40 chars), try to resolve it
if len(commit) != 40 or not all(
c in "0123456789abcdef" for c in commit.lower()
Expand All @@ -423,6 +423,20 @@ def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder)
if latest:
logging.info("Fetching latest commit from dashboard")
commit = get_latest_commit(origin, giturl, branch)
kci_msg("commit: " + commit)
logging.info("commit: " + commit)

return giturl, branch, commit


def get_tree_name(origin, giturl, branch, commit):
"""Get tree name from git URL, branch, and commit"""
trees = dashboard_fetch_tree_list(origin, False)

for t in trees:
if (
t["git_repository_url"] == giturl
and t["git_repository_branch"] == branch
and t["git_commit_hash"] == commit
):
return t["tree_name"]
return None
39 changes: 24 additions & 15 deletions kcidev/libs/maestro_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,29 @@ def maestro_get_node(url, nodeid):
return node_data


def maestro_get_nodes(url, limit, offset, filter):
def maestro_get_nodes(url, limit, offset, filter, paginate):
headers = {
"Content-Type": "application/json; charset=utf-8",
}
url = url + "latest/nodes/fast?limit=" + str(limit) + "&offset=" + str(offset)

logging.info(f"Fetching Maestro nodes - limit: {limit}, offset: {offset}")
if filter:
logging.debug(f"Applying filters: {filter}")
for f in filter:
# TBD: We need to add translate filter to API
# if we need anything more complex than eq(=)
url = url + "&" + f
if paginate:
url = url + "latest/nodes/fast?limit=" + str(limit) + "&offset=" + str(offset)
logging.info(f"Fetching Maestro nodes - limit: {limit}, offset: {offset}")
if filter:
for f in filter:
logging.debug(f"Applying filters: {filter}")
# TBD: We need to add translate filter to API
# if we need anything more complex than eq(=)
url = url + "&" + f

else:
url = url + "latest/nodes/fast"
if filter:
url = url + "?"
for f in filter:
# TBD: We need to add translate filter to API
# if we need anything more complex than eq(=)
url = url + "&" + f
logging.debug(f"Full nodes URL: {url}")
maestro_print_api_call(url)

Expand Down Expand Up @@ -190,18 +199,18 @@ def maestro_node_result(node):
or result == "done"
or result == "pass"
):
kci_msg_green_nonl("PASS")
kci_msg_green("PASS", nl=False)
elif result == None:
kci_msg_green_nonl("PASS")
kci_msg_green("PASS", nl=False)
else:
kci_msg_red_nonl("FAIL")
kci_msg_red("FAIL", nl=False)
else:
if node["result"] == "pass":
kci_msg_green_nonl("PASS")
kci_msg_green("PASS", nl=False)
elif node["result"] == "fail":
kci_msg_red_nonl("FAIL")
kci_msg_red("FAIL", nl=False)
else:
kci_msg_yellow_nonl(node["result"])
kci_msg_yellow(node["result"])

if node["kind"] == "checkout":
kci_msg_nonl(" branch checkout")
Expand Down
2 changes: 2 additions & 0 deletions kcidev/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
maestro_results,
results,
testretry,
validate,
watch,
)

Expand Down Expand Up @@ -63,6 +64,7 @@ def run():
cli.add_command(maestro_results.maestro_results)
cli.add_command(testretry.testretry)
cli.add_command(results.results)
cli.add_command(validate.validate)
cli.add_command(watch.watch)
cli()

Expand Down
20 changes: 19 additions & 1 deletion kcidev/subcommands/maestro_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
required=False,
help="Filter results by tree name",
)
@click.option(
"--count",
is_flag=True,
required=False,
help="Print only count of nodes",
)
@click.option(
"--paginate",
is_flag=True,
required=False,
default=True,
help="Set True if pagination is required in the output. Default is True",
)
@add_filter_options
@click.pass_context
def maestro_results(
Expand All @@ -82,6 +95,8 @@ def maestro_results(
compiler,
config,
git_branch,
count,
paginate,
):
logging.info("Starting maestro-results command")
logging.debug(
Expand Down Expand Up @@ -125,9 +140,12 @@ def maestro_results(
logging.info(
f"Fetching nodes with {len(filter)} filters, limit: {limit}, offset: {offset}"
)
results = maestro_get_nodes(url, limit, offset, filter)
results = maestro_get_nodes(url, limit, offset, filter, paginate)
if count:
return results

logging.debug(f"Displaying results with fields: {field if field else 'all'}")

maestro_print_nodes(results, field)


Expand Down
18 changes: 15 additions & 3 deletions kcidev/subcommands/results/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,22 @@ def summary(origin, git_folder, giturl, branch, commit, latest, arch, tree, use_
help="Select KCIDB origin",
default="maestro",
)
@click.option(
"--days",
help="Provide a period of time in days to get results for",
type=int,
default=7,
)
@click.option(
"--verbose",
is_flag=True,
default=True,
help="Print tree details",
)
@results_display_options
def trees(origin, use_json):
def trees(origin, use_json, days, verbose):
"""List trees from a give origin."""
cmd_list_trees(origin, use_json)
return cmd_list_trees(origin, use_json, days, verbose)


@results.command()
Expand Down Expand Up @@ -133,7 +145,7 @@ def builds(
data = dashboard_fetch_builds(
origin, giturl, branch, commit, arch, tree, start_date, end_date, use_json
)
cmd_builds(
return cmd_builds(
data,
commit,
download_logs,
Expand Down
Loading