Skip to content

Commit be49640

Browse files
authored
Merge pull request #170 from JenySadadia/validate-builds-cmd
Implement command to validate builds
2 parents 3cb5f3f + 1ffc1d0 commit be49640

File tree

11 files changed

+424
-61
lines changed

11 files changed

+424
-61
lines changed

kcidev/libs/common.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
import json
45
import logging
56
import os
67
import sys
@@ -128,17 +129,21 @@ def kci_msg_nonl(content):
128129
click.echo(content, nl=False)
129130

130131

131-
def kci_msg_green_nonl(content):
132-
click.secho(content, fg="green", nl=False)
132+
def kci_msg_green(content, nl=True):
133+
click.secho(content, fg="green", nl=nl)
133134

134135

135-
def kci_msg_red_nonl(content):
136-
click.secho(content, fg="red", nl=False)
136+
def kci_msg_red(content, nl=True):
137+
click.secho(content, fg="red", nl=nl)
137138

138139

139-
def kci_msg_yellow_nonl(content):
140-
click.secho(content, fg="bright_yellow", nl=False)
140+
def kci_msg_yellow(content, nl=True):
141+
click.secho(content, fg="bright_yellow", nl=nl)
141142

142143

143-
def kci_msg_cyan_nonl(content):
144-
click.secho(content, fg="cyan", nl=False)
144+
def kci_msg_cyan(content, nl=True):
145+
click.secho(content, fg="cyan", nl=nl)
146+
147+
148+
def kci_msg_json(content, indent=1):
149+
click.echo(json.dumps(content, indent=indent))

kcidev/libs/git_repo.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,11 @@ def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder)
402402
logging.info(
403403
f"Final parameters - URL: {giturl}, Branch: {branch}, Commit: {commit if commit else 'latest'}"
404404
)
405-
kci_msg("git folder: " + str(git_folder))
406-
kci_msg("tree: " + giturl)
407-
kci_msg("branch: " + branch)
405+
logging.info("git folder: " + str(git_folder))
406+
logging.info("tree: " + giturl)
407+
logging.info("branch: " + branch)
408408
if commit:
409-
kci_msg("commit: " + commit)
409+
logging.info("commit: " + commit)
410410
# If commit looks like a tag or short hash (not 40 chars), try to resolve it
411411
if len(commit) != 40 or not all(
412412
c in "0123456789abcdef" for c in commit.lower()
@@ -423,6 +423,20 @@ def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder)
423423
if latest:
424424
logging.info("Fetching latest commit from dashboard")
425425
commit = get_latest_commit(origin, giturl, branch)
426-
kci_msg("commit: " + commit)
426+
logging.info("commit: " + commit)
427427

428428
return giturl, branch, commit
429+
430+
431+
def get_tree_name(origin, giturl, branch, commit):
432+
"""Get tree name from git URL, branch, and commit"""
433+
trees = dashboard_fetch_tree_list(origin, False)
434+
435+
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+
):
441+
return t["tree_name"]
442+
return None

kcidev/libs/maestro_common.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,29 @@ def maestro_get_node(url, nodeid):
8080
return node_data
8181

8282

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

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

98+
else:
99+
url = url + "latest/nodes/fast"
100+
if filter:
101+
url = url + "?"
102+
for f in filter:
103+
# TBD: We need to add translate filter to API
104+
# if we need anything more complex than eq(=)
105+
url = url + "&" + f
97106
logging.debug(f"Full nodes URL: {url}")
98107
maestro_print_api_call(url)
99108

@@ -190,18 +199,18 @@ def maestro_node_result(node):
190199
or result == "done"
191200
or result == "pass"
192201
):
193-
kci_msg_green_nonl("PASS")
202+
kci_msg_green("PASS", nl=False)
194203
elif result == None:
195-
kci_msg_green_nonl("PASS")
204+
kci_msg_green("PASS", nl=False)
196205
else:
197-
kci_msg_red_nonl("FAIL")
206+
kci_msg_red("FAIL", nl=False)
198207
else:
199208
if node["result"] == "pass":
200-
kci_msg_green_nonl("PASS")
209+
kci_msg_green("PASS", nl=False)
201210
elif node["result"] == "fail":
202-
kci_msg_red_nonl("FAIL")
211+
kci_msg_red("FAIL", nl=False)
203212
else:
204-
kci_msg_yellow_nonl(node["result"])
213+
kci_msg_yellow(node["result"])
205214

206215
if node["kind"] == "checkout":
207216
kci_msg_nonl(" branch checkout")

kcidev/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
maestro,
1515
results,
1616
testretry,
17+
validate,
1718
watch,
1819
)
1920

@@ -63,6 +64,7 @@ def run():
6364
cli.add_command(maestro.maestro)
6465
cli.add_command(testretry.testretry)
6566
cli.add_command(results.results)
67+
cli.add_command(validate.validate)
6668
cli.add_command(watch.watch)
6769
cli()
6870

kcidev/subcommands/maestro/results.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@
6767
required=False,
6868
help="Filter results by tree name",
6969
)
70+
@click.option(
71+
"--count",
72+
is_flag=True,
73+
required=False,
74+
help="Print only count of nodes",
75+
)
76+
@click.option(
77+
"--paginate",
78+
is_flag=True,
79+
required=False,
80+
default=True,
81+
help="Set True if pagination is required in the output. Default is True",
82+
)
7083
@add_filter_options
7184
@click.pass_context
7285
def results(
@@ -84,6 +97,8 @@ def results(
8497
compiler,
8598
config,
8699
git_branch,
100+
count,
101+
paginate,
87102
):
88103
logging.info("Starting maestro results command")
89104
logging.debug(
@@ -127,9 +142,12 @@ def results(
127142
logging.info(
128143
f"Fetching nodes with {len(filter)} filters, limit: {limit}, offset: {offset}"
129144
)
130-
results = maestro_get_nodes(url, limit, offset, filter)
145+
results = maestro_get_nodes(url, limit, offset, filter, paginate)
146+
if count:
147+
return results
131148

132149
logging.debug(f"Displaying results with fields: {field if field else 'all'}")
150+
133151
maestro_print_nodes(results, field)
134152

135153

kcidev/subcommands/results/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,27 @@ def summary(origin, git_folder, giturl, branch, commit, latest, arch, tree, use_
9898
type=int,
9999
default=7,
100100
)
101+
@click.option(
102+
"--verbose",
103+
is_flag=True,
104+
default=True,
105+
help="Print tree details",
106+
)
101107
@results_display_options
102-
def trees(origin, use_json, days):
108+
def trees(origin, use_json, days, verbose):
103109
"""List trees from a give origin."""
104-
cmd_list_trees(origin, use_json, days)
110+
return cmd_list_trees(origin, use_json, days, verbose)
105111

106112

107113
@results.command()
108114
@common_options
109115
@builds_and_tests_options
116+
@click.option(
117+
"--verbose",
118+
is_flag=True,
119+
default=True,
120+
help="Print build details",
121+
)
110122
def builds(
111123
origin,
112124
git_folder,
@@ -131,6 +143,7 @@ def builds(
131143
compatible,
132144
min_duration,
133145
max_duration,
146+
verbose,
134147
):
135148
"""Display build results."""
136149
giturl, branch, commit = set_giturl_branch_commit(
@@ -139,7 +152,7 @@ def builds(
139152
data = dashboard_fetch_builds(
140153
origin, giturl, branch, commit, arch, tree, start_date, end_date, use_json
141154
)
142-
cmd_builds(
155+
return cmd_builds(
143156
data,
144157
commit,
145158
download_logs,
@@ -149,6 +162,7 @@ def builds(
149162
git_branch,
150163
count,
151164
use_json,
165+
verbose,
152166
)
153167

154168

0 commit comments

Comments
 (0)