Skip to content

Commit

Permalink
Fixes #36859 - Fix inconsistent repo publication
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Oct 25, 2023
1 parent ed38597 commit ee30afc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/lib/actions/pulp3/repository/save_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def run
repo.update(:version_href => version_href)
end
else
output[:contents_changed] = false
# get publication and check if repo-version and publication match. Otherwise, contents_changed: false
if fetch_current_published_version_href(repo) != repo.version_href
output[:contents_changed] = true
else
output[:contents_changed] = false
end
end
end

Expand All @@ -44,6 +49,12 @@ def fetch_version_href(repo)
repo_href = repo_backend_service.repository_reference.repository_href
repo_backend_service.api.repositories_api.read(repo_href).latest_version_href
end

def fetch_current_published_version_href(repo)
# Fetch latest Pulp 3 repo version
repo_backend_service = repo.backend_service(SmartProxy.pulp_primary)
repo_backend_service.api.publications_api.read(repo.publication_href).repository_version
end
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions test/actions/pulp3/repository/save_versions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,24 @@ def test_save_new_version_from_lookup
assert_equal task.output[:contents_changed], true
assert_empty task.output[:updated_repositories] - [@repo1.id, @repo2.id]
end

def test_save_version_with_outdated_publication
@repo1.update(version_href: "test_repo_1/1/", publication_href: "test_publ_1/")
::Katello::Pulp3::RepositoryReference.new(repository_href: "test_repo_1/", root_repository_id: @repo1.root_id, content_view_id: @repo1.content_view.id).save

tasks_map = [{ created_resources: [] }]

::PulpFileClient::PublicationsFileApi.any_instance.expects(:read).with("test_publ_1/").
returns(::PulpFileClient::FileFilePublicationResponse.new(repository_version: "test_repo_1/0/"))
::Katello::Repository.any_instance.stubs(:index_content).returns(true)

task = ForemanTasks.sync_task(::Actions::Pulp3::Repository::SaveVersion, @repo1, tasks: tasks_map)

@repo1.reload

assert_equal "test_repo_1/1/", @repo1.version_href
assert_equal true, task.output[:contents_changed]
assert_nil task.output[:updated_repositories]
end
end
end

0 comments on commit ee30afc

Please sign in to comment.