Skip to content

fix: improve wording for unassignable Policy #4414

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

Merged
merged 1 commit into from
May 20, 2025

Conversation

romanblanco
Copy link
Member

@romanblanco romanblanco commented Apr 3, 2025

https://issues.redhat.com/browse/RHINENG-10847

When Compliance tries to assign Host to a Policy, it returns either 202 in case of success or 404 in any other case.

When one tries to assign a Host that already has a Policy assigned, the Policy is not anymore in the list of available options, hence the process can not succeed with creating the link and returns 404.

That in the logic of insights-client seems as failure, and it returns non-zero error status with the confusing message "Policy ... does not exist".

This commit is to improve the message sent in such case to make it less misleading.

@LightOfHeaven1994
Copy link
Contributor

@romanblanco as there are might be 2 cases:

  1. Policy doesn't exist
  2. Policy exists but host can't be assigned due to already existing association

For the 2nd case we might want to add additional request to else block: systems/{ID}/policies?limit=100&ids_only=true and check if policy id is already there - then we return message "Policy already associated to host"
And if not - "Policy doesn't exist"

It's not cool to have another request for that but it will be beneficial for all of us + this request is easy one for backend.

You also need to sign off your PR (git commit --amend -s) and update tests

@@ -227,7 +227,7 @@ def policy_link(self, policy_id, opt):
logger.info("Operation completed successfully.\n")
Copy link
Contributor

@Mishrasubha Mishrasubha Apr 3, 2025

Choose a reason for hiding this comment

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

can we also change Operation completed successfully to something more specific like System successfully assigned to policy?

@xiangce
Copy link
Contributor

xiangce commented Apr 7, 2025

@romanblanco, Please also update the expected assert string in tests. Thanks.

@sayan3296
Copy link

From a user's point of view, along with saying that Policy ID xxyy can not be assigned. can we also say \ append this string i.e. Refer to the /var/log/insights-client/insights-client.log for more details. ?

I believe that would probably help delivering a better user-experience here.

@romanblanco romanblanco force-pushed the reword-error-message branch 2 times, most recently from 38cc746 to da0b004 Compare May 16, 2025 12:35
    When Compliance tries to assign Host to a Policy,
    it returns either 202 in case of success or 404 in any other case.

    When one tries to assign a Host that already has a Policy assigned,
    the Policy is not anymore in the list of available options,
    hence the process can not succeed with creating the link and returns 404.

    That in the logic of insights-client seems as failure, and it returns
    non-zero error status with the confusing message
    "Policy ... does not exist".

    This commit is to improve the message sent in such case to make it
    less misleading.

Signed-off-by: Roman Blanco <[email protected]>
@romanblanco romanblanco force-pushed the reword-error-message branch from da0b004 to e78ea6f Compare May 16, 2025 12:43
@codecov-commenter
Copy link

codecov-commenter commented May 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.69%. Comparing base (ba8350d) to head (e78ea6f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4414      +/-   ##
==========================================
- Coverage   77.70%   77.69%   -0.01%     
==========================================
  Files         745      745              
  Lines       41740    41740              
  Branches     6704     6704              
==========================================
- Hits        32432    32430       -2     
- Misses       8277     8278       +1     
- Partials     1031     1032       +1     
Flag Coverage Δ
unittests 77.68% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@romanblanco
Copy link
Member Author

as there are might be 2 cases:

  1. Policy doesn't exist
  2. Policy exists but host can't be assigned due to already existing association

For the 2nd case we might want to add additional request to else block: systems/{ID}/policies?limit=100&ids_only=true and check if policy id is already there - then we return message "Policy already associated to host"
And if not - "Policy doesn't exist"

It's not cool to have another request for that but it will be beneficial for all of us + this request is easy one for backend.

Agreed with @LightOfHeaven1994 to add this change in a separate PR.

Copy link
Contributor

@LightOfHeaven1994 LightOfHeaven1994 left a comment

Choose a reason for hiding this comment

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

lgtm

@LightOfHeaven1994
Copy link
Contributor

@xiangce can you help us get it merged, please?

@xiangce xiangce merged commit a4e9afc into RedHatInsights:master May 20, 2025
16 checks passed
@romanblanco romanblanco deleted the reword-error-message branch May 20, 2025 07:29
xiangce pushed a commit that referenced this pull request Jun 5, 2025
When Compliance tries to assign Host to a Policy,
    it returns either 202 in case of success or 404 in any other case.

    When one tries to assign a Host that already has a Policy assigned,
    the Policy is not anymore in the list of available options,
    hence the process can not succeed with creating the link and returns 404.

    That in the logic of insights-client seems as failure, and it returns
    non-zero error status with the confusing message
    "Policy ... does not exist".

    This commit is to improve the message sent in such case to make it
    less misleading.

Signed-off-by: Roman Blanco <[email protected]>
(cherry picked from commit a4e9afc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants