Skip to content

Commit 6d8d4a9

Browse files
author
Jeny Sadadia
committed
Implement command to validate builds
Get builds from dashboard and validate them with maestro result. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent 6876c03 commit 6d8d4a9

File tree

6 files changed

+102
-11
lines changed

6 files changed

+102
-11
lines changed

kcidev/libs/maestro_common.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,29 @@ def maestro_get_node(url, nodeid):
6262
return response.json()
6363

6464

65-
def maestro_get_nodes(url, limit, offset, filter):
65+
def maestro_get_nodes(url, limit, offset, filter, paginate):
6666
headers = {
6767
"Content-Type": "application/json; charset=utf-8",
6868
}
69-
url = url + "latest/nodes/fast?limit=" + str(limit) + "&offset=" + str(offset)
70-
maestro_print_api_call(url)
71-
if filter:
72-
for f in filter:
73-
# TBD: We need to add translate filter to API
74-
# if we need anything more complex than eq(=)
75-
url = url + "&" + f
7669

70+
if paginate:
71+
url = url + "latest/nodes/fast?limit=" + str(limit) + "&offset=" + str(offset)
72+
if filter:
73+
for f in filter:
74+
# TBD: We need to add translate filter to API
75+
# if we need anything more complex than eq(=)
76+
url = url + "&" + f
77+
78+
else:
79+
url = url + "latest/nodes/fast"
80+
if filter:
81+
url = url + "?"
82+
for f in filter:
83+
# TBD: We need to add translate filter to API
84+
# if we need anything more complex than eq(=)
85+
url = url + "&" + f
86+
87+
maestro_print_api_call(url)
7788
response = requests.get(url, headers=headers)
7889
try:
7990
response.raise_for_status()

kcidev/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
patch,
1616
results,
1717
testretry,
18+
validate_builds,
1819
watch,
1920
)
2021

@@ -66,6 +67,7 @@ def run():
6667
cli.add_command(testretry.testretry)
6768
cli.add_command(results.results)
6869
cli.add_command(watch.watch)
70+
cli.add_command(validate_builds.validate_builds)
6971
cli()
7072

7173

kcidev/subcommands/maestro_results.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,21 @@
4444
multiple=True,
4545
help="Print only particular field(s) from node data",
4646
)
47+
@click.option(
48+
"--count",
49+
is_flag=True,
50+
required=False,
51+
help="Print only count of nodes",
52+
)
53+
@click.option(
54+
"--paginate",
55+
is_flag=True,
56+
required=False,
57+
default=True,
58+
help="Set True if pagination is required in the output. Default is True",
59+
)
4760
@click.pass_context
48-
def maestro_results(ctx, nodeid, nodes, limit, offset, filter, field):
61+
def maestro_results(ctx, nodeid, nodes, limit, offset, filter, field, count, paginate):
4962
config = ctx.obj.get("CFG")
5063
instance = ctx.obj.get("INSTANCE")
5164
url = config[instance]["api"]
@@ -55,7 +68,10 @@ def maestro_results(ctx, nodeid, nodes, limit, offset, filter, field):
5568
if nodeid:
5669
results = maestro_get_node(url, nodeid)
5770
if nodes:
58-
results = maestro_get_nodes(url, limit, offset, filter)
71+
results = maestro_get_nodes(url, limit, offset, filter, paginate)
72+
if count:
73+
print("Total nodes found in maestro: ", len(results))
74+
return results
5975
maestro_print_nodes(results, field)
6076

6177

kcidev/subcommands/results/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def builds(
8484
origin, giturl, branch, commit, latest, git_folder
8585
)
8686
data = dashboard_fetch_builds(origin, giturl, branch, commit, arch, use_json)
87-
cmd_builds(data, commit, download_logs, status, count, use_json)
87+
return cmd_builds(data, commit, download_logs, status, count, use_json)
8888

8989

9090
@results.command()

kcidev/subcommands/results/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def cmd_builds(data, commit, download_logs, status, count, use_json):
174174
kci_msg(filtered_builds)
175175
elif use_json:
176176
kci_msg(json.dumps(builds))
177+
return data["builds"]
177178

178179

179180
def print_build(build, log_path):

kcidev/subcommands/validate_builds.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import click
5+
6+
from kcidev.libs.common import *
7+
from kcidev.libs.maestro_common import *
8+
9+
from .maestro_results import maestro_results
10+
from .results import builds
11+
12+
13+
@click.command(help="Validate builds from dashboard and maestro")
14+
@click.option(
15+
"--giturl",
16+
required=True,
17+
help="Git URL of kernel tree ",
18+
)
19+
@click.option(
20+
"--branch",
21+
required=True,
22+
help="Branch to get results for",
23+
)
24+
@click.option(
25+
"--commit",
26+
required=True,
27+
help="Commit or tag to get results for",
28+
)
29+
@click.option("--arch", help="Filter by arch")
30+
@click.pass_context
31+
def validate_builds(ctx, giturl, branch, commit, arch):
32+
"""
33+
Command to pull builds by providing git URL, branch and checkout
34+
commit from dashboard and compare them with results from maestro
35+
"""
36+
filters = [
37+
"kind=kbuild",
38+
"data.kernel_revision.url=" + giturl,
39+
"data.kernel_revision.branch=" + branch,
40+
"data.kernel_revision.commit=" + commit,
41+
]
42+
if arch:
43+
filters.append("data.arch=" + arch)
44+
kci_msg_cyan_nonl("Maestro:\n")
45+
maestro_builds = ctx.invoke(
46+
maestro_results,
47+
count=True,
48+
nodes=True,
49+
filter=filters,
50+
paginate=False,
51+
)
52+
kci_msg_cyan_nonl("Dashboard:\n")
53+
dashboard_builds = ctx.forward(builds, count=True)
54+
if len(dashboard_builds) == len(maestro_builds):
55+
print("Build count matched")
56+
else:
57+
print("Build count didn't match")
58+
59+
60+
if __name__ == "__main__":
61+
main_kcidev()

0 commit comments

Comments
 (0)