Revision 97f8a09c
Added by Quirin Pamp 26 days ago
app/services/katello/pulp3/alternate_content_source.rb | ||
---|---|---|
end
|
||
|
||
def get_remote(href = smart_proxy_acs.remote_href)
|
||
acs.base_url&.start_with?('uln') ? api.remotes_uln_api.read(href) : api.remotes_api.read(href)
|
||
api.get_remotes_api(href: href).read(href)
|
||
end
|
||
|
||
def update_remote
|
||
api.remotes_api.partial_update(smart_proxy_acs.remote_href, remote_options)
|
||
def update_remote(href = smart_proxy_acs.remote_href)
|
||
api.get_remotes_api(href: href).partial_update(href, remote_options)
|
||
end
|
||
|
||
# The old repo URL is needed to determine which remote API to use.
|
||
def delete_remote(options = {})
|
||
options[:href] ||= smart_proxy_acs.remote_href
|
||
options[:old_url] ||= remote_options[:url]
|
||
ignore_404_exception { options[:old_url]&.start_with?('uln') ? api.remotes_uln_api.delete(options[:href]) : api.remotes_api.delete(options[:href]) } if options[:href]
|
||
ignore_404_exception { api.get_remotes_api(href: options[:href]).delete(options[:href]) } if options[:href]
|
||
end
|
||
|
||
def create
|
app/services/katello/pulp3/api/core.rb | ||
---|---|---|
fail NotImplementedError
|
||
end
|
||
|
||
# Method is called with either :url or :href parameters for the sake of yum content.
|
||
def get_remotes_api(*)
|
||
remotes_api
|
||
end
|
||
|
||
def publications_api
|
||
repository_type.publications_api_class.new(api_client) #Optional
|
||
end
|
app/services/katello/pulp3/api/yum.rb | ||
---|---|---|
PulpRpmClient::RemotesUlnApi.new(api_client)
|
||
end
|
||
|
||
def get_remotes_api(href: nil, url: nil)
|
||
fail 'Provide exactly one of href or url for yum remote selection!' if url.blank? && href.blank?
|
||
fail 'The href must be a pulp_rpm remote href!' if href && !href.start_with?('/pulp/api/v3/remotes/rpm/')
|
||
|
||
if href&.start_with?('/pulp/api/v3/remotes/rpm/uln/') || url&.start_with?('uln')
|
||
remotes_uln_api
|
||
else
|
||
remotes_api
|
||
end
|
||
end
|
||
|
||
def copy_api
|
||
PulpRpmClient::RpmCopyApi.new(api_client)
|
||
end
|
app/services/katello/pulp3/repository.rb | ||
---|---|---|
end
|
||
|
||
def remote_partial_update
|
||
if remote_options[:url]&.start_with?('uln')
|
||
api.remotes_uln_api.partial_update(repo.remote_href, remote_options)
|
||
else
|
||
api.remotes_api.partial_update(repo.remote_href, remote_options)
|
||
url_type = remote_options[:url]&.start_with?('uln') ? 'uln' : 'default'
|
||
remote_type = repo.remote_href.start_with?('/pulp/api/v3/remotes/rpm/uln/') ? 'uln' : 'default'
|
||
href = repo.remote_href
|
||
|
||
if url_type == remote_type
|
||
api.get_remotes_api(href: href).partial_update(href, remote_options)
|
||
else # We need to recreate a remote of the correct type!
|
||
create_remote
|
||
delete_remote(href: href)
|
||
end
|
||
end
|
||
|
||
def delete_remote(options = {})
|
||
options[:href] ||= repo.remote_href
|
||
ignore_404_exception { remote_options[:url]&.start_with?('uln') ? api.remotes_uln_api.delete(options[:href]) : api.remotes_api.delete(options[:href]) } if options[:href]
|
||
ignore_404_exception { api.get_remotes_api(href: options[:href]).delete(options[:href]) } if options[:href]
|
||
end
|
||
|
||
def self.instance_for_type(repo, smart_proxy)
|
||
... | ... | |
end
|
||
|
||
def get_remote(href = repo.remote_href)
|
||
repo.url&.start_with?('uln') ? api.remotes_uln_api.read(href) : api.remotes_api.read(href)
|
||
api.get_remotes_api(href: href).read(href)
|
||
end
|
||
|
||
def get_distribution(href = distribution_reference.href)
|
app/services/katello/pulp3/repository_mirror.rb | ||
---|---|---|
def refresh_entities
|
||
href = remote_href
|
||
if href
|
||
if remote_options[:url]&.start_with?('uln')
|
||
[api.remotes_uln_api.partial_update(href, remote_options)]
|
||
else
|
||
[api.remotes_api.partial_update(href, remote_options)]
|
||
end
|
||
# Do not consider remotes_uln_api, since the Katello server is not a ULN server. Even if the sync
|
||
# to Katello used ULN, the sync from Katello server to smart proxy will use a normal RPM remote!
|
||
[api.remotes_api.partial_update(href, remote_options)]
|
||
else
|
||
create_remote
|
||
[]
|
||
... | ... | |
end
|
||
|
||
def create_remote
|
||
if remote_options[:url]&.start_with?('uln')
|
||
remote_file_data = @repo_service.api.class.remote_uln_class.new(remote_options)
|
||
api.remotes_uln_api.create(remote_file_data)
|
||
else
|
||
remote_file_data = @repo_service.api.remote_class.new(remote_options)
|
||
api.remotes_api.create(remote_file_data)
|
||
end
|
||
# Do not consider remotes_uln_api, since the Katello server is not a ULN server. Even if the sync
|
||
# to Katello used ULN, the sync from Katello server to smart proxy will use a normal RPM remote!
|
||
remote_file_data = @repo_service.api.remote_class.new(remote_options)
|
||
api.remotes_api.create(remote_file_data)
|
||
end
|
||
|
||
def compute_remote_options
|
app/services/katello/pulp3/service_common.rb | ||
---|---|---|
remote_file_data = api.remote_class.new(remote_options)
|
||
end
|
||
reformat_api_exception do
|
||
if remote_options[:url]&.start_with?('uln')
|
||
response = api.remotes_uln_api.create(remote_file_data)
|
||
else
|
||
response = api.remotes_api.create(remote_file_data)
|
||
end
|
||
response = api.get_remotes_api(url: remote_options[:url]).create(remote_file_data)
|
||
end
|
||
response
|
||
end
|
||
... | ... | |
end
|
||
|
||
reformat_api_exception do
|
||
if remote_options[:url]&.start_with?('uln')
|
||
response = api.remotes_uln_api.create(remote_file_data)
|
||
else
|
||
response = api.remotes_api.create(remote_file_data)
|
||
end
|
||
response = api.get_remotes_api(url: remote_options[:url]).create(remote_file_data)
|
||
#delete is async, but if its not properly deleted, orphan cleanup will take care of it later
|
||
delete_remote(href: response.pulp_href)
|
||
end
|
test/services/katello/pulp3/repository/file/update_remote_test.rb | ||
---|---|---|
@file_repo_service = @file_repo.backend_service(@mock_smart_proxy)
|
||
@file_repo.root.update(url: 'my-files.org')
|
||
@file_repo_service.stubs(:api).returns(@mock_api_wrapper)
|
||
@mock_api_wrapper.stubs(:remotes_api).returns(@mock_pulp3_api)
|
||
@mock_api_wrapper.stubs(:get_remotes_api).returns(@mock_pulp3_api)
|
||
|
||
@file_repo.remote_href = '193874298udsfsdf'
|
||
refute_empty @file_repo.remote_href
|
Also available in: Unified diff
Fixes #37279 - Re-create remotes when the type needs to change
When updating a remote, we need to re-create it instead if the type has
changed from uln to rpm or vice versa.
For operations on a remote href, the type is now determined from the
href, rather than indirectly from the url. This is more robust since it
is the actually relevant source of truth. In addition the remote API
selection code is now deduplicated within the new get_remote_api method.