Skip to content

Commit 552a759

Browse files
Matthias Dellwegnadjaheitmann
authored andcommitted
[PR] Fixes #25978 - debian errata support
Co-Authored-by: Markus Bucher <[email protected]> Co-Authored-by: Bernhard Suttner <[email protected]> Co-Authored-by: Manisha Singhal <[email protected]> from Katello#7961
1 parent 20f0ebc commit 552a759

File tree

55 files changed

+3643
-3491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3643
-3491
lines changed

app/controllers/katello/api/v2/repositories_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def custom_index_relation(collection)
6262
param :deb_releases, String, :desc => N_("whitespace-separated list of releases to be synced from deb-archive")
6363
param :deb_components, String, :desc => N_("whitespace-separated list of repo components to be synced from deb-archive")
6464
param :deb_architectures, String, :desc => N_("whitespace-separated list of architectures to be synced from deb-archive")
65+
param :deb_errata_url, String, :desc => N_("URL to a deb errata service (use only on the security repositories)")
6566
param :ignorable_content, Array, :desc => N_("List of content units to ignore while syncing a yum repository. Must be subset of %s") % RootRepository::IGNORABLE_CONTENT_UNIT_TYPES.join(",")
6667
param :ansible_collection_requirements, String, :desc => N_("Contents of requirement yaml file to sync from URL")
6768
param :ansible_collection_auth_url, String, :desc => N_("The URL to receive a session token from, e.g. used with Automation Hub.")
@@ -586,7 +587,7 @@ def repository_params
586587
keys = [:download_policy, :mirroring_policy, :sync_policy, :arch, :verify_ssl_on_sync, :upstream_password,
587588
:upstream_username, :download_concurrency, :upstream_authentication_token, :metadata_expire,
588589
{:os_versions => []}, :deb_releases, :deb_components, :deb_architectures, :description,
589-
:http_proxy_policy, :http_proxy_id, :retain_package_versions_count, {:ignorable_content => []}
590+
:http_proxy_policy, :http_proxy_id, :retain_package_versions_count, {:ignorable_content => []}, :deb_errata_url
590591
]
591592
keys += [{:include_tags => []}, {:exclude_tags => []}, :docker_upstream_name] if params[:action] == 'create' || @repository&.docker?
592593
keys += [:ansible_collection_requirements, :ansible_collection_auth_url, :ansible_collection_auth_token] if params[:action] == 'create' || @repository&.ansible_collection?
@@ -651,6 +652,7 @@ def construct_repo_from_params(repo_params) # rubocop:disable Metrics/AbcSize
651652
root.deb_releases = repo_params[:deb_releases] if repo_params[:deb_releases]
652653
root.deb_components = repo_params[:deb_components] if repo_params[:deb_components]
653654
root.deb_architectures = repo_params[:deb_architectures] if repo_params[:deb_architectures]
655+
root.deb_errata_url = repo_params[:deb_errata_url] if repo_params[:deb_errata_url]
654656
end
655657

656658
if root.ansible_collection?

app/lib/actions/katello/content_view/incremental_updates.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def total_counts(input)
104104
total_count[:errata_count] = added_units[:erratum].try(:count)
105105
total_count[:modulemd_count] = added_units[:modulemd].try(:count)
106106
total_count[:rpm_count] = added_units[:rpm].try(:count)
107+
total_count[:deb_count] = added_units[:deb].try(:count)
107108
end
108109
end
109110
end
@@ -147,6 +148,10 @@ def content_output_collection(total_count)
147148
rpm = _(" %{package_count} Package(s)" % {:package_count => total_count[:rpm_count]})
148149
content << rpm
149150
end
151+
if total_count[:deb_count] && total_count[:deb_count] > 0
152+
deb = _(" %{deb_package_count} Package(s)" % {:deb_package_count => total_count[:deb_count]})
153+
content << deb
154+
end
150155
content
151156
end
152157

app/lib/actions/katello/content_view/presenters/incremental_updates_presenter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class IncrementalUpdatesPresenter < Helpers::Presenter::Base
66
HUMANIZED_TYPES = {
77
::Katello::Erratum::CONTENT_TYPE => "Errata",
88
::Katello::ModuleStream::CONTENT_TYPE => "Module Streams",
9-
::Katello::Rpm::CONTENT_TYPE => "Packages"
9+
::Katello::Rpm::CONTENT_TYPE => "RPM Packages",
10+
::Katello::Deb::CONTENT_TYPE => "Deb Packages"
1011
}.freeze
1112

1213
def humanized_output
@@ -25,7 +26,7 @@ def humanized_content
2526
if cvv
2627
humanized_lines << "Content View: #{cvv.content_view.name} version #{cvv.version}"
2728
humanized_lines << _("Added Content:")
28-
[::Katello::Erratum, ::Katello::ModuleStream, ::Katello::Rpm].each do |content_type|
29+
[::Katello::Erratum, ::Katello::ModuleStream, ::Katello::Rpm, ::Katello::Deb].each do |content_type|
2930
unless output[:added_units][content_type::CONTENT_TYPE].blank?
3031
humanized_lines << " #{HUMANIZED_TYPES[content_type::CONTENT_TYPE]}:"
3132
humanized_lines += output[:added_units][content_type::CONTENT_TYPE].sort.map { |unit| " #{unit}" }

app/lib/actions/katello/content_view_version/incremental_update.rb

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Actions
22
module Katello
33
module ContentViewVersion
4-
class IncrementalUpdate < Actions::EntryAction
4+
class IncrementalUpdate < Actions::EntryAction # rubocop:disable Metrics/ClassLength
55
include ::Katello::ContentViewHelper
66
attr_accessor :new_content_view_version, :new_content_view_version_id
77

@@ -77,10 +77,21 @@ def plan(old_version, environments, options = {})
7777
[:pulp3_deb_multicopy, :pulp3_yum_multicopy].each do |mapping|
7878
if separated_repo_map[mapping].keys.flatten.present?
7979
extended_repo_mapping = pulp3_repo_mapping(separated_repo_map[mapping], old_version)
80-
unit_map = pulp3_content_mapping(content)
80+
local_content = {}
81+
if mapping == :pulp3_deb_multicopy
82+
local_content[:errata_ids], local_content[:deb_ids] = resolve_deb_errata(content, extended_repo_mapping)
83+
end
84+
85+
# makes sure that all keys in local_content are symbols!
86+
# content is of type ActionController::Parameters and uses string and symbol keys synonymically.
87+
# Hash (local_content) does not and we only access with symbol-keys, so make sure we only use symbols.
88+
local_content.keys.union(content.keys.map(&:to_sym)).each do |content_type|
89+
local_content[content_type] = local_content.fetch(content_type, []) + content.fetch(content_type, [])
90+
end
91+
unit_map = pulp3_content_mapping(local_content)
8192

82-
unless extended_repo_mapping.empty? || unit_map.values.flatten.empty?
83-
sequence do
93+
sequence do
94+
unless extended_repo_mapping.empty? || unit_map.values.flatten.empty?
8495
# Pre-copy content if dest_repo is a soft copy of its library instance.
8596
# Don't use extended_repo_mapping because the source repositories are library instances.
8697
# We want the old CV snapshot repositories here so as to not pull in excess new content.
@@ -101,6 +112,19 @@ def plan(old_version, environments, options = {})
101112
end
102113
end
103114
end
115+
116+
separated_repo_map[mapping].each do |_source_repos, dest_repo|
117+
next unless dest_repo.deb?
118+
119+
# find errata belonging to this repo
120+
errata = ::Katello::Erratum.with_identifiers(local_content[:errata_ids]).joins(:root_repositories).where(::Katello::RootRepository.table_name => {id: dest_repo.root}).distinct
121+
if errata.present?
122+
# attach deb errata to the dest_repo
123+
copy_action_outputs << plan_action(Actions::Katello::Repository::CopyDebErratum,
124+
target_repo_id: dest_repo.id,
125+
erratum_ids: errata.pluck(:errata_id)).output
126+
end
127+
end
104128
end
105129
end
106130
end
@@ -217,6 +241,36 @@ def components_repo_instances(old_version_repo, new_component_versions)
217241
end
218242
end
219243

244+
def resolve_deb_errata(content, extended_repo_mapping)
245+
needed_errata = []
246+
needed_debs = []
247+
content[:errata_ids].each do |erratum_id|
248+
extended_repo_mapping.each do |source_repos, _dest_repo|
249+
source_repos.each do |source_repo|
250+
re = ::Katello::RepositoryErratum.joins(:erratum).find_by(::Katello::Erratum.table_name => { errata_id: erratum_id }, repository_id: source_repo)
251+
252+
next if re.nil? # Erratum not in Repository
253+
254+
# find packages
255+
# FIXME: if multiple packages with the same name exist, we have to make sure we install the newest version
256+
# but (for now) at least a version bigger or equal the one from the erratum!
257+
pkgs = ::Katello::Deb.joins(repositories: { repository_errata: { erratum: :deb_packages }})
258+
.where("#{::Katello::Deb.table_name}.name = #{::Katello::ErratumDebPackage.table_name}.name AND deb_version_cmp(#{::Katello::Deb.table_name}.version,#{::Katello::ErratumDebPackage.table_name}.version) >=0")
259+
.where(::Katello::RepositoryErratum.table_name => { id: re })
260+
.distinct.pluck(:id)
261+
errata = ::Katello::Erratum.joins({ repositories: :debs }, :deb_packages)
262+
.where(::Katello::RepositoryErratum.table_name => { repository_id: source_repo })
263+
.where(::Katello::Deb.table_name => { id: pkgs })
264+
.where("#{::Katello::Deb.table_name}.name = #{::Katello::ErratumDebPackage.table_name}.name AND deb_version_cmp(#{::Katello::Deb.table_name}.version,#{::Katello::ErratumDebPackage.table_name}.version) >=0")
265+
.distinct.pluck(:errata_id)
266+
needed_errata.concat errata
267+
needed_debs.concat pkgs
268+
end
269+
end
270+
end
271+
return needed_errata, needed_debs
272+
end
273+
220274
def run
221275
content = { ::Katello::Erratum::CONTENT_TYPE => [],
222276
::Katello::Rpm::CONTENT_TYPE => [],
@@ -234,6 +288,7 @@ def run
234288
new_errata = new_repo.errata - (matched_old_repo&.errata || [])
235289
new_module_streams = new_repo.module_streams - (matched_old_repo&.module_streams || [])
236290
new_rpms = new_repo.rpms - (matched_old_repo&.rpms || [])
291+
new_debs = new_repo.debs - (matched_old_repo&.debs || [])
237292

238293
new_errata.each do |erratum|
239294
content[::Katello::Erratum::CONTENT_TYPE] << erratum.errata_id
@@ -245,6 +300,9 @@ def run
245300
new_rpms.each do |rpm|
246301
content[::Katello::Rpm::CONTENT_TYPE] << rpm.nvra
247302
end
303+
new_debs.each do |deb|
304+
content[::Katello::Deb::CONTENT_TYPE] << deb.nva
305+
end
248306
end
249307
end
250308
output[:added_units] = content
@@ -286,10 +344,11 @@ def calculate_components(old_version, new_components)
286344

287345
def generate_description(version, content)
288346
humanized_lines = []
289-
[::Katello::Erratum, ::Katello::Rpm].each do |content_type|
347+
[::Katello::Erratum, ::Katello::Rpm, ::Katello::Deb].each do |content_type|
290348
unless content[content_type::CONTENT_TYPE].blank?
291349
humanized_lines << "#{HUMANIZED_TYPES[content_type::CONTENT_TYPE]}:"
292-
humanized_lines += content[content_type::CONTENT_TYPE].sort.map { |unit| " #{unit}" }
350+
#FIXME: solves duplicate Deb-Errata displayed, here (might need deeper inspection)
351+
humanized_lines += content[content_type::CONTENT_TYPE].uniq.sort.map { |unit| " #{unit}" }
293352
end
294353
humanized_lines << ''
295354
end

app/lib/actions/katello/repository/clone_contents.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def plan(source_repositories, new_repository, options)
1818
SmartProxy.pulp_primary,
1919
source_repositories,
2020
filters: filters, rpm_filenames: rpm_filenames, solve_dependencies: solve_dependencies)
21+
22+
source_repositories.select(&:deb?).each do |repository|
23+
plan_action(Actions::Katello::Repository::CopyDebErratum,
24+
source_repo_id: repository.id,
25+
target_repo_id: new_repository.id,
26+
clean_target_errata: true)
27+
end
2128
end
2229

2330
matching_content = check_matching_content(new_repository, source_repositories)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module Actions
2+
module Katello
3+
module Repository
4+
class CopyDebErratum < Actions::Base
5+
input_format do
6+
param :source_repo_id
7+
param :target_repo_id
8+
param :erratum_ids
9+
param :clean_target_errata
10+
end
11+
12+
def run
13+
target_repo = ::Katello::Repository.find(input[:target_repo_id])
14+
15+
# drop all existing errata from target_repo (e.g. promoting LCENV back to an earlier version)
16+
target_repo.repository_errata.destroy_all if input[:clean_target_errata] == true
17+
18+
erratum_ids_to_copy = []
19+
if input[:source_repo_id].present?
20+
erratum_ids_to_copy = ::Katello::Repository.find(input[:source_repo_id])&.erratum_ids
21+
elsif input[:erratum_ids].present?
22+
erratum_ids_to_copy = ::Katello::Erratum.where(errata_id: input[:erratum_ids]).pluck(:id)
23+
end
24+
erratum_ids_to_copy -= target_repo.erratum_ids
25+
target_repo.erratum_ids |= erratum_ids_to_copy
26+
target_repo.save
27+
28+
# fake output to make foreman task presenter happy
29+
if input[:erratum_ids].present?
30+
units = []
31+
::Katello::Erratum.find(erratum_ids_to_copy).each do |erratum|
32+
units << { 'type_id' => 'erratum', 'unit_key' => { 'id' => erratum.pulp_id } }
33+
erratum.deb_packages.map do |pkg|
34+
units << { 'type_id' => 'deb', 'unit_key' => { 'name' => pkg.name, 'version' => pkg.version } }
35+
end
36+
end
37+
output[:pulp_tasks] = [{ :result => { :units_successful => units } }]
38+
end
39+
end
40+
end
41+
end
42+
end
43+
end

app/lib/actions/katello/repository/multi_clone_contents.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def plan(extended_repo_mapping, options)
2121
extended_repo_mapping.each do |source_repos, dest_repo_map|
2222
dest_repo_map[:matching_content] = check_matching_content(dest_repo_map[:dest_repo], source_repos)
2323

24+
if source_repos.first.deb?
25+
plan_action(Actions::Katello::Repository::CopyDebErratum,
26+
source_repo_id: source_repos.first.id,
27+
target_repo_id: dest_repo_map[:dest_repo].id)
28+
end
29+
2430
if generate_metadata
2531
metadata_generate(source_repos, dest_repo_map[:dest_repo], dest_repo_map[:filters], dest_repo_map[:matching_content])
2632
end

app/lib/actions/katello/repository/sync.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def plan(repo, options = {})
5151
plan_action(Katello::Foreman::ContentUpdate, repo.environment, repo.content_view, repo)
5252
plan_action(Katello::Repository::FetchPxeFiles, :id => repo.id)
5353
concurrence do
54+
plan_action(Katello::Repository::SyncDebErrata, repo, skip_metadata_check) if repo.deb? && repo.root.deb_errata_url.present?
5455
plan_action(Katello::Repository::ErrataMail, repo)
5556
plan_action(Actions::Katello::Applicability::Repository::Regenerate, :repo_ids => [repo.id]) if generate_applicability
5657
end

0 commit comments

Comments
 (0)