Bug 1155513 - [RFE] Define API call to search for a package in all the consumers
Summary: [RFE] Define API call to search for a package in all the consumers
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Pulp
Classification: Retired
Component: API/integration
Version: unspecified
Hardware: Unspecified
OS: Unspecified
medium
low
Target Milestone: ---
: 2.6.0
Assignee: Andrea Giardini
QA Contact: Preethi Thomas
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-10-22 09:17 UTC by Andrea Giardini
Modified: 2015-02-28 23:42 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-02-19 01:19:55 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Pulp Redmine 262 0 None None None Never

Description Andrea Giardini 2014-10-22 09:17:28 UTC
Description of problem:

It makes sense to have an API call to search for a specific package, reporting his status for each consumers.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Andrea Giardini 2014-10-27 12:45:58 UTC
Do you have suggestion or guideline about the API implementation?

Comment 2 Brian Bouterse 2014-11-04 16:35:15 UTC
I think that this is already possible without any code changes. Can you try to achieve a search like that using the Advanced Search for Consumers [0]? You should be able to form GET style parameters that adhere to the search API [1].

When playing with the API I like to use a tool called pic [2]. Here's a pic hello world example:

from pulp.common import pic
pic.connect()
pic.GET('/pulp/api/v2/consumers/search/')

[0]: https://pulp-dev-guide.readthedocs.org/en/latest/integration/rest-api/consumer/retrieval.html#advanced-search-for-consumers
[1]: https://pulp-dev-guide.readthedocs.org/en/latest/conventions/criteria.html#search-api
[2]: https://github.com/pulp/pulp/blob/master/common/pulp/common/pic.py

Comment 3 Brian Bouterse 2014-11-04 22:17:12 UTC
Here is an unrelated example, except that it uses the search API. Here is how I search for tasks that are in the running state:

from pulp.common import pic
pic.connect()

body = {"criteria": {"filters": {"state":"running"}}}
pic.POST('/pulp/api/v2/tasks/search/', body)

The Search API json is used as the payload of the POST to the URL. I wanted to paste this here since I already had it and it is a related example.

Comment 4 Andrea Giardini 2014-11-05 09:42:41 UTC
I don't think that's possible but i will try to investigate...

Tell me if i'm wrong:
/pulp/api/v2/tasks/search/ -> search on the 'tasks_status' mongo table
/pulp/api/v2/consumers/search/ -> search on the 'consumers' mongo table

Is it correct?

Comment 5 Brian Bouterse 2014-11-06 14:17:03 UTC
After some discussion on IRC it was determined:

The URLs in comment 4 don't search on the consumer_unit_profile. Apparently no URL actually provides search on that table so introducing a new URL seems like the right thing to do.

I propose the following URL be introduced:

/pulp/api/v2/consumers/profile/search/

This is consistent with the existing consumer search URLs for bindings for example:

/pulp/api/v2/consumers/binding/search/

Also, since this is a reverse compatible new API change it would need to be introduced in a 2.Y release.

Comment 6 Andrea Giardini 2014-11-12 09:24:36 UTC
Pull request submitted here:

https://github.com/pulp/pulp/pull/1292

Comment 7 Brian Bouterse 2014-11-13 16:39:02 UTC
Merged to master. QA, please see the docs that were added [0] to test this feature.

[0]: http://pulp.readthedocs.org/en/latest/dev-guide/integration/rest-api/consumer/profile.html#searching-profiles

Comment 8 Chris Duryee 2014-12-23 20:52:59 UTC
fixed in pulp 2.6.0-0.2.beta

Comment 9 Preethi Thomas 2015-02-02 21:34:13 UTC
Fails-qa

GET worked fine for me
but for post doesnt return any respone

>>> pic.POST('/v2/consumers/profile/search/',body={"criteria": { "filters": {"profile_name": "screen"},"fields":  ["consumer_id","foo"] }})
Request Body
{
  "criteria": {
    "fields": [
      "consumer_id", 
      "foo"
    ], 
    "filters": {
      "profile_name": "screen"
    }
  }
}
Response Body
[]
(200, [])



I do have a consumer foo.

>>> pic.GET('/v2/consumers/')
Response Body
[
  {
    "display_name": "foo", 
    "description": null, 
    "_ns": "consumers", 
    "notes": {
      "_node-update-strategy": "additive", 
      "_child-node": true
    },

Comment 10 Preethi Thomas 2015-02-03 14:57:37 UTC
Looks like it was user error.
Moving to verified
[root@cloud-qe-4 ~]# rpm -qa |grep pulp-server
pulp-server-2.6.0-0.5.beta.el7
I used profile_name instead of profile.name

When used with profile.name the correct response is given.

>>> pic.POST('/v2/consumers/profile/search/',body={"criteria": { "filters": {"profile.name": "screen"},"fields":  ["consumer_id","foo"] }})
Request Body
{
  "criteria": {
    "fields": [
      "consumer_id", 
      "foo"
    ], 
    "filters": {
      "profile.name": "screen"
    }
  }
}
Response Body
[
  {
    "_id": {
      "$oid": "54cad13f9f9b813d5b604cfc"
    }, 
    "id": "54cad13f9f9b813d5b604cfc", 
    "consumer_id": "foo"
  }
]
(200, [{u'_id': {u'$oid': u'54cad13f9f9b813d5b604cfc'}, u'id': u'54cad13f9f9b813d5b604cfc', u'consumer_id': u'foo'}])

Comment 11 Randy Barlow 2015-02-05 21:49:57 UTC
Moving to verified, as per Preethi's comment.

Comment 12 Brian Bouterse 2015-02-19 01:19:55 UTC
Moved to https://pulp.plan.io/issues/262


Note You need to log in before you can comment on or make changes to this bug.