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

[6.15.z] addFinalizer in test body #14422

Conversation

Satellite-QE
Copy link
Collaborator

Cherrypick of PR: #14036

Problem Statement

Turns out that @request.addFinalizer when used in test body (not in fixture) is dependent on the execution order, so basically when some assertion defined in the test before the finalizer part fails, finalizer is not added and so not executed.

This exactly happened in test_positive_disable_hammer_defaults in upgrades, breaking a lot of other tests in the same run. Big kudos to @lpramuk for isolating the issue there.

Solution

Moving the addFinalizer part to the start of the test, fixes the problem. Prt run won't reveal much in this case, but running the previous version of the test with induced assertion error leaves satellite with:

~]# hammer defaults list
----------------|------
PARAMETER       | VALUE
----------------|------
organization_id | 41   
----------------|------

...which means that the finalizer didn't run. With this pr, the defaults are properly cleaned up:

~]# hammer defaults list
----------|------
PARAMETER | VALUE
----------|------

Related Issues

I did a quick search for this pattern across robottelo and I found quite a bit of cases where @request.addfinalizer is added towards the end of the test body, with some preceding assertions that could possibly break it:

This doesn't include request.addFinalizer(...) calls that likely suffer from the same problem. Now, I could go and reorder all those occurrences, but I feel we should discuss this team wide and maybe abolish this practice all together

* reordered addFinalizer in test body

* Update tests/foreman/cli/test_errata.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/api/test_discoveryrule.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/cli/test_errata.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/destructive/test_capsule_loadbalancer.py

Co-authored-by: Gaurav Talreja <[email protected]>

---------

Co-authored-by: Gaurav Talreja <[email protected]>
(cherry picked from commit 84e54f2)
@Satellite-QE Satellite-QE requested a review from a team as a code owner March 15, 2024 13:44
@Satellite-QE Satellite-QE added 6.15.z Introduced in or relating directly to Satellite 6.15 Auto_Cherry_Picked Automatically cherrypicked PR using GHA No-CherryPick PR doesnt need CherryPick to previous branches labels Mar 15, 2024
@Gauravtalreja1 Gauravtalreja1 merged commit 795c0c7 into 6.15.z Mar 15, 2024
11 checks passed
@Gauravtalreja1 Gauravtalreja1 deleted the cherry-pick-6.15.z-84e54f220f57fadc44d47a69347eb8e9f42b3d92 branch March 15, 2024 19:54
damoore044 pushed a commit to damoore044/robottelo that referenced this pull request Mar 18, 2024
addFinalizer in test body (SatelliteQE#14036)

* reordered addFinalizer in test body

* Update tests/foreman/cli/test_errata.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/api/test_discoveryrule.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/cli/test_errata.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/destructive/test_capsule_loadbalancer.py

Co-authored-by: Gaurav Talreja <[email protected]>

---------

Co-authored-by: Gaurav Talreja <[email protected]>
(cherry picked from commit 84e54f2)

Co-authored-by: Peter Ondrejka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.15.z Introduced in or relating directly to Satellite 6.15 Auto_Cherry_Picked Automatically cherrypicked PR using GHA No-CherryPick PR doesnt need CherryPick to previous branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants