Skip to content

Commit b90508c

Browse files
authored
Merge pull request #188 from JenySadadia/validate-builds-history
Validate builds history
2 parents 96ea570 + 30faf8c commit b90508c

File tree

6 files changed

+191
-9
lines changed

6 files changed

+191
-9
lines changed

kcidev/libs/git_repo.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,11 @@ def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder)
428428
return giturl, branch, commit
429429

430430

431-
def get_tree_name(origin, giturl, branch, commit):
432-
"""Get tree name from git URL, branch, and commit"""
431+
def get_tree_name(origin, giturl, branch):
432+
"""Get tree name from git URL, and branch"""
433433
trees = dashboard_fetch_tree_list(origin, False)
434434

435435
for t in trees:
436-
if (
437-
t["git_repository_url"] == giturl
438-
and t["git_repository_branch"] == branch
439-
and t["git_commit_hash"] == commit
440-
):
436+
if t["git_repository_url"] == giturl and t["git_repository_branch"] == branch:
441437
return t["tree_name"]
442438
return None

kcidev/subcommands/validate/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from kcidev.subcommands.validate.boots import boots
66
from kcidev.subcommands.validate.builds import builds
7+
from kcidev.subcommands.validate.builds_history import builds_history
78

89

910
@click.group(
@@ -13,6 +14,7 @@
1314
Subcommands:
1415
builds - Validate build results
1516
boots - Validate boot results
17+
builds-history - Validate builds history
1618
1719
\b
1820
Examples:
@@ -22,6 +24,9 @@
2224
# Validate boots
2325
kci-dev validate boots --all-checkouts --days <number-of-days>
2426
kci-dev validate boots -commit <git-commit> --giturl <git-url> --branch <git-branch>
27+
# Validate builds history
28+
kci-dev validate builds-history --all-checkouts --days <number-of-days> --arch <architecture-filter>
29+
kci-dev validate builds-history -commit <git-commit> --giturl <git-url> --branch <git-branch> --days <number-of-days>
2530
""",
2631
invoke_without_command=True,
2732
)
@@ -36,6 +41,7 @@ def validate(ctx):
3641
# Add subcommands to the validate group
3742
validate.add_command(builds)
3843
validate.add_command(boots)
44+
validate.add_command(builds_history)
3945

4046

4147
if __name__ == "__main__":

kcidev/subcommands/validate/boots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def boots(
105105
giturl, branch, commit = set_giturl_branch_commit(
106106
origin, giturl, branch, commit, latest, git_folder
107107
)
108-
tree_name = get_tree_name(origin, giturl, branch, commit)
108+
tree_name = get_tree_name(origin, giturl, branch)
109109
stats = get_boot_stats(ctx, giturl, branch, commit, tree_name, verbose, arch)
110110
if stats:
111111
final_stats.append(stats)

kcidev/subcommands/validate/builds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def builds(
105105
giturl, branch, commit = set_giturl_branch_commit(
106106
origin, giturl, branch, commit, latest, git_folder
107107
)
108-
tree_name = get_tree_name(origin, giturl, branch, commit)
108+
tree_name = get_tree_name(origin, giturl, branch)
109109
stats = get_build_stats(ctx, giturl, branch, commit, tree_name, verbose, arch)
110110
if stats:
111111
final_stats.append(stats)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import click
2+
3+
from kcidev.libs.git_repo import get_tree_name
4+
from kcidev.subcommands.results import trees
5+
6+
from .helper import get_builds_history_stats, print_stats
7+
8+
9+
@click.command(
10+
name="builds-history",
11+
help="""Validate dashboard builds history with maestro.
12+
13+
The command can be used to check if number of builds is consitent
14+
for different checkouts of the same git tree/branch.
15+
`--days` option is used to fetch checkouts created during the mentioned days.
16+
Default is `7` days.
17+
18+
\b
19+
Examples:
20+
kci-dev validate builds-history --all-checkouts --days <number-of-days>
21+
kci-dev validate builds-history --giturl <git-url> --branch <git-branch> --days <number-of-days>
22+
""",
23+
)
24+
@click.option(
25+
"--all-checkouts",
26+
is_flag=True,
27+
help="Get build validation stats for all available checkouts",
28+
)
29+
@click.option(
30+
"--days",
31+
help="Provide a period of time in days to get results for",
32+
type=int,
33+
default="7",
34+
)
35+
@click.option(
36+
"--origin",
37+
help="Select KCIDB origin",
38+
default="maestro",
39+
)
40+
@click.option(
41+
"--giturl",
42+
help="Git URL of kernel tree",
43+
)
44+
@click.option(
45+
"--branch",
46+
help="Branch to get results for",
47+
)
48+
@click.option("--arch", help="Filter by arch")
49+
@click.option(
50+
"--verbose",
51+
is_flag=True,
52+
default=False,
53+
help="Get detailed output",
54+
)
55+
@click.pass_context
56+
def builds_history(
57+
ctx,
58+
all_checkouts,
59+
origin,
60+
giturl,
61+
branch,
62+
arch,
63+
days,
64+
verbose,
65+
):
66+
final_stats = []
67+
print("Fetching builds history information...")
68+
if all_checkouts:
69+
if giturl or branch:
70+
raise click.UsageError(
71+
"Cannot use --all-checkouts with --giturl or --branch"
72+
)
73+
trees_list = ctx.invoke(trees, origin=origin, days=days, verbose=False)
74+
for tree in trees_list:
75+
giturl = tree["git_repository_url"]
76+
branch = tree["git_repository_branch"]
77+
tree_name = tree["tree_name"]
78+
stats = get_builds_history_stats(
79+
ctx, giturl, branch, tree_name, arch, days, verbose
80+
)
81+
if stats:
82+
final_stats.extend(stats)
83+
else:
84+
tree_name = get_tree_name(origin, giturl, branch)
85+
final_stats = get_builds_history_stats(
86+
ctx, giturl, branch, tree_name, arch, days, verbose
87+
)
88+
if final_stats:
89+
headers = [
90+
"tree/branch",
91+
"Commit",
92+
"Maestro\nbuilds",
93+
"Dashboard\nbuilds",
94+
"Build count\ncomparison",
95+
"Missing build IDs",
96+
]
97+
max_col_width = [None, 40, 3, 3, 2, 30]
98+
table_fmt = "simple_grid"
99+
print_stats(final_stats, headers, max_col_width, table_fmt)

kcidev/subcommands/validate/helper.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from datetime import datetime, timedelta
4+
35
import click
46
from tabulate import tabulate
57

@@ -233,3 +235,82 @@ def get_boot_stats(ctx, giturl, branch, commit, tree_name, verbose, arch=None):
233235
boots_with_status_mismatch,
234236
]
235237
return stats
238+
239+
240+
def get_builds_history_stats(ctx, giturl, branch, tree_name, arch, days, verbose):
241+
checkouts = get_checkouts(ctx, giturl, branch, days)
242+
final_stats = []
243+
builds_history = get_builds_history(ctx, checkouts, arch)
244+
for b in builds_history:
245+
missing_build_ids = find_missing_items(b[1], b[2], verbose)
246+
total_maestro_builds = len(b[1])
247+
total_dashboard_builds = len(b[2])
248+
stats = [
249+
f"{tree_name}/{branch}",
250+
b[0],
251+
total_maestro_builds,
252+
total_dashboard_builds,
253+
"✅" if total_maestro_builds == total_dashboard_builds else "❌",
254+
missing_build_ids,
255+
]
256+
final_stats.append(stats)
257+
return final_stats
258+
259+
260+
def get_checkouts(ctx, giturl, branch, days):
261+
"""Get checkouts upto last specified days for a particular git
262+
URL and branch"""
263+
now = datetime.now()
264+
start_timestamp = now - timedelta(days=days)
265+
filters = [
266+
"kind=checkout",
267+
"data.kernel_revision.url=" + giturl,
268+
"data.kernel_revision.branch=" + branch,
269+
"state=done",
270+
"created__gte=" + start_timestamp.isoformat(),
271+
]
272+
checkouts = ctx.invoke(
273+
results,
274+
count=True,
275+
nodes=True,
276+
filter=filters,
277+
paginate=False,
278+
)
279+
return checkouts
280+
281+
282+
def get_builds_history(ctx, checkouts, arch):
283+
"""Get builds from maestro and dashboard for provided checkouts"""
284+
builds_history = []
285+
for c in checkouts:
286+
commit = c["data"]["kernel_revision"].get("commit")
287+
filters = [
288+
"kind=kbuild",
289+
"data.error_code__ne=node_timeout",
290+
"parent=" + c["id"],
291+
"state__in=done,available",
292+
]
293+
if arch:
294+
filters.append(f"data.arch={arch}")
295+
maestro_builds = ctx.invoke(
296+
results,
297+
count=True,
298+
nodes=True,
299+
filter=filters,
300+
paginate=False,
301+
)
302+
303+
try:
304+
dashboard_builds = ctx.invoke(
305+
builds,
306+
giturl=c["data"]["kernel_revision"].get("url"),
307+
branch=c["data"]["kernel_revision"].get("branch"),
308+
commit=commit,
309+
count=True,
310+
verbose=False,
311+
arch=arch,
312+
)
313+
builds_history.append([commit, maestro_builds, dashboard_builds])
314+
except click.Abort:
315+
kci_msg_red("Aborted while fetching dashboard builds")
316+
return builds_history

0 commit comments

Comments
 (0)