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

Fixes #38040 - Clear retain_version_count when mirroring policy is not additive #11285

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

sjha4
Copy link
Member

@sjha4 sjha4 commented Jan 22, 2025

What are the changes introduced in this pull request?

  1. On the API, clear out retain_package_versions_count when mirroring policy is anything other than additive
  2. Add a validation on root model to make sure retain_package_versions_count is only set when mirroring policy is additive.

Considerations taken when implementing this change?

What are the testing steps for this pull request?

  1. Create a yum repo with some retain_package_versions_count and mirroring policy as Additive
  2. Sync
  3. Now update mirroring policy to Content only/Complete and sync again.
  4. You'll see an error.
  5. In console if you check repo.root.retain_package_versions_count it will still have the value from step 1

With this change,
In step 4 you'll not see the sync error
In console if you check repo.root.retain_package_versions_count you'll see nil

We can also test the validation by doing so in console:

repo.root.mirroring_policy = "mirror_complete"
repo.root.retain_package_versions_count = 3
repo.root.valid? # false
repo.root.errors.messages # {:retain_package_versions_count=>["cannot be set for repos without 'Additive' mirroring policy."]}

@sjha4 sjha4 force-pushed the mirror_complete branch 2 times, most recently from 0887e64 to 877c7cc Compare January 23, 2025 18:19
Copy link
Contributor

@qcjames53 qcjames53 left a comment

Choose a reason for hiding this comment

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

I have confirmed that errors are thrown appropriately when changing the mirroring policy to an invalid option in the UI, hammer, API, and in the rails console. The validation works for both setting an invalid mirroring policy with a versions count set and for setting a versions count with an invalid mirroring policy set. The logic looks okay to me and I'm happy with the test case changes. I had one nitpick on line length; once that's fixed feel free to merge!

ACKed.

@@ -403,6 +403,9 @@ def update
end
end

if @repository.yum? && !(repo_params[:mirroring_policy] == ::Katello::RootRepository::MIRRORING_POLICY_ADDITIVE || @repository.root.mirroring_policy == ::Katello::RootRepository::MIRRORING_POLICY_ADDITIVE)
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is REALLY long. Would you mind splitting it up?

Copy link
Member Author

Choose a reason for hiding this comment

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

@qcjames53 : Updated for readability..

@qcjames53 qcjames53 merged commit 06452b5 into Katello:master Jan 27, 2025
19 checks passed
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.

2 participants