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

Enable user to filter tasks by created_resources #229

Merged
merged 1 commit into from
Aug 22, 2019

Conversation

lubosmj
Copy link
Member

@lubosmj lubosmj commented Jul 23, 2019

@codecov
Copy link

codecov bot commented Jul 23, 2019

Codecov Report

Merging #229 into master will increase coverage by 0.07%.
The diff coverage is 89.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   67.66%   67.74%   +0.07%     
==========================================
  Files          69       69              
  Lines        3272     3289      +17     
==========================================
+ Hits         2214     2228      +14     
- Misses       1058     1061       +3
Impacted Files Coverage Δ
pulpcore/app/viewsets/task.py 93.58% <100%> (+0.08%) ⬆️
pulpcore/app/viewsets/custom_filters.py 92.66% <89.28%> (-1.17%) ⬇️
pulpcore/app/models/base.py 73.58% <0%> (-3.34%) ⬇️
pulpcore/app/serializers/repository.py 97.64% <0%> (-1.18%) ⬇️
pulpcore/app/viewsets/repository.py 98.58% <0%> (-0.71%) ⬇️
pulpcore/content/handler.py 62.76% <0%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd3ba8d...b96864d. Read the comment docs.

@lubosmj lubosmj requested a review from a team August 12, 2019 15:19


class FilterTaskCreatedResourcesTestCase(unittest.TestCase):
"""Perform filtering over reserved resources."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Perform filtering over reserved resources."""
"""Perform filtering over created resources."""



class FilterTaskCreatedResourcesContentTestCase(unittest.TestCase):
"""Perform filtering for contents of created resources."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this work has a related pulp.plan.io issue it would be nice to add as part of the docstring. It is very helpful later on.

Suggested change
"""Perform filtering for contents of created resources."""
"""Perform filtering for contents of created resources.
This test targets the following issue:
* `Pulp #xxx <https://pulp.plan.io/issues/xxxx>`
"""

cls.client = api.Client(config.get_config(), api.page_handler)

cls.repository = cls.client.post(REPO_PATH, gen_repo())
response = cls.client.post(cls.repository['_versions_href'])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is interesting. Goal here is to create a task. But I was expecting to be necessary to pass a few parameters to this endpoint: add_content_units, remove_content_units, or base_path. It seems that they are not mandatory.

https://docs.pulpproject.org/en/3.0/nightly/restapi.html#operation/repositories_versions_list

'created_resources': self.task['created_resources'][0]
}
results = self.client.get(TASKS_PATH, params=filter_params)
self.assertEqual(len(results), 1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(len(results), 1)
self.assertEqual(len(results), 1, results)

@@ -28,6 +32,7 @@ class TaskFilter(BaseFilterSet):
started_at = IsoDateTimeFilter(field_name='started_at')
finished_at = IsoDateTimeFilter(field_name='finished_at')
parent = HyperlinkRelatedFilter()
created_resources = RepositoryGenericRelationFilter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created resources can be not only repository versions but many other things like distributions, content, etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ http GET :24817/pulp/api/v3/tasks/?created_resources=/pulp/api/v3/distributions/docker/docker/ac1cbc69-1b1b-4108-90cd-45952dc2d60e/
HTTP/1.1 400 Bad Request
Allow: GET, HEAD, OPTIONS
Connection: close
Content-Length: 97
Content-Type: application/json
Date: Tue, 13 Aug 2019 14:51:16 GMT
Server: gunicorn/19.9.0
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

[
    "URI not valid: /pulp/api/v3/distributions/docker/docker/ac1cbc69-1b1b-4108-90cd-45952dc2d60e/"
]

Copy link
Member

@ipanova ipanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filter needs to be extended to other resources that repo version

@lubosmj lubosmj force-pushed the created-res-filter-4931 branch 2 times, most recently from bc1489f to a169fe9 Compare August 14, 2019 18:09
@lubosmj lubosmj force-pushed the created-res-filter-4931 branch 2 times, most recently from f89b220 to f5d6416 Compare August 21, 2019 15:57
Loop through the QuerySet and retrieve objects from a database which
are matching a type and a URI of a corresponding created resource.
"""
for task in qs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heres another pattern we can try:

from django.urls import resolve
match = resolve("/pulp/api/v3/repositories/38f857e4-92c5-4550-a087-7ce1a37f58a9/versions/1/")
match.func.cls.get_resource(
    "/pulp/api/v3/repositories/38f857e4-92c5-4550-a087-7ce1a37f58a9/versions/1/", 
    match.func.cls.queryset.model
)

Out: <Repository: 3e361f06-b81a-4c15-92af-3715d72d91a4; Version: 1>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which can be trimmed:

match = resolve(value)
return NamedModelViewSet.get_resource(value, match.func.cls.queryset.model)

Copy link
Member Author

@lubosmj lubosmj Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great! Will it work in every scenario, like filtering distributions, contents, repository versions, and so on?

I will definitely give it a try tomorrow. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, but I only tried it with repo versions because I had some lying around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested it manually and it seems to be working fine.

@lubosmj lubosmj force-pushed the created-res-filter-4931 branch 5 times, most recently from a10bbb8 to b96864d Compare August 22, 2019 10:23
Copy link
Member

@ipanova ipanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works! thank you 🍺

@ipanova ipanova merged commit 62ee868 into pulp:master Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants