Skip to content
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

Add the --wait option to the task-group show command #565

Merged
merged 1 commit into from
Oct 12, 2022
Merged
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
2 changes: 2 additions & 0 deletions CHANGES/459.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Introduced the option ``--wait`` for the task-group show command.
By using this option, details of the task-group will be shown only after waiting for all related tasks to finish.
2 changes: 1 addition & 1 deletion pulpcore/cli/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def wait_for_task_group(self, task_group: EntityDefinition) -> Any:
time.sleep(1)
self.echo(".", nl=False, err=True)
task_group = self.api.call(
"task_group_read", parameters={"task_group_href": task_group["pulp_href"]}
"task_groups_read", parameters={"task_group_href": task_group["pulp_href"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bugfix. Didn't we have tests for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a bug fix. I think we do not have any tests for it. The method wait_for_task_group was not invoked anywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

)
except KeyboardInterrupt:
raise PulpNoWait(
Expand Down
60 changes: 57 additions & 3 deletions pulpcore/cli/core/task_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from typing import Optional

import click

from pulpcore.cli.common.context import PulpContext, pass_pulp_context
from pulpcore.cli.common.generic import href_option, list_command, pulp_group, show_command
from pulpcore.cli.common.context import PulpContext, PulpEntityContext
from pulpcore.cli.common.generic import (
href_option,
list_command,
pass_entity_context,
pass_pulp_context,
pulp_group,
pulp_option,
)
from pulpcore.cli.common.i18n import get_translation
from pulpcore.cli.core.context import PulpTaskGroupContext

Expand All @@ -17,4 +26,49 @@ def task_group(ctx: click.Context, pulp_ctx: PulpContext) -> None:


task_group.add_command(list_command())
task_group.add_command(show_command(decorators=[href_option]))


def _uuid_callback(
ctx: click.Context, param: click.Parameter, value: Optional[str]
) -> Optional[str]:
if value is not None:
entity_ctx = ctx.find_object(PulpEntityContext)
assert entity_ctx is not None
entity_ctx.pulp_href = f"{entity_ctx.pulp_ctx.api_path}task-groups/{value}/"
return value


uuid_option = pulp_option(
"--uuid",
help=_("UUID of the {entity}"),
callback=_uuid_callback,
expose_value=False,
)


@task_group.command()
@href_option
@uuid_option
@click.option("-w", "--wait", is_flag=True, help=_("Wait for the group-task to finish"))
@pass_entity_context
@pass_pulp_context
def show(pulp_ctx: PulpContext, task_group_ctx: PulpTaskGroupContext, wait: bool) -> None:
"""Shows details of a group-task."""
entity = task_group_ctx.entity
if wait:
if not entity["all_tasks_dispatched"]:
click.echo(_("Waiting for all tasks to be dispatched"), err=True)
else:
unfinished_tasks = []
for task in entity["tasks"]:
if task["state"] in ["waiting", "running", "canceling"]:
unfinished_tasks.append(task["pulp_href"])

if unfinished_tasks:
click.echo(
_("Waiting for the following tasks to finish: {}").format(unfinished_tasks),
err=True,
)

entity = pulp_ctx.wait_for_task_group(entity)
pulp_ctx.output_result(entity)
9 changes: 7 additions & 2 deletions tests/scripts/pulp_file/test_acs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ expect_succ pulp file acs show --name $acs
test "$(echo "$OUTPUT" | jq ".paths | length")" -eq 2

# test refresh
expect_succ pulp file acs refresh --name $acs
expect_succ pulp --background file acs refresh --name $acs
task_group=$(echo "$ERROUTPUT" | grep -E -o "${PULP_API_ROOT}api/v3/task-groups/[-[:xdigit:]]*/")
expect_succ pulp task-group show --href "$task_group"
expect_succ pulp task-group show --href "$task_group" --wait

group_task_uuid="${task_group%/}"
group_task_uuid="${group_task_uuid##*/}"
expect_succ pulp task-group show --uuid "$group_task_uuid"

test "$(echo "$OUTPUT" | jq ".tasks | length")" -eq 2

# create a remote with manifest only and sync it
Expand Down