Skip to content

Commit

Permalink
Fixes #33534 - registry name pattern update fails (#9663)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou authored and jlsherrill committed Oct 6, 2021
1 parent 14e1679 commit ae13594
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions app/lib/actions/katello/capsule_content/sync_capsule.rb
Expand Up @@ -11,6 +11,7 @@ def plan(smart_proxy, options = {})
skip_metadata_check = options.fetch(:skip_metadata_check, false)
sequence do
repos = repos_to_sync(smart_proxy, environment, content_view, repository, skip_metadata_check)
return nil if repos.empty?

repos.in_groups_of(Setting[:foreman_proxy_content_batch_size], false) do |repo_batch|
concurrence do
Expand Down
Expand Up @@ -16,6 +16,7 @@ def plan(env, options = {})
repositories.each do |repository|
sequence do
repository.set_container_repository_name
repository.clear_smart_proxy_sync_histories
plan_action(::Actions::Katello::Repository::InstanceUpdate, repository)
plan_action(::Actions::Katello::Repository::CapsuleSync, repository)
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/repository/instance_update.rb
Expand Up @@ -7,7 +7,7 @@ class InstanceUpdate < Actions::EntryAction
def plan(repository)
action_subject repository
repository.save!
plan_action(::Actions::Pulp3::Orchestration::Repository::RefreshIfNeeded, repository)
plan_action(::Actions::Pulp3::Orchestration::Repository::RefreshIfNeeded, repository, SmartProxy.pulp_primary)
plan_self(:repository_id => repository.id)
end

Expand Down
25 changes: 11 additions & 14 deletions app/services/katello/pulp3/repository.rb
Expand Up @@ -185,7 +185,7 @@ def get_distribution(href = distribution_reference.href)
def distribution_needs_update?
if distribution_reference
expected = secure_distribution_options(relative_path).except(:name).compact
actual = get_distribution.to_hash
actual = get_distribution&.to_hash || {}
expected != actual.slice(*expected.keys)
elsif repo.environment
true
Expand Down Expand Up @@ -262,21 +262,18 @@ def refresh_distributions
else
dist = lookup_distributions(base_path: repo.relative_path).first
end
dist_ref = distribution_reference

# First check if the distribution exists
if dist
dist_ref = distribution_reference
# If we have a DistributionReference, update the distribution
if dist_ref
return update_distribution
# If no DistributionReference, create a DistributionReference and return
else
save_distribution_references([dist.pulp_href])
return []
end
if dist && !dist_ref
save_distribution_references([dist.pulp_href])
return update_distribution
end

# So far, it looks like there is no distribution. Try to create one.
if dist_ref
return update_distribution
end

# Since we got this far, we need to create a new distribution
begin
create_distribution(relative_path)
rescue api.class.client_module::ApiError => e
Expand All @@ -285,7 +282,7 @@ def refresh_distributions
e.message.include?("\"base_path\":[\"Overlaps with existing distribution\"")
dist = lookup_distributions(base_path: repo.relative_path).first
save_distribution_references([dist.pulp_href])
return []
return update_distribution
else
raise e
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/katello/pulp3/repository_mirror.rb
Expand Up @@ -160,7 +160,7 @@ def refresh_distributions(options = {})
if (distro = repo_service.lookup_distributions(base_path: path).first) ||
(distro = repo_service.lookup_distributions(name: "#{backend_object_name}").first)
# update dist
dist_options = dist_options.except(:name, :base_path)
dist_options = dist_options.except(:name)
api.distributions_api.partial_update(distro.pulp_href, dist_options)
else
# create dist
Expand Down
10 changes: 10 additions & 0 deletions test/models/smart_proxy_sync_history_test.rb
Expand Up @@ -50,5 +50,15 @@ def test_clear_history_on_smart_proxy
smart_proxy_helper.clear_smart_proxy_sync_histories
assert_equal @repo.smart_proxy_sync_histories.count, 0
end

def test_clear_history_on_publish_repositories
User.current = users(:admin)
@repo.create_smart_proxy_sync_history(proxy_with_pulp)
library = katello_environments(:library)
library.expects(:repositories).returns([@repo])
::Actions::Katello::Environment::PublishRepositories.any_instance.expects(:plan_action).twice
::ForemanTasks.sync_task(::Actions::Katello::Environment::PublishRepositories, library)
assert_equal @repo.smart_proxy_sync_histories.count, 0
end
end
end
Expand Up @@ -26,8 +26,11 @@ def test_sync
def test_refresh_distributions_update_dist
mock_distribution = "distro"
mock_distribution.expects(:pulp_href).once.returns("pulp_href")
@repo_service.stubs(:lookup_distributions).returns([mock_distribution])
PulpAnsibleClient::DistributionsAnsibleApi.any_instance.expects(:partial_update).with("pulp_href", {:content_guard => nil})
@repo_service.expects(:lookup_distributions).returns([mock_distribution])
@repo_service.expects(:relative_path).returns("relative_path")
PulpAnsibleClient::DistributionsAnsibleApi.any_instance.expects(:partial_update).with("pulp_href",
{ :content_guard => nil,
:base_path => "relative_path" })
@repo_mirror.refresh_distributions(name: "test name", base_path: "test base_path", content_guard: "test content_guard")
end

Expand Down
Expand Up @@ -26,8 +26,11 @@ def test_sync
def test_refresh_distributions_update_dist
mock_distribution = "distro"
mock_distribution.expects(:pulp_href).once.returns("pulp_href")
@repo_service.stubs(:lookup_distributions).returns([mock_distribution])
PulpContainerClient::DistributionsContainerApi.any_instance.expects(:partial_update).with("pulp_href", {})
@repo_service.expects(:lookup_distributions).returns([mock_distribution])
@repo_service.expects(:relative_path).returns("base_path")
PulpContainerClient::DistributionsContainerApi.any_instance.expects(:partial_update).with("pulp_href",
{ base_path: "base_path" })

@repo_mirror.refresh_distributions(name: "test name", base_path: "test base_path", content_guard: "test content_guard")
end

Expand Down

0 comments on commit ae13594

Please sign in to comment.