Skip to content

Commit

Permalink
Fixes #38040 - Clear retain_package_version_count when mirroring poli…
Browse files Browse the repository at this point in the history
…cy is not additive
  • Loading branch information
sjha4 committed Jan 22, 2025
1 parent c988a00 commit 0887e64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/katello/api/v2/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ def update
end
end

if @repository.yum? && repo_params[:mirroring_policy] != ::Katello::RootRepository::MIRRORING_POLICY_ADDITIVE
repo_params[:retain_package_versions_count] = nil
end
sync_task(::Actions::Katello::Repository::Update, @repository.root, repo_params)
respond_for_show(:resource => @repository)
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/katello/root_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def ensure_valid_retain_package_versions_count
unless yum?
errors.add(:retain_package_versions_count, N_("is only allowed for Yum repositories."))
end
if yum? && self.mirroring_policy != MIRRORING_POLICY_ADDITIVE
errors.add(:retain_package_versions_count, N_("cannot be set for repositories without 'Additive' mirroring policy."))
end
if self.retain_package_versions_count.to_i < 0
errors.add(:retain_package_versions_count, N_("must not be a negative value."))
end
Expand Down
7 changes: 7 additions & 0 deletions test/models/root_repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_invalid_retain_package_version_counts
@root.content_type = 'yum'
@root.url = 'http://inecas.fedorapeople.org/fakerepos/zoo2/'
@root.retain_package_versions_count = -2
@root.mirroring_policy = 'additive'
assert_not_valid @root
assert_equal @root.errors[:retain_package_versions_count], ["must not be a negative value."]
end
Expand All @@ -67,6 +68,7 @@ def test_valid_retain_package_version_counts
@root.content_type = 'yum'
@root.url = 'http://inecas.fedorapeople.org/fakerepos/zoo2/'
@root.retain_package_versions_count = 2
@root.mirroring_policy = 'additive'
assert_valid @root
end

Expand Down Expand Up @@ -582,7 +584,12 @@ def test_yum_retain_package_versions_count
assert @root.valid?

@root.retain_package_versions_count = 2
@root.mirroring_policy = 'additive'
assert @root.valid?

@root.mirroring_policy = 'mirror_content_only'
refute @root.valid?
assert_equal @root.errors[:retain_package_versions_count], ["cannot be set for repositories without 'Additive' mirroring policy."]
end

def test_sha1_checksum_removed
Expand Down

0 comments on commit 0887e64

Please sign in to comment.