Skip to content

Commit

Permalink
Fixes #31257 - support incremental update for debs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Jan 12, 2024
1 parent ae7ee10 commit 0e2b9cc
Show file tree
Hide file tree
Showing 12 changed files with 958 additions and 57 deletions.
4 changes: 3 additions & 1 deletion app/helpers/katello/content_view_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module Katello
module ContentViewHelper
def separated_repo_mapping(repo_mapping, use_multicopy_actions)
separated_mapping = { :pulp3_yum_multicopy => {}, :other => {} }
separated_mapping = { :pulp3_deb_multicopy => {}, :pulp3_yum_multicopy => {}, :other => {} }
repo_mapping.each do |source_repos, dest_repo|
if dest_repo.content_type == "yum" && SmartProxy.pulp_primary.pulp3_support?(dest_repo) && use_multicopy_actions
separated_mapping[:pulp3_yum_multicopy][source_repos] = dest_repo
elsif dest_repo.content_type == "deb" && SmartProxy.pulp_primary.pulp3_support?(dest_repo) && use_multicopy_actions
separated_mapping[:pulp3_deb_multicopy][source_repos] = dest_repo
else
separated_mapping[:other][source_repos] = dest_repo
end
Expand Down
2 changes: 2 additions & 0 deletions app/lib/actions/katello/content_view/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def plan(content_view, description = "", options = {importing: false, syncable:

if options[:importing]
handle_import(version, options.slice(:path, :metadata))
elsif separated_repo_map[:pulp3_deb_multicopy].keys.flatten.present?
plan_action(Repository::MultiCloneToVersion, separated_repo_map[:pulp3_deb_multicopy], version)
elsif separated_repo_map[:pulp3_yum_multicopy].keys.flatten.present?
plan_action(Repository::MultiCloneToVersion, separated_repo_map[:pulp3_yum_multicopy], version)
end
Expand Down
49 changes: 27 additions & 22 deletions app/lib/actions/katello/content_view_version/incremental_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,31 @@ def plan(old_version, environments, options = {})
end

concurrence do
if separated_repo_map[:pulp3_yum_multicopy].keys.flatten.present?
extended_repo_mapping = pulp3_repo_mapping(separated_repo_map[:pulp3_yum_multicopy], old_version)
unit_map = pulp3_content_mapping(content)

unless extended_repo_mapping.empty? || unit_map.values.flatten.empty?
sequence do
# Pre-copy content if dest_repo is a soft copy of its library instance.
# Don't use extended_repo_mapping because the source repositories are library instances.
# We want the old CV snapshot repositories here so as to not pull in excess new content.
separated_repo_map[:pulp3_yum_multicopy].each do |source_repos, dest_repo|
if dest_repo.soft_copy_of_library?
source_repos.each do |source_repo|
# remove_all flag is set to cover the case of incrementally updating more than once with different content.
# Without it, content from the previous incremental update will be copied as well due to how Pulp repo versions work.
plan_action(Pulp3::Repository::CopyContent, source_repo, SmartProxy.pulp_primary, dest_repo, copy_all: true, remove_all: true)
[:pulp3_deb_multicopy, :pulp3_yum_multicopy].each do |mapping|
if separated_repo_map[mapping].keys.flatten.present?
extended_repo_mapping = pulp3_repo_mapping(separated_repo_map[mapping], old_version)
unit_map = pulp3_content_mapping(content)

unless extended_repo_mapping.empty? || unit_map.values.flatten.empty?
sequence do
# Pre-copy content if dest_repo is a soft copy of its library instance.
# Don't use extended_repo_mapping because the source repositories are library instances.
# We want the old CV snapshot repositories here so as to not pull in excess new content.
separated_repo_map[mapping].each do |source_repos, dest_repo|
if dest_repo.soft_copy_of_library?
source_repos.each do |source_repo|
# remove_all flag is set to cover the case of incrementally updating more than once with different content.
# Without it, content from the previous incremental update will be copied as well due to how Pulp repo versions work.
plan_action(Pulp3::Repository::CopyContent, source_repo, SmartProxy.pulp_primary, dest_repo, copy_all: true, remove_all: true)
end
end
end
end
copy_action_outputs << plan_action(Pulp3::Repository::MultiCopyUnits, extended_repo_mapping, unit_map,
dependency_solving: dep_solve).output
repos_to_clone.each do |source_repos|
if separated_repo_map[:pulp3_yum_multicopy].keys.include?(source_repos)
copy_repos(repository_mapping[source_repos])
copy_action_outputs << plan_action(Pulp3::Repository::MultiCopyUnits, extended_repo_mapping, unit_map,
dependency_solving: dep_solve).output
repos_to_clone.each do |source_repos|
if separated_repo_map[mapping].keys.include?(source_repos)
copy_repos(repository_mapping[source_repos])
end
end
end
end
Expand Down Expand Up @@ -124,11 +126,14 @@ def plan(old_version, environments, options = {})

def pulp3_content_mapping(content)
units = ::Katello::Erratum.with_identifiers(content[:errata_ids]) +
::Katello::Deb.with_identifiers(content[:deb_ids]) +
::Katello::Rpm.with_identifiers(content[:package_ids])
unit_map = { :errata => [], :rpms => [] }
unit_map = { :errata => [], :debs => [], :rpms => [] }
units.each do |unit|
if unit.class.name == "Katello::Erratum"
unit_map[:errata] << unit.id
elsif unit.class.name == "Katello::Deb"
unit_map[:debs] << unit.id
elsif unit.class.name == "Katello::Rpm"
unit_map[:rpms] << unit.id
end
Expand Down
4 changes: 4 additions & 0 deletions app/lib/actions/pulp3/repository/multi_copy_units.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def invoke_external_task
katello_errata.id in (#{input[:unit_map][:errata].join(",")})").map(&:erratum_pulp3_href)
end

if input[:unit_map][:debs].any?
unit_hrefs << ::Katello::Deb.where(:id => input[:unit_map][:debs]).map(&:pulp_id)
end

if input[:unit_map][:rpms].any?
unit_hrefs << ::Katello::Rpm.where(:id => input[:unit_map][:rpms]).map(&:pulp_id)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/katello/pulp3/api/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.add_remove_content_class
end

def copy_api
PulpDebClient::CopyApi.new(api_client)
PulpDebClient::DebCopyApi.new(api_client)
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion app/services/katello/pulp3/repository/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ def multi_copy_units(repo_id_map, dependency_solving)
dest_repo_href = ::Katello::Pulp3::Repository::Apt.new(dest_repo, SmartProxy.pulp_primary).repository_reference.repository_href
content_unit_hrefs = dest_repo_id_map[:content_unit_hrefs]
# Not needed during incremental update due to dest_base_version
# -> Unless incrementally updating a CV repo that is a soft copy of its library instance.
# -> I.e. no filters and not an incremental version.
unless dest_repo_id_map[:base_version]
# Don't perform extra content actions if the repo is a soft copy of its library instance.
# Taken care of by the IncrementalUpdate action.
unless dest_repo.soft_copy_of_library?
tasks << remove_all_content_from_repo(dest_repo_href)
end
end
source_repo_ids.each do |source_repo_id|
source_repo_version = ::Katello::Repository.find(source_repo_id).version_href
config = { source_repo_version: source_repo_version, dest_repo: dest_repo_href, content: content_unit_hrefs }
Expand Down Expand Up @@ -233,7 +242,8 @@ def copy_units(content_unit_hrefs, remove_all)
tasks << add_content(slice, first_slice)
first_slice = false
end
else
# If we're merging composite cv repositories, don't clear out the Pulp repository.
elsif remove_all
tasks << remove_all_content
end
tasks
Expand Down
4 changes: 2 additions & 2 deletions test/actions/katello/content_view_version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def pulp3_cvv_setup
pulp3_repo_map[[library_repo.id]] = { :dest_repo => new_repo.id, :base_version => nil }
assert_action_planned_with(action, ::Actions::Pulp3::Repository::MultiCopyUnits,
pulp3_repo_map,
{ :errata => [], :rpms => [old_rpm.id] },
{ :debs => [], :errata => [], :rpms => [old_rpm.id] },
:dependency_solving => false)
assert_action_planned_with(action, ::Actions::Pulp3::Repository::CopyContent, library_repo, SmartProxy.pulp_primary, new_repo, copy_all: true, remove_all: true)
assert_action_planned_with(action, ::Actions::Katello::Repository::MetadataGenerate, new_repo)
Expand All @@ -103,7 +103,7 @@ def pulp3_cvv_setup
pulp3_repo_map[[library_repo.id]] = { :dest_repo => new_repo.id, :base_version => 1 }
assert_action_planned_with(action, ::Actions::Pulp3::Repository::MultiCopyUnits,
pulp3_repo_map,
{ :errata => [], :rpms => [old_rpm.id] },
{ :debs => [], :errata => [], :rpms => [old_rpm.id] },
:dependency_solving => true)
refute_action_planned(action, ::Actions::Pulp3::Repository::CopyContent)
end
Expand Down
Loading

0 comments on commit 0e2b9cc

Please sign in to comment.