Skip to content

Commit

Permalink
some endpoints do not include spawned_tasks so treat it as optional…
Browse files Browse the repository at this point in the history
… when polling for tasks [noissue]
  • Loading branch information
ironfroggy authored and kersommoura committed Oct 29, 2019
1 parent 359e6e9 commit c54d593
Showing 1 changed file with 24 additions and 18 deletions.
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

0 comments on commit c54d593

Please sign in to comment.