diff --git a/kcidev/main.py b/kcidev/main.py index 1954be1..6380d9d 100755 --- a/kcidev/main.py +++ b/kcidev/main.py @@ -14,7 +14,6 @@ maestro, results, testretry, - validate, watch, ) @@ -64,7 +63,6 @@ def run(): cli.add_command(maestro.maestro) cli.add_command(testretry.testretry) cli.add_command(results.results) - cli.add_command(validate.validate) cli.add_command(watch.watch) cli() diff --git a/kcidev/subcommands/maestro/__init__.py b/kcidev/subcommands/maestro/__init__.py index 12723bf..c5729cf 100644 --- a/kcidev/subcommands/maestro/__init__.py +++ b/kcidev/subcommands/maestro/__init__.py @@ -6,6 +6,7 @@ import click from kcidev.subcommands.maestro.results import results +from kcidev.subcommands.maestro.validate import validate @click.group( @@ -37,7 +38,7 @@ def maestro(ctx): # Add subcommands to the maestro group maestro.add_command(results) - +maestro.add_command(validate) if __name__ == "__main__": from kcidev.libs.common import main_kcidev diff --git a/kcidev/subcommands/validate/__init__.py b/kcidev/subcommands/maestro/validate/__init__.py similarity index 66% rename from kcidev/subcommands/validate/__init__.py rename to kcidev/subcommands/maestro/validate/__init__.py index afb81c5..5c2f574 100644 --- a/kcidev/subcommands/validate/__init__.py +++ b/kcidev/subcommands/maestro/validate/__init__.py @@ -2,9 +2,8 @@ import click -from kcidev.subcommands.validate.boots import boots -from kcidev.subcommands.validate.builds import builds -from kcidev.subcommands.validate.builds_history import builds_history +from kcidev.subcommands.maestro.validate.boots import boots +from kcidev.subcommands.maestro.validate.builds import builds @click.group( @@ -14,7 +13,6 @@ Subcommands: builds - Validate build results boots - Validate boot results - builds-history - Validate builds history \b Examples: @@ -25,8 +23,8 @@ kci-dev validate boots --all-checkouts --days kci-dev validate boots -commit --giturl --branch # Validate builds history - kci-dev validate builds-history --all-checkouts --days --arch - kci-dev validate builds-history -commit --giturl --branch --days + kci-dev validate builds --history --all-checkouts --days --arch + kci-dev validate builds --history -commit --giturl --branch --days """, invoke_without_command=True, ) @@ -41,7 +39,6 @@ def validate(ctx): # Add subcommands to the validate group validate.add_command(builds) validate.add_command(boots) -validate.add_command(builds_history) if __name__ == "__main__": diff --git a/kcidev/subcommands/validate/boots.py b/kcidev/subcommands/maestro/validate/boots.py similarity index 100% rename from kcidev/subcommands/validate/boots.py rename to kcidev/subcommands/maestro/validate/boots.py diff --git a/kcidev/subcommands/validate/builds.py b/kcidev/subcommands/maestro/validate/builds.py similarity index 50% rename from kcidev/subcommands/validate/builds.py rename to kcidev/subcommands/maestro/validate/builds.py index 1fa5e33..ff84e61 100644 --- a/kcidev/subcommands/validate/builds.py +++ b/kcidev/subcommands/maestro/validate/builds.py @@ -3,7 +3,7 @@ from kcidev.libs.git_repo import get_tree_name, set_giturl_branch_commit from kcidev.subcommands.results import trees -from .helper import get_build_stats, print_stats +from .helper import get_build_stats, get_builds_history_stats, print_stats @click.command( @@ -19,10 +19,18 @@ If above options are not provided, if will take latest/provided commit checkout from the git folder specified. +Builds history validation, i.e. checking if number of builds is consistent +for different checkouts of the same git tree/branch, can be performed by the command +by providing --history option. + \b Examples: + # Build validation kci-dev validate builds --all-checkouts --days kci-dev validate builds -commit --giturl --branch + # Build history validation + kci-dev validate builds --history --all-checkouts --days + kci-dev validate builds --history --giturl --branch --days """, ) @click.option( @@ -63,6 +71,11 @@ help="Select latest results available", ) @click.option("--arch", help="Filter by arch") +@click.option( + "--history", + is_flag=True, + help="Check if number of builds is consistent for different checkouts of the same git tree/branch", +) @click.option( "--verbose", is_flag=True, @@ -81,6 +94,7 @@ def builds( latest, arch, days, + history, verbose, ): final_stats = [] @@ -90,17 +104,34 @@ def builds( raise click.UsageError( "Cannot use --all-checkouts with --giturl, --branch, or --commit" ) - trees_list = ctx.invoke(trees, origin=origin, days=days, verbose=False) - for tree in trees_list: - giturl = tree["git_repository_url"] - branch = tree["git_repository_branch"] - commit = tree["git_commit_hash"] - tree_name = tree["tree_name"] - stats = get_build_stats( - ctx, giturl, branch, commit, tree_name, verbose, arch - ) - if stats: - final_stats.append(stats) + if history: + trees_list = ctx.invoke(trees, origin=origin, days=days, verbose=False) + for tree in trees_list: + giturl = tree["git_repository_url"] + branch = tree["git_repository_branch"] + tree_name = tree["tree_name"] + stats = get_builds_history_stats( + ctx, giturl, branch, tree_name, arch, days, verbose + ) + if stats: + final_stats.extend(stats) + else: + trees_list = ctx.invoke(trees, origin=origin, days=days, verbose=False) + for tree in trees_list: + giturl = tree["git_repository_url"] + branch = tree["git_repository_branch"] + commit = tree["git_commit_hash"] + tree_name = tree["tree_name"] + stats = get_build_stats( + ctx, giturl, branch, commit, tree_name, verbose, arch + ) + if stats: + final_stats.append(stats) + elif history: + tree_name = get_tree_name(origin, giturl, branch) + final_stats = get_builds_history_stats( + ctx, giturl, branch, tree_name, arch, days, verbose + ) else: giturl, branch, commit = set_giturl_branch_commit( origin, giturl, branch, commit, latest, git_folder @@ -110,15 +141,27 @@ def builds( if stats: final_stats.append(stats) if final_stats: - headers = [ - "tree/branch", - "Commit", - "Maestro\nbuilds", - "Dashboard\nbuilds", - "Build count\ncomparison", - "Missing build IDs", - "Builds with\nstatus mismatch", - ] - max_col_width = [None, 40, 3, 3, 2, 30, 30] + if history: + headers = [ + "tree/branch", + "Commit", + "Maestro\nbuilds", + "Dashboard\nbuilds", + "Build count\ncomparison", + "Missing build IDs", + ] + max_col_width = [None, 40, 3, 3, 2, 30] + + else: + headers = [ + "tree/branch", + "Commit", + "Maestro\nbuilds", + "Dashboard\nbuilds", + "Build count\ncomparison", + "Missing build IDs", + "Builds with\nstatus mismatch", + ] + max_col_width = [None, 40, 3, 3, 2, 30, 30] table_fmt = "simple_grid" print_stats(final_stats, headers, max_col_width, table_fmt) diff --git a/kcidev/subcommands/validate/helper.py b/kcidev/subcommands/maestro/validate/helper.py similarity index 93% rename from kcidev/subcommands/validate/helper.py rename to kcidev/subcommands/maestro/validate/helper.py index c34f4fe..f2afdeb 100644 --- a/kcidev/subcommands/validate/helper.py +++ b/kcidev/subcommands/maestro/validate/helper.py @@ -43,7 +43,10 @@ def get_builds(ctx, giturl, branch, commit, arch): arch=arch, ) except click.Abort: - kci_msg_red("Aborted while fetching dashboard builds") + kci_msg_red(f"{branch}/{commit}: Aborted while fetching dashboard builds") + return maestro_builds, None + except click.ClickException as e: + kci_msg_red(f"{branch}/{commit}: {e.message}") return maestro_builds, None return maestro_builds, dashboard_builds @@ -211,7 +214,10 @@ def get_boots(ctx, giturl, branch, commit, arch): arch=arch, ) except click.Abort: - kci_msg_red("Aborted while fetching dashboard boots") + kci_msg_red(f"{branch}/{commit}: Aborted while fetching dashboard boots") + return maestro_boots, None + except click.ClickException as e: + kci_msg_red(f"{branch}/{commit}: {e.message}") return maestro_boots, None return maestro_boots, dashboard_boots @@ -303,11 +309,12 @@ def get_builds_history(ctx, checkouts, arch): paginate=False, ) + branch = c["data"]["kernel_revision"].get("branch") try: dashboard_builds = ctx.invoke( builds, giturl=c["data"]["kernel_revision"].get("url"), - branch=c["data"]["kernel_revision"].get("branch"), + branch=branch, commit=commit, count=True, verbose=False, @@ -315,5 +322,7 @@ def get_builds_history(ctx, checkouts, arch): ) builds_history.append([commit, maestro_builds, dashboard_builds]) except click.Abort: - kci_msg_red("Aborted while fetching dashboard builds") + kci_msg_red(f"{branch}/{commit}: Aborted while fetching dashboard builds") + except click.ClickException as e: + kci_msg_red(f"{branch}/{commit}: {e.message}") return builds_history diff --git a/kcidev/subcommands/validate/builds_history.py b/kcidev/subcommands/validate/builds_history.py deleted file mode 100644 index ea4af77..0000000 --- a/kcidev/subcommands/validate/builds_history.py +++ /dev/null @@ -1,99 +0,0 @@ -import click - -from kcidev.libs.git_repo import get_tree_name -from kcidev.subcommands.results import trees - -from .helper import get_builds_history_stats, print_stats - - -@click.command( - name="builds-history", - help="""Validate dashboard builds history with maestro. - -The command can be used to check if number of builds is consitent -for different checkouts of the same git tree/branch. -`--days` option is used to fetch checkouts created during the mentioned days. -Default is `7` days. - -\b -Examples: - kci-dev validate builds-history --all-checkouts --days - kci-dev validate builds-history --giturl --branch --days -""", -) -@click.option( - "--all-checkouts", - is_flag=True, - help="Get build validation stats for all available checkouts", -) -@click.option( - "--days", - help="Provide a period of time in days to get results for", - type=int, - default="7", -) -@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("--arch", help="Filter by arch") -@click.option( - "--verbose", - is_flag=True, - default=False, - help="Get detailed output", -) -@click.pass_context -def builds_history( - ctx, - all_checkouts, - origin, - giturl, - branch, - arch, - days, - verbose, -): - final_stats = [] - print("Fetching builds history information...") - if all_checkouts: - if giturl or branch: - raise click.UsageError( - "Cannot use --all-checkouts with --giturl or --branch" - ) - trees_list = ctx.invoke(trees, origin=origin, days=days, verbose=False) - for tree in trees_list: - giturl = tree["git_repository_url"] - branch = tree["git_repository_branch"] - tree_name = tree["tree_name"] - stats = get_builds_history_stats( - ctx, giturl, branch, tree_name, arch, days, verbose - ) - if stats: - final_stats.extend(stats) - else: - tree_name = get_tree_name(origin, giturl, branch) - final_stats = get_builds_history_stats( - ctx, giturl, branch, tree_name, arch, days, verbose - ) - if final_stats: - headers = [ - "tree/branch", - "Commit", - "Maestro\nbuilds", - "Dashboard\nbuilds", - "Build count\ncomparison", - "Missing build IDs", - ] - max_col_width = [None, 40, 3, 3, 2, 30] - table_fmt = "simple_grid" - print_stats(final_stats, headers, max_col_width, table_fmt)