Skip to content

Commit

Permalink
Add the pulp_created as a filter field for tasks viewset.
Browse files Browse the repository at this point in the history
Adds the `pulp_created` datetime field as a filter to allow
filtering tasks by its creation date. Also, adds a test to
check if the filter is working as expected.
  • Loading branch information
decko committed Feb 4, 2025
1 parent 21f2c21 commit c93bebc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/6241.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `pulp_created` filter for Tasks API.
1 change: 1 addition & 0 deletions pulpcore/app/viewsets/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Meta:
"worker": ["exact", "in", "isnull"],
"name": ["exact", "contains", "in", "ne"],
"logging_cid": ["exact", "contains"],
"pulp_created": DATETIME_FILTER_OPTIONS,
"started_at": DATETIME_FILTER_OPTIONS,
"finished_at": DATETIME_FILTER_OPTIONS,
"unblocked_at": DATETIME_FILTER_OPTIONS,
Expand Down
28 changes: 28 additions & 0 deletions pulpcore/tests/functional/api/test_tasking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

from aiohttp import BasicAuth
from datetime import datetime
from urllib.parse import urljoin
from uuid import uuid4

Expand Down Expand Up @@ -272,6 +273,33 @@ def test_filter_tasks_using_worker__in_filter(pulpcore_bindings, dispatch_task,
assert task2_href in tasks_hrefs


@pytest.mark.parallel
def test_filter_tasks_using_pulp_created_filter(pulpcore_bindings, dispatch_task):

task1_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,))

time.sleep(2)
start_time = datetime.now()
task2_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,))
task3_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,))

search_results_gte = pulpcore_bindings.TasksApi.list(pulp_created__gte=start_time)

tasks_hrefs_gte = [task.pulp_href for task in search_results_gte.results]

assert task1_href not in tasks_hrefs_gte
assert task2_href in tasks_hrefs_gte
assert task3_href in tasks_hrefs_gte

search_results_lte = pulpcore_bindings.TasksApi.list(pulp_created__lte=start_time)

tasks_hrefs_lte = [task.pulp_href for task in search_results_lte.results]

assert task1_href in tasks_hrefs_lte
assert task2_href not in tasks_hrefs_lte
assert task3_href not in tasks_hrefs_lte


def test_cancel_gooey_task(pulpcore_bindings, dispatch_task, monitor_task):
task_href = dispatch_task("pulpcore.app.tasks.test.gooey_task", args=(60,))
for i in range(10):
Expand Down

0 comments on commit c93bebc

Please sign in to comment.