-
Notifications
You must be signed in to change notification settings - Fork 297
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 #29122 - Correct CV deletion behavior for pulp3 #8594
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/lib/actions/pulp3/content_view/delete_repository_references.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Actions | ||
module Pulp3 | ||
module ContentView | ||
class DeleteRepositoryReferences < Pulp3::AbstractAsyncTask | ||
def plan(content_view, smart_proxy) | ||
if content_view.repository_references.any? | ||
plan_self(:content_view_id => content_view.id, :smart_proxy_id => smart_proxy.id) | ||
end | ||
end | ||
|
||
def invoke_external_task | ||
tasks = [] | ||
content_view = ::Katello::ContentView.find(input[:content_view_id]) | ||
content_view.repository_references.each do |repository_reference| | ||
repo = repository_reference.root_repository.library_instance | ||
#force pulp3 in case we've done migrations, but haven't switched over yet | ||
tasks << repo.backend_service(smart_proxy, true).delete(repository_reference.repository_href) | ||
end | ||
content_view.repository_references.destroy_all | ||
|
||
output[:pulp_tasks] = tasks | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Actions | ||
module Pulp3 | ||
module Repository | ||
class DeleteVersion < Pulp3::AbstractAsyncTask | ||
def plan(repository, smart_proxy) | ||
#A version from library might be reused in a composite, or could have been copied | ||
# from a library repository, so only delete the version if its the last | ||
if ::Katello::Repository.where(:version_href => repository.version_href).count == 1 | ||
plan_self(:repository_id => repository.id, :smart_proxy_id => smart_proxy.id) | ||
end | ||
end | ||
|
||
def invoke_external_task | ||
repo = ::Katello::Repository.find(input[:repository_id]) | ||
output[:response] = repo.backend_service(smart_proxy).delete_version | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
test/actions/pulp3/content_view/delete_repository_references.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'katello_test_helper' | ||
|
||
module ::Actions::Pulp3::ContentView | ||
class DeleteRepositoryReferenceTest < ActiveSupport::TestCase | ||
include Katello::Pulp3Support | ||
|
||
def setup | ||
@master = FactoryBot.create(:smart_proxy, :default_smart_proxy, :with_pulp3) | ||
@repo = katello_repositories(:generic_file_archive) | ||
@content_view = @repo.content_view | ||
ensure_creatable(@repo, @master) | ||
end | ||
|
||
def test_create | ||
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::Create, @repo, @master) | ||
repo_reference = Katello::Pulp3::RepositoryReference.find_by(:content_view => @content_view, :root_repository_id => @repo.root_id) | ||
assert repo_reference | ||
assert Katello::Pulp3::Api::File.new(@master).repositories_api.read(repo_reference.repository_href) | ||
|
||
ForemanTasks.sync_task(::Actions::Pulp3::ContentView::DeleteRepositoryReferences, @content_view, @master) | ||
refute Katello::Pulp3::RepositoryReference.find_by(:id => repo_reference.id) | ||
|
||
assert_raises(PulpFileClient::ApiError) do | ||
Katello::Pulp3::Api::File.new(@master).repositories_api.read(repo_reference.repository_href) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would we use the
force_pulp3
parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its used in one place at the moment. When we delete a content view: https://github.com/Katello/katello/pull/8594/files#diff-d4b12ef3369bd829bf21911a41392ee5R17
If at this point we aren't using pulp3 for that type of content, but for some reason a Pulp3::RepositoryReference exists, it means we have to have run the content migration already, but are deleting stuff before actually switching over to pulp3. So it makes sense to force it in order to get the backend service object to delete the pulp3 repository.