Bug 1244904

Summary: API: Support task search by parent_task_id
Product: Red Hat Satellite Reporter: Brad Buckingham <bbuckingham>
Component: APIAssignee: Brad Buckingham <bbuckingham>
Status: CLOSED ERRATA QA Contact: jaudet
Severity: high Docs Contact: David O'Brien <daobrien>
Priority: unspecified    
Version: 6.1.0CC: bbuckingham, cwelton, mmccune
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/11162
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-09-15 07:22:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1212602    

Description Brad Buckingham 2015-07-20 18:05:49 UTC
Description of problem:

Update foreman-tasks so that a user can search for tasks associated with a given parent_task_id.  This is useful for users that know the parent task and need to get access to it's children tasks.   This is needed to support RHCI and potentially other use cases.

E.g.

curl -k -u admin:password -H "Content-Type:application/json" -H "Accept:application/json,version=2" -X GET -d "{\"search\": \"parent_task_id=e3d1bd0e-652b-43f6-bb26-a9d389e7b466\"}" https://sat61fusor.example.com/foreman_tasks/api/tasks | json_reformat

Comment 1 RHEL Program Management 2015-07-20 18:14:34 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Brad Buckingham 2015-07-21 14:03:32 UTC
Upstream PR: 
https://github.com/theforeman/foreman-tasks/pull/127

Comment 4 Bryan Kearney 2015-07-22 08:04:37 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/11162 has been closed
-------------
Brad Buckingham
Applied in changeset commit:ef6d2c311ccc1c6c21536c8f312c6b678ed69c23.

Comment 5 David O'Brien 2015-08-20 05:26:56 UTC
Is this valid rel note material? Looks like just an RFE that's in the process of being addressed.

If valid, can someone provide suitable doc text? If not, pls remove the release note blocker flag.

thanks

Comment 6 Brad Buckingham 2015-08-20 13:13:58 UTC
This one is an RFE that is being added to support dependent projects; therefore, a rel note should not be needed.  I'll remove the sat61-release-notes blocker.

Comment 8 jaudet 2015-09-09 17:20:50 UTC
It's definitely possible to search for foreman tasks using the `parent_task_id`
filter. I can make no guarantees that the searches are semantically correct, but
it's definitely true that the form of the returned data appears sane.

I don't know how to definitively trigger parent and child tasks. Instead, I use
heuristics to verify this bug. I gather 1,000 foreman task IDs and perform a
search on each of those IDs, and then analyze the search results. 996 of the
searches return zero children, but 4 return one child. The search results appear
to have a sane form (at least the first one has an ID).

When Satellite receives an invalid search term, it typically ignores that search
term. If that was the case, then the 1,000 searches would have returned far, far
more results.

    >>> from nailgun.entities import ForemanTask
    >>> foreman_tasks = ForemanTask().search(query={'per_page': 1000})
    >>> len(foreman_tasks)
    1000
    >>> child_tasks = [
    ...     ForemanTask().search(query={
    ...         'search': 'parent_task_id={}'.format(foreman_task.id)
    ...     })
    ...     for foreman_task in foreman_tasks
    ... ]
    >>> len(child_tasks)
    1000
    >>> child_task_lengths = {}
    >>> for child_task in child_tasks:
    ...     child_task_len = len(child_task)
    ...     if child_task_len not in child_task_lengths:
    ...         child_task_lengths[child_task_len] = 1
    ...     else:
    ...         child_task_lengths[child_task_len] += 1
    ...
    >>> child_task_lengths  # Over 99% of tasks are childless.
    {0: 996, 1: 4}
    >>> [
    ...     i
    ...     for i, child_task in enumerate(child_tasks)
    ...     if len(child_task) > 0
    ... ]
    [298, 857, 863, 869]
    >>> child_tasks[298][0].id  # This is a sanity check on the returned data.
    u'bc41fef8-2028-4a19-8b54-2e683927658d'

Comment 10 errata-xmlrpc 2015-09-15 07:22:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2015:1786