From 3250cc7bf28e75d7a770d278ad167c7507c967a7 Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Wed, 25 Oct 2023 10:52:17 +0200 Subject: [PATCH] Fixes #36859 - Fix inconsistent repo publication --- .../actions/pulp3/repository/save_version.rb | 13 ++++++++++++- .../pulp3/repository/save_versions_test.rb | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/lib/actions/pulp3/repository/save_version.rb b/app/lib/actions/pulp3/repository/save_version.rb index ff3b332faac..b2c59a0cc8e 100644 --- a/app/lib/actions/pulp3/repository/save_version.rb +++ b/app/lib/actions/pulp3/repository/save_version.rb @@ -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 @@ -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 diff --git a/test/actions/pulp3/repository/save_versions_test.rb b/test/actions/pulp3/repository/save_versions_test.rb index 1535bf4d5cb..70dc1bee9f1 100644 --- a/test/actions/pulp3/repository/save_versions_test.rb +++ b/test/actions/pulp3/repository/save_versions_test.rb @@ -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 task.output[:contents_changed] + assert_nil task.output[:updated_repositories] + end end end