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

Quick fix- CI failure- for number of found CV publish tasks #14890

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/foreman/api/test_contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def test_negative_publish_during_repo_sync(self, content_view, module_target_sat
2. HTTP exception raised, assert publish task failed for expected reason,
repo sync task_id found in humanized error, content-view versions unchanged.
"""
org = content_view.organization.read()
# add repository to content-view
content_view.repository = [self.yum_repo]
content_view.update(['repository'])
Expand All @@ -565,15 +566,14 @@ def test_negative_publish_during_repo_sync(self, content_view, module_target_sat
with pytest.raises(HTTPError) as InternalServerError:
content_view.publish()
assert str(content_view.id) in str(InternalServerError)

# search for failed publish task
task_action = 'Actions::Katello::ContentView::Publish'
task_action = f"Publish content view '{content_view.name}', organization '{org.name}'"
task_search = module_target_sat.api.ForemanTask().search(
query={'search': f'{task_action} and started_at >= "{timestamp}"'}
)
assert len(task_search) == 1
assert len(task_search) > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get the task id of publish task and search for it. It will be unique and you will get a single task.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the CV.publish() task fails from raised exception, it does not return task_id as it normally would, the method returns None.
Do you know if there's some way to workaround this?

Copy link
Contributor Author

@damoore044 damoore044 Apr 29, 2024

Choose a reason for hiding this comment

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

@shweta83 Also tried asynchronous Publish, it also returns None once exception is raised/caught.
Instead I've updated to narrow the search scope, for just the publish task(s) with the desired cv.name and org.name.
Let me know if this addresses your suggestion!

Copy link
Contributor

Choose a reason for hiding this comment

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

task_search returns a task id which you can search in tasks and it will return a single task failed:
label='Actions::Katello::ContentView::Publish', output={}, pending=False, progress=1, result='error', started_at='2024-04-29 14:13:58 UTC', state='stopped', id='350e6a11-651b-408d-85df-09ea569296b1').

This id can be used to search that task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in lines below, I get id from first entry in task_search, which returns like the output in your comment.
Then I poll that task by id and get failed output.
Am I missing something else or some other step for getting task id, other than ForemanTask.search()?

task_id = task_search[0].id
# task failed for expected reason
# publish task failed for expected reason
task = module_target_sat.api.ForemanTask(id=task_id).poll(must_succeed=False)
assert task['result'] == 'error'
assert len(task['humanized']['errors']) == 1
Expand Down
Loading