Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Api::V2::AlternateContentSourcesController < Api::V2::ApiController
param :description, String, desc: N_("Description for the alternate content source"), required: false
param :base_url, String, desc: N_('Base URL for finding alternate content'), required: false
param :subpaths, Array, desc: N_('Path suffixes for finding alternate content'), required: false
param :deb_releases, String, desc: N_('Debian releases/distributions (e.g., bookworm, bullseye)'), required: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
param :deb_releases, String, desc: N_('Debian releases/distributions (e.g., bookworm, bullseye)'), required: false
param :deb_releases, String, desc: N_('Debian releases/distributions (e.g., trixie, bookworm)'), required: false

suggestion to use latest two codenames as example.

param :deb_components, String, desc: N_('Debian components (e.g., main, contrib)'), required: false
param :deb_architectures, String, desc: N_('Debian architectures (e.g., amd64, arm64)'), required: false
param :smart_proxy_ids, Array, desc: N_("Ids of smart proxies to associate"), required: false
param :smart_proxy_names, Array, desc: N_("Names of smart proxies to associate"), required: false
param :upstream_username, String, desc: N_("Basic authentication username"), required: false
Expand Down Expand Up @@ -119,7 +122,8 @@ def acs_params
keys = [
:name, :label, :description, {smart_proxy_ids: []}, {smart_proxy_names: []}, :content_type,
:alternate_content_source_type, :use_http_proxies, :base_url, {subpaths: []}, :upstream_username,
:upstream_password, :ssl_ca_cert_id, :ssl_client_cert_id, :ssl_client_key_id, :verify_ssl, {product_ids: []}
:upstream_password, :ssl_ca_cert_id, :ssl_client_cert_id, :ssl_client_key_id, :verify_ssl, {product_ids: []},
:deb_releases, :deb_components, :deb_architectures
]

params.require(:alternate_content_source).permit(*keys).to_h.with_indifferent_access
Expand Down
19 changes: 18 additions & 1 deletion app/models/katello/alternate_content_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class AlternateContentSource < Katello::Model
self.table_name = :katello_alternate_content_sources

ACS_TYPES = %w(custom simplified rhui).freeze
CONTENT_TYPES = [::Katello::Repository::YUM_TYPE, ::Katello::Repository::FILE_TYPE].freeze
CONTENT_TYPES = [
::Katello::Repository::YUM_TYPE,
::Katello::Repository::FILE_TYPE,
::Katello::Repository::DEB_TYPE,
].freeze
AUDIT_REFRESH_ACTION = 'refresh'.freeze

encrypts :upstream_password
Expand All @@ -22,6 +26,7 @@ class AlternateContentSource < Katello::Model

validate :validate_ssl_ids
validate :validate_products
validate :deb_constraints

has_many :alternate_content_source_products, dependent: :delete_all, inverse_of: :alternate_content_source,
class_name: "Katello::AlternateContentSourceProduct"
Expand Down Expand Up @@ -94,6 +99,10 @@ def rhui?
alternate_content_source_type == 'rhui'
end

def deb?
content_type == ::Katello::Repository::DEB_TYPE
end

def self.with_products(products)
products = [products] unless products.is_a?(Array)
joins(:alternate_content_source_products).where('katello_alternate_content_source_products.product_id in (:product_ids)', product_ids: products.pluck(:id))
Expand Down Expand Up @@ -168,5 +177,13 @@ def validate_products
errors.add(:product_ids, "cannot be set for custom or rhui ACS")
end
end

def deb_constraints
return unless deb?

if custom? && deb_releases.to_s.strip.blank?
errors.add(:deb_releases, 'must be provided for deb alternate content sources')
end
end
end
end
20 changes: 20 additions & 0 deletions app/services/katello/pulp3/alternate_content_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def api
@api ||= ::Katello::Pulp3::Repository.api(smart_proxy, @acs.content_type)
end

def join_space_or_nil(value)
vals = Array(value).map(&:to_s).map(&:strip).reject(&:blank?)
vals.empty? ? nil : vals.join(' ')
end

def join_space_required!(field, value)
s = join_space_or_nil(value)
fail ::Katello::Errors::Pulp3Error, "Debian ACS requires '#{field}' to be a non-empty string" if s.nil?
s
end

def generate_backend_object_name
"#{acs.label}-#{smart_proxy.url}-#{rand(9999)}"
end
Expand Down Expand Up @@ -56,6 +67,11 @@ def remote_options
proxy_password: smart_proxy.http_proxy&.password,
total_timeout: Setting[:sync_connect_timeout],
}
if acs.deb?
remote_options[:distributions] = join_space_required!('deb_releases', acs.deb_releases)
remote_options[:components] = join_space_or_nil(acs.deb_components)
remote_options[:architectures] = join_space_or_nil(acs.deb_architectures)
end
if acs.content_type == ::Katello::Repository::FILE_TYPE && acs.subpaths.empty? && !remote_options[:url].end_with?('/PULP_MANIFEST')
remote_options[:url] = acs.base_url + '/PULP_MANIFEST'
end
Expand All @@ -68,6 +84,10 @@ def remote_options
remote_options.merge!(ssl_remote_options)
end

def remove_options
{ proxy_url: nil, proxy_username: nil, proxy_password: nil }
end

def ssl_remote_options
if acs.custom? || acs.rhui?
{
Expand Down
8 changes: 8 additions & 0 deletions app/services/katello/pulp3/api/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def copy_api
def content_release_components_api
PulpDebClient::ContentReleaseComponentsApi.new(api_client)
end

def self.alternate_content_source_class
PulpDebClient::DebAptAlternateContentSource
end

def alternate_content_source_api
PulpDebClient::AcsDebApi.new(api_client)
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions app/services/katello/pulp3/smart_proxy_mirror_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ def delete_orphan_alternate_content_sources
tasks << yum_acs_api.delete(orphan_yum_acs_href)
end
end
if RepositoryTypeManager.enabled_repository_types['deb']
deb_acs_api = ::Katello::Pulp3::Repository.api(smart_proxy, 'deb').alternate_content_source_api
orphan_deb_acs_hrefs = deb_acs_api.list.results.map(&:pulp_href) - known_acs_hrefs
orphan_deb_acs_hrefs.each do |orphan_deb_acs_href|
tasks << deb_acs_api.delete(orphan_deb_acs_href)
end
end
end

def delete_orphan_remotes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends 'katello/api/v2/common/identifier'

if @object.respond_to?(:alternate_content_source_type)
if @object.custom? || @object.rhui?
attributes :name, :alternate_content_source_type, :content_type, :base_url, :subpaths, :upstream_username, :smart_proxies, :verify_ssl, :use_http_proxies
attributes :name, :alternate_content_source_type, :content_type, :base_url, :subpaths, :deb_releases, :deb_components, :deb_architectures, :upstream_username, :smart_proxies, :verify_ssl, :use_http_proxies
child :ssl_ca_cert => :ssl_ca_cert do |_object|
attributes :id, :name
end
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20251110000001_add_deb_fields_to_acs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddDebFieldsToAcs < ActiveRecord::Migration[7.0]
def change
add_column :katello_alternate_content_sources, :deb_releases, :string
add_column :katello_alternate_content_sources, :deb_components, :string
add_column :katello_alternate_content_sources, :deb_architectures, :string
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ def setup
@primary = SmartProxy.pulp_primary
@yum_acs = katello_alternate_content_sources(:yum_alternate_content_source)
@file_acs = katello_alternate_content_sources(:file_alternate_content_source)
@deb_acs = katello_alternate_content_sources(:deb_alternate_content_source)
@yum_acs.save!
@file_acs.save!
@deb_acs.save!
end

def teardown
Expand All @@ -24,6 +26,12 @@ def teardown
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end
@file_acs.reload

@deb_acs.smart_proxy_alternate_content_sources.each do |smart_proxy_acs|
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end
@deb_acs.reload
end

def test_yum_create
Expand Down Expand Up @@ -52,6 +60,15 @@ def test_file_create
assert_match(/^prn:file\.filealternatecontentsource:[0-9a-f\-]+$/, @file_acs.smart_proxy_alternate_content_sources.first.alternate_content_source_prn)
end

def test_deb_create
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@deb_acs.name)
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @deb_acs.id, smart_proxy_id: @primary.id)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
assert_equal 1, @deb_acs.smart_proxy_alternate_content_sources.count
assert @deb_acs.smart_proxy_alternate_content_sources.first.remote_href.start_with?('/pulp/api/v3/remotes/deb/apt/')
assert @deb_acs.smart_proxy_alternate_content_sources.first.alternate_content_source_href.start_with?('/pulp/api/v3/acs/deb/deb/')
end

def test_yum_create_complex
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@yum_acs.name)
ca = katello_gpg_keys(:real_ca)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ def setup
@primary = SmartProxy.pulp_primary
@yum_acs = katello_alternate_content_sources(:yum_alternate_content_source)
@file_acs = katello_alternate_content_sources(:file_alternate_content_source)
@deb_acs = katello_alternate_content_sources(:deb_alternate_content_source)
@yum_acs.save!
@file_acs.save!
@deb_acs.save!
end

def teardown
Expand All @@ -24,6 +26,12 @@ def teardown
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end
@file_acs.reload

@deb_acs.smart_proxy_alternate_content_sources.each do |smart_proxy_acs|
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end
@deb_acs.reload
end

def test_yum_delete
Expand All @@ -41,5 +49,13 @@ def test_file_delete
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
assert_equal 0, @file_acs.smart_proxy_alternate_content_sources.count
end

def test_deb_delete
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@deb_acs.name)
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @deb_acs.id, smart_proxy_id: @primary.id)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
assert_equal 0, @deb_acs.smart_proxy_alternate_content_sources.count
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ def setup
@file_acs.ssl_client_key_id = nil
@file_acs.upstream_username = nil
@file_acs.upstream_password = nil
@deb_acs = katello_alternate_content_sources(:deb_alternate_content_source)
@deb_acs.subpaths = []
@deb_acs.deb_releases = 'ragnarok'
@deb_acs.deb_components = ''
@deb_acs.deb_architectures = ''
@deb_acs.ssl_ca_cert_id = nil
@deb_acs.ssl_client_cert_id = nil
@deb_acs.ssl_client_key_id = nil
@deb_acs.upstream_username = nil
@deb_acs.upstream_password = nil
@yum_acs.save!
@file_acs.save!
@deb_acs.save!
@yum_simplified_acs = katello_alternate_content_sources(:yum_simplified_alternate_content_source)
@file_simplified_acs = katello_alternate_content_sources(:file_simplified_alternate_content_source)
::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @yum_acs.id, smart_proxy_id: @primary.id)
Expand All @@ -38,6 +49,11 @@ def teardown
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end

@deb_acs.smart_proxy_alternate_content_sources.where.not(remote_href: nil).sort_by(&:remote_href).each do |smart_proxy_acs|
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end

@yum_simplified_acs.smart_proxy_alternate_content_sources.where.not(remote_href: nil).sort_by(&:remote_href).each do |smart_proxy_acs|
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
Expand Down Expand Up @@ -91,5 +107,22 @@ def test_file_refresh
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Refresh, smart_proxy_acs)
end

def test_deb_refresh
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@deb_acs.name)
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @deb_acs.id, smart_proxy_id: @primary.id)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Refresh, smart_proxy_acs)
end

def test_deb_refresh_updates_remote
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@deb_acs.name)
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @deb_acs.id, smart_proxy_id: @primary.id)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
@deb_acs.update!(verify_ssl: false)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Refresh, smart_proxy_acs)
new_verify_ssl = smart_proxy_acs.backend_service.api.remotes_list(name: @deb_acs.name).first.tls_validation
assert_equal new_verify_ssl, @deb_acs.verify_ssl
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def setup
@repository = katello_repositories(:rhel_6_x86_64)
@yum_acs = katello_alternate_content_sources(:yum_alternate_content_source)
@file_acs = katello_alternate_content_sources(:file_alternate_content_source)
@deb_acs = katello_alternate_content_sources(:deb_alternate_content_source)
@simplified_acs = katello_alternate_content_sources(:yum_simplified_alternate_content_source)
@simplified_acs.products << @repository.product
@rhui_acs = katello_alternate_content_sources(:yum_alternate_content_source_rhui)
@yum_acs.save!
@file_acs.save!
@deb_acs.save!
@simplified_acs.save!
@rhui_acs.save!
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:test_remote_name).returns('test-remote')
Expand All @@ -33,6 +35,11 @@ def teardown
end
@file_acs.reload

@deb_acs.smart_proxy_alternate_content_sources.each do |smart_proxy_acs|
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
end

@simplified_acs.smart_proxy_alternate_content_sources.each do |smart_proxy_acs|
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs)
Expand Down Expand Up @@ -72,6 +79,18 @@ def test_file_update
assert_equal @file_acs.subpaths.collect { |s| s + '/PULP_MANIFEST' }.sort, pulp_acs.paths.sort
end

def test_deb_update
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@deb_acs.name)
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @deb_acs.id, smart_proxy_id: @primary.id)
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs)
@deb_acs.update(base_url: 'https://fixtures.pulpproject.org/debian/', deb_releases: 'ragnarok ginnungagap')
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::AlternateContentSource::Update, smart_proxy_acs)

pulp_remote = @deb_acs.backend_service(@primary).get_remote
assert_equal @deb_acs.base_url, pulp_remote.url
assert_equal 'ragnarok ginnungagap', pulp_remote.distributions
end

def test_file_update_no_subpaths
::Katello::Pulp3::AlternateContentSource.any_instance.stubs(:generate_backend_object_name).returns(@file_acs.name)
smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @file_acs.id, smart_proxy_id: @primary.id)
Expand Down Expand Up @@ -155,5 +174,25 @@ def test_http_proxy_url_update_simplified_acs
assert_nil remote_options[:proxy_username]
assert_nil remote_options[:proxy_password]
end

def test_http_proxy_url_update_deb_acs
proxy = FactoryBot.create(:http_proxy)
proxy.update!(url: "https://test_url", username: "foo", password: "bar")

@deb_acs.update!(use_http_proxies: true)
::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: @deb_acs.id, smart_proxy_id: @primary.id)
@deb_acs.smart_proxy_alternate_content_sources.first.backend_service.smart_proxy.update!(http_proxy_id: proxy.id)

remote_options = @deb_acs.smart_proxy_alternate_content_sources.first.backend_service.remote_options
assert_equal proxy.url, remote_options[:proxy_url]
assert_equal proxy.username, remote_options[:proxy_username]
assert_equal proxy.password, remote_options[:proxy_password]

@deb_acs.update(use_http_proxies: false)
remote_options = @deb_acs.smart_proxy_alternate_content_sources.first.backend_service.remote_options
assert_nil remote_options[:proxy_url]
assert_nil remote_options[:proxy_username]
assert_nil remote_options[:proxy_password]
end
end
end
Loading
Loading