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] Use manifester from fixture #14405

Closed

Conversation

dosas
Copy link
Collaborator

@dosas dosas commented Mar 14, 2024

#14377

We should check with the authors of these tests, but I believe it was by design that they did not use Manifester via fixtures in these cases. function_entitlement_manifest returns a Request object, not a Manifester object, so the Manifester instance methods are not available to it or the other Manifester fixtures. If a test requires Manifester instance methods, it's currently necessary to instantiate Manifester locally in order to access those methods.

@omkarkhatavkar @ColeHiggins2 can you confirm that these tests are intentionally instantiating Manifester objects?

@dosas dosas requested a review from a team as a code owner March 14, 2024 11:25
@vsedmik vsedmik changed the title Use manifester from fixture [6.15.z] Use manifester from fixture Mar 14, 2024
Copy link
Contributor

@synkd synkd left a comment

Choose a reason for hiding this comment

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

PRT is currently down, but running the repositories test with these changes locally fails with an AttributeError:

$ pytest tests/foreman/api/test_repositories.py::test_negative_upload_expired_manifest
===================================================================================================================================== test session starts =====================================================================================================================================

*** snip ***

collected 1 item                                                                                                                                              

tests/foreman/api/test_repositories.py F                                                                                                                                                                                                                                                [100%]

========================================================================================================================================== FAILURES ===========================================================================================================================================
____________________________________________________________________________________________________________________________ test_negative_upload_expired_manifest ____________________________________________________________________________________________________________________________

*** snip ***

>       manifest = function_entitlement_manifest.get_manifest()
E       AttributeError: 'Response' object has no attribute 'get_manifest'

Debugging the test, we can see that function_entitlement_manifest is of type requests.models.Response, not a Manifester object:

-> manifest = function_entitlement_manifest.get_manifest()
(Pdb) type(function_entitlement_manifest)
<class 'requests.models.Response'>
(Pdb) function_entitlement_manifest.get_manifest()
*** AttributeError: 'Response' object has no attribute 'get_manifest'

As noted above, there are some test scenarios that currently require importing and instantiating Manifester in the test module. The two tests modified by this PR are examples of this type of scenario and will fail with these changes. I would therefore suggest that this PR be closed.

@dosas
Copy link
Collaborator Author

dosas commented Mar 14, 2024

@synkd Thanks for testing.

Now I get it, the problem is in the manifester context: https://github.com/SatelliteQE/manifester/blob/master/manifester/manifester.py#L421 it does not return an instance of manifester but the result of get_manifest() ...

In that case it should be closed. Would you be fine if I add a marker (pytest.mark.manifester) directly to those two tests?

@synkd
Copy link
Contributor

synkd commented Mar 14, 2024

@dosas You're welcome, and yes, you have the issue exactly right.

I have no problem with adding the manifester marker directly to these two tests.

@ColeHiggins2
Copy link
Member

ColeHiggins2 commented Mar 14, 2024

@dosas @synkd. @synkd is correct. Calling function_entitlement_manifest.get_manifest() will fail with AttributeError: 'Response' object has no attribute 'get_manifest'. I chose to use Manifester to directly act upon the manifest object for this specific test scenario. We needed an "expire manifest" for this test and one way to do that is to remove the subscription allocation. We do not want to delete the subscription allocation for other tests that may use the function_entitlement_manifest fixture within the same scope

@@ -199,10 +198,9 @@ def test_negative_upload_expired_manifest(module_org, target_sat):

:expectedresults: Manifest refresh should fail and return error message
"""
manifester = Manifester(manifest_category=settings.manifest.entitlement)
manifest = manifester.get_manifest()
manifest = function_entitlement_manifest.get_manifest()
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dosas As you've mentioned it does not return an instance of manifester but the result of get_manifest(), so what if we can just use function_entitlement_manifest for manifest?
CC @synkd @jyejare wdyt?

Suggested change
manifest = function_entitlement_manifest.get_manifest()
target_sat.upload_manifest(module_org.id, function_entitlement_manifest.content)
request.addfinalizer(function_entitlement_manifest.delete_subscription_allocation)

Copy link
Contributor

Choose a reason for hiding this comment

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

@Gauravtalreja1 This would be technically possible, but currently, it's a bit simpler to generate the manifest from a local Manifester instance. Manifester's delete_subscription_allocation method does allow passing in an arbitrary UUID argument for deletion [1], but the allocation UUID is not immediately accessible from the function_entitlement_manifest object. It's embedded in function_entitlement_manifest.url but would need to be extracted from a URL path like this one [2].

With that said, it should be a fairly simple change to add a line like the following to the end of Manifester's trigger_manifest_export method [3]:

manifest.uuid = self.allocation_uuid

The UUID would then be accessible as function_entitlement_manifest.uuid, which could be passed to Manifester.delete_subscription_allocation(). From the looks of it, this same change would also enable tests/upgrades/test_subscription.py::test_post_subscription_auto_attach to use a Manifester fixture.

If this is the direction that people want to go, then I'll also note that I would welcome a community contribution to Manifester making the necessary change.

[1] https://github.com/SatelliteQE/manifester/blob/8ff1e296d5dff89ccd9d76deffca8592807064ff/manifester/manifester.py#L184

[2] 'https://api.access.redhat.com/management/v1/allocations/0df90e19-9fda-49d8-8a3f-c7bc29ef1b23/export/2c94e7b58e14afed018e43cacf5b4db9'

[3] https://github.com/SatelliteQE/manifester/blob/8ff1e296d5dff89ccd9d76deffca8592807064ff/manifester/manifester.py#L400

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@synkd I can continue here once a new release of manifester is out

Copy link
Contributor

Choose a reason for hiding this comment

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

@dosas I just cut a new Manifester release that includes this change. However, the build/publish to PyPi job failed, and I will be OOO the rest of this week and next week. We'll need to hold off on merging this change until the new Manifester release is published, which may need to wait until I return.

Copy link
Collaborator Author

@dosas dosas Mar 26, 2024

Choose a reason for hiding this comment

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

I doubt that the uuid change will enable the usage of the fixture since it still does not provide an instance of manifester?
@synkd What do you think. For me this PR #14521 would be a valid alternative.

Copy link
Member

Choose a reason for hiding this comment

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

@synkd hello, mind revisiting this? it's been sitting here for a while. Thanks!

@jyejare
Copy link
Member

jyejare commented Mar 21, 2024

@dosas , Sorry to let you know that this has to be hold on until @synkd is back which will not happen this month.

@dosas
Copy link
Collaborator Author

dosas commented Mar 21, 2024

@dosas , Sorry to let you know that this has to be hold on until @synkd is back which will not happen this month.

no problem.

@ogajduse ogajduse requested a review from synkd April 2, 2024 17:05
@dosas dosas added the No-CherryPick PR doesnt need CherryPick to previous branches label Jun 19, 2024
@dosas
Copy link
Collaborator Author

dosas commented Jun 19, 2024

@synkd Are you okay with these changes?

@dosas
Copy link
Collaborator Author

dosas commented Jun 19, 2024

Not relevant anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
No-CherryPick PR doesnt need CherryPick to previous branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants