app/services/katello/pulp3/repository/yum.rb in katello-3.16.0 vs app/services/katello/pulp3/repository/yum.rb in katello-3.16.1
- old
+ new
@@ -1,14 +1,17 @@
require 'pulp_rpm_client'
module Katello
module Pulp3
class Repository
+ # rubocop:disable Metrics/ClassLength
class Yum < ::Katello::Pulp3::Repository
include Katello::Util::Errata
include Katello::Util::PulpcoreContentFilters
+ UNIT_LIMIT = 10_000
+
def remote_options
if root.url.blank?
common_remote_options.merge(url: nil, policy: root.download_policy)
else
common_remote_options.merge(policy: root.download_policy)
@@ -29,14 +32,10 @@
publication: repo.publication_href,
name: "#{generate_backend_object_name}"
}
end
- def sync_params
- {remote: repo.remote_href, mirror: repo.root.mirror_on_sync, optimize: false}
- end
-
def mirror_remote_options
policy = smart_proxy.download_policy
if smart_proxy.download_policy == SmartProxy::DOWNLOAD_INHERIT
policy = repo.root.download_policy
@@ -61,10 +60,16 @@
end
end
end
end
+ def sync_url_params(sync_options)
+ params = super
+ params[:optimize] = sync_options[:optimize] if sync_options.key?(:optimize)
+ params
+ end
+
def self.distribution_bootable?(distribution)
file_paths = distribution.results.first.images.map(&:path)
file_paths.any? do |path|
path.include?('vmlinuz') || path.include?('pxeboot') || path.include?('kernel.img') || path.include?('initrd.img') || path.include?('boot.iso')
end
@@ -100,18 +105,75 @@
config = { source_repo_version: source_repo_version, dest_repo: dest_repo_href, content: content_unit_hrefs }
config[:dest_base_version] = dest_repo_id_map[:base_version] if dest_repo_id_map[:base_version]
data.config << config
end
end
- # FIXME: data's content being [] causes all content to be copied back
- tasks << api.copy_api.copy_content(data)
+ tasks << copy_content_chunked(data)
else
tasks << remove_all_content_from_mapping(repo_id_map)
end
tasks.flatten
end
+ def copy_api_data_dup(data)
+ data_dup = PulpRpmClient::Copy.new
+ data_dup.dependency_solving = data.dependency_solving
+ data_dup.config = []
+ data.config.each do |repo_config|
+ config_hash = {
+ source_repo_version: repo_config[:source_repo_version],
+ dest_repo: repo_config[:dest_repo],
+ content: []
+ }
+ config_hash[:dest_base_version] = repo_config[:dest_base_version] if repo_config[:dest_base_version]
+ data_dup.config << config_hash
+ end
+ data_dup
+ end
+
+ def copy_content_chunked(data)
+ tasks = []
+ # Don't chunk if there aren't enough content units
+ if data.config.sum { |repo_config| repo_config[:content].size } <= UNIT_LIMIT
+ return api.copy_api.copy_content(data)
+ end
+
+ unit_copy_counter = 0
+ i = 0
+ leftover_units = data.config.first[:content].deep_dup
+
+ # Copy data and clear its content fields
+ data_dup = copy_api_data_dup(data)
+
+ while i < data_dup.config.size
+ # Copy all units within repo or only some?
+ if leftover_units.length < UNIT_LIMIT - unit_copy_counter
+ copy_amount = leftover_units.length
+ else
+ copy_amount = UNIT_LIMIT - unit_copy_counter
+ end
+
+ data_dup.config[i][:content] = leftover_units.pop(copy_amount)
+ unit_copy_counter += copy_amount
+ # Do copy call if limit is reached or if we're under the limit but on the last repo config.
+ if unit_copy_counter >= UNIT_LIMIT || (i == data_dup.config.size - 1 && leftover_units.empty?)
+ tasks << api.copy_api.copy_content(data_dup)
+ unit_copy_counter = 0
+ end
+
+ if leftover_units.empty?
+ # Nothing more to copy -- clear current config's content
+ data_dup.config[i][:content] = []
+ i += 1
+ # Fetch unit list for next data config
+ leftover_units = data.config[i][:content].deep_dup unless i == data_dup.config.size
+ end
+ end
+
+ tasks
+ end
+
def remove_all_content_from_mapping(repo_id_map)
tasks = []
repo_id_map.each do |_source_repo_ids, dest_repo_id_map|
dest_repo = ::Katello::Repository.find(dest_repo_id_map[:dest_repo])
dest_repo_href = ::Katello::Pulp3::Repository::Yum.new(dest_repo, SmartProxy.pulp_master).repository_reference.repository_href
@@ -143,9 +205,14 @@
def remove_all_content_from_repo(repo_href)
data = PulpRpmClient::RepositoryAddRemoveContent.new(
remove_content_units: ['*'])
api.repositories_api.modify(repo_href, data)
+ end
+
+ def repair(repository_version_href)
+ data = PulpRpmClient::RepositoryVersion.new
+ api.repository_versions_api.repair(repository_version_href, data)
end
def remove_all_content
data = PulpRpmClient::RepositoryAddRemoveContent.new(
remove_content_units: ['*'])