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

Task polling fix for pulp_ansible Galaxy V3 API tests #1225

Merged
merged 1 commit into from
Oct 29, 2019
Merged
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
42 changes: 24 additions & 18 deletions pulp_smash/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def page_handler(client, response):


def task_handler(client, response):
"""Wait tasks to complete and collect resources.
"""Wait for tasks to complete and then collect resources.

Do the following:

Expand Down Expand Up @@ -257,15 +257,18 @@ def task_handler(client, response):

if response.request.method == "POST":
# Task might have created new resources
created = done_task["created_resources"]
logger.debug("Task created resources: %s", created)
if len(created) == 1: # Single resource href
return client.using_handler(json_handler).get(created[0])
if len(created) > 1: # Multiple resource hrefs
return [
client.using_handler(json_handler).get(resource_href)
for resource_href in created
]
if "created_resources" in done_task:
created = done_task["created_resources"]
logger.debug("Task created resources: %s", created)
if len(created) == 1: # Single resource href
return client.using_handler(json_handler).get(created[0])
if len(created) > 1: # Multiple resource hrefs
return [
client.using_handler(json_handler).get(resource_href)
for resource_href in created
]
else:
return []

if response.request.method in ["PUT", "PATCH"]:
# Task might have updated resource so re-read and return it back
Expand Down Expand Up @@ -710,14 +713,17 @@ def poll_task(cfg, href, pulp_host=None):
# This task has completed. Yield its final state, then recursively
# iterate through children and yield their final states.
yield task
for spawned_task in task["spawned_tasks"]:
key = (
"_href" if cfg.pulp_version < Version("3") else "pulp_href"
)
for descendant_tsk in poll_task(
cfg, spawned_task[key], pulp_host
):
yield descendant_tsk
if "spawned_tasks" in task:
for spawned_task in task["spawned_tasks"]:
key = (
"_href"
if cfg.pulp_version < Version("3")
else "pulp_href"
)
for descendant_tsk in poll_task(
cfg, spawned_task[key], pulp_host
):
yield descendant_tsk
break
poll_counter += 1
if poll_counter > poll_limit:
Expand Down