pulp/pulp-smash

Be notified when Pulp 3 returns multiple tasks after certain calls

Closed this issue · 1 comments

The code base currently includes this kludge:

# As of this writing, Pulp 3 only returns one task. If Pulp 3 starts
# returning multiple tasks, this may need to be re-written.
last_task = next(api.poll_spawned_tasks(cfg, call_report))
return client.get(last_task['created_resources'][0])

What happens if call_report leads to multiple tasks? Every task after the first is ignored. That's bad. Even worse, I noticed that this same idiom is repeated in a recent PR.

Let's update each of these cases with code like this:

# As of this writing, Pulp 3 only returns one task. If Pulp 3 starts
# returning multiple tasks, this may need to be re-written.
tasks = tuple(api.poll_spawned_tasks(cfg, call_report))
if len(tasks) != 1:
    warnings.warn(
        'Multiple tasks were spawned in response to an API call. This is '
        'unexpected, and Pulp Smash may handle the response incorrectly',
        RuntimeWarning
    )
return client.get(tasks[-1]['created_resources'][0])

Or code like this:

# As of this writing, Pulp 3 only returns one task. If Pulp 3 starts
# returning multiple tasks, this may need to be re-written.
tasks = tuple(api.poll_spawned_tasks(cfg, call_report))
assert len(tasks) == 1
return client.get(tasks[-1]['created_resources'][0])

...or so on.

See also: #795