Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36859 - Fix inconsistent repo publication #10776

Merged
merged 1 commit into from
Dec 20, 2023
Merged
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
14 changes: 13 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 !repo.repository_type.pulp3_skip_publication && 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,13 @@ 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
return nil if repo.publication_href.nil?
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the correct file for the test?

I kinda doubt it, but it seemed to be the best fir without creating a new test-class 😇

Copy link
Member

Choose a reason for hiding this comment

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

Works for me!

@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
Loading
Loading