app/lib/actions/katello/repository/update.rb in katello-4.8.4 vs app/lib/actions/katello/repository/update.rb in katello-4.9.0.rc1
- old
+ new
@@ -1,5 +1,7 @@
+require 'set'
+
module Actions
module Katello
module Repository
class Update < Actions::EntryAction
# rubocop:disable Metrics/MethodLength
@@ -27,11 +29,12 @@
:content_url => root.custom_content_path,
:gpg_key_url => repository.yum_gpg_key_url,
:label => content.label,
:type => root.content_type,
:arches => root.format_arches,
- :os_versions => root.os_versions&.join(',')
+ :os_versions => root.os_versions&.join(','),
+ :metadata_expire => root.metadata_expire
)
content.update!(name: root.name,
content_url: root.custom_content_path,
content_type: repository.content_type,
@@ -71,15 +74,34 @@
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id, repository_id: repository.id)
plan_action(Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
end
end
elsif delete_acs
+ handle_acs_product_removal(repository)
repository.smart_proxy_alternate_content_sources.each do |smart_proxy_acs|
plan_action(Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs, old_url: old_url)
end
else
repository.smart_proxy_alternate_content_sources.each do |smart_proxy_acs|
plan_action(Pulp3::Orchestration::AlternateContentSource::Update, smart_proxy_acs)
+ end
+ end
+ end
+
+ def handle_acs_product_removal(repository)
+ # Remove products from ACS's that contain no repositories which both
+ # match the ACS content type and have a non-nil URL
+ product = repository.product
+ repo_content_types = Set.new
+ product.repositories.each do |test_repo|
+ # we need to check id because test_repo will still contain the old, non-nil url
+ repo_content_types.add(test_repo.content_type) if (repository.id != test_repo.id) && test_repo.url.present?
+ end
+ ::Katello::AlternateContentSource.with_products(product).each do |acs|
+ unless repo_content_types.include?(acs.content_type)
+ acs.products = acs.products - [product]
+ Rails.logger.info _('Removing product %{prod_name} with ID %{prod_id} from ACS %{acs_name} with ID %{acs_id}') %
+ { prod_name: product.name, prod_id: product.id, acs_name: acs.name, acs_id: acs.id }
end
end
end
def update_content?(repository)