nailgun icon indicating copy to clipboard operation
nailgun copied to clipboard

[6.15.z] Add json response to entity creation error message

Open Satellite-QE opened this issue 10 months ago • 3 comments

Cherrypick of PR: https://github.com/SatelliteQE/nailgun/pull/1119

Description of changes

Add json response to entity creation error message

  • Makes the error message information more detailed and informative
  • Possibility to write more precise assertions

There are some robottelo tests that would greatly benefit from more precise assertions on error messages, i.e. tests/foreman/api/test_repository.py::TestRepository::test_negative_update_checksum_with_on_demand_policy (or other tests in this module) I doubt that the supposed error message should be:

RuntimeError: The repository's publication is missing. Please run a 'complete sync' on MPvytWJ.","errors":["Task c7fa616b-2f71-4476-b581-1cae65a9eafd: RuntimeError: The repository's publication is missing. Please run a 'complete sync' on MPvytWJ."]}
Upstream API documentation, plugin, or feature links

None

Functional demonstration

Example:

before:

requests.exceptions.HTTPError: ('422 Client Error: Unprocessable Content for url: https://robottelo...')

after

requests.exceptions.HTTPError: ('422 Client Error: Unprocessable Content for url: https://...', {'displayMessage': 'Validation failed: When "Upstream URL" is set, "Releases/Distributions" must also be set!', 'errors': {'base': ['When "Upstream URL" is set, "Releases/Distributions" must also be set!']}}
Additional Information

None

Satellite-QE avatar Apr 17 '24 14:04 Satellite-QE

trigger: test-robottelo pytest: -k test_negative_update_checksum_with_on_demand_policy tests/foreman/api/test_repository.py

Satellite-QE avatar Apr 17 '24 14:04 Satellite-QE

PRT Result

Build Number: 26
Build Status: UNSTABLE
PRT Comment: pytest -k test_negative_update_checksum_with_on_demand_policy tests/foreman/api/test_repository.py --external-logging
Test Result : ==== 1 failed, 1 passed, 163 deselected, 195 warnings in 689.38s (0:11:29) =====

Satellite-QE avatar Apr 17 '24 14:04 Satellite-QE

@omkarkhatavkar I cannot see the cause of the error. Could you maybe paste the stacktrace?

dosas avatar Apr 25 '24 10:04 dosas

@omkarkhatavkar let me know if I can help you to get this PR fixed.

dosas avatar May 15 '24 09:05 dosas

trigger: test-robottelo pytest: -k test_negative_update_checksum_with_on_demand_policy tests/foreman/api/test_repository.py

omkarkhatavkar avatar May 15 '24 10:05 omkarkhatavkar

PRT Result

Build Number: 30
Build Status: UNSTABLE
PRT Comment: pytest -k test_negative_update_checksum_with_on_demand_policy tests/foreman/api/test_repository.py --external-logging
Test Result : ==== 1 failed, 1 passed, 163 deselected, 193 warnings in 667.88s (0:11:07) =====

Satellite-QE avatar May 15 '24 10:05 Satellite-QE

@dosas here is the stack

repo = robottelo.hosts.DecClass(ansible_collection_auth_url=None, ansible_collection_auth_token=None, ansible_collection_requ...stream_username=None, verify_ssl_on_sync=True, http_proxy_policy='global_default_http_proxy', http_proxy_id=None, id=1)

    @pytest.mark.tier1
    @pytest.mark.parametrize(
        'repo_options',
        **datafactory.parametrized(
            {
                checksum_type: {'checksum_type': checksum_type, 'download_policy': 'immediate'}
                for checksum_type in ('sha1', 'sha256')
            }
        ),
        indirect=True,
    )
    def test_negative_update_checksum_with_on_demand_policy(self, repo):
        """Attempt to update the download policy to on_demand on a repository with checksum type.
    
        :id: 5bfaef4f-de66-42a0-8419-b86d00ffde6f
    
        :parametrized: yes
    
        :expectedresults: A repository is not updated and error is raised.
    
        :CaseImportance: Critical
        """
        repo.download_policy = 'on_demand'
>       with pytest.raises(HTTPError):
E       Failed: DID NOT RAISE <class 'requests.exceptions.HTTPError'>

tests/foreman/api/test_repository.py:576: Failed

omkarkhatavkar avatar May 15 '24 12:05 omkarkhatavkar

@dosas here is the stack

repo = robottelo.hosts.DecClass(ansible_collection_auth_url=None, ansible_collection_auth_token=None, ansible_collection_requ...stream_username=None, verify_ssl_on_sync=True, http_proxy_policy='global_default_http_proxy', http_proxy_id=None, id=1)

    @pytest.mark.tier1
    @pytest.mark.parametrize(
        'repo_options',
        **datafactory.parametrized(
            {
                checksum_type: {'checksum_type': checksum_type, 'download_policy': 'immediate'}
                for checksum_type in ('sha1', 'sha256')
            }
        ),
        indirect=True,
    )
    def test_negative_update_checksum_with_on_demand_policy(self, repo):
        """Attempt to update the download policy to on_demand on a repository with checksum type.
    
        :id: 5bfaef4f-de66-42a0-8419-b86d00ffde6f
    
        :parametrized: yes
    
        :expectedresults: A repository is not updated and error is raised.
    
        :CaseImportance: Critical
        """
        repo.download_policy = 'on_demand'
>       with pytest.raises(HTTPError):
E       Failed: DID NOT RAISE <class 'requests.exceptions.HTTPError'>

tests/foreman/api/test_repository.py:576: Failed

Thank you.

  • Does this test fail for all parametrizations (sha1, sha256)?
  • Are we sure that this test is stable? I wonder why it did succeed for the master branch merge.

I do not exactly know what this katello code does but there was a change in this section 2 years ago that was just recently fixed in robottelo

I doubt that this error is caused by the change since the error raised is still the same.

dosas avatar May 15 '24 12:05 dosas

It looks like not related to this PR change.

omkarkhatavkar avatar May 15 '24 13:05 omkarkhatavkar