Skip to content

Commit

Permalink
Fixes #37864 - API upload of deb-content fails
Browse files Browse the repository at this point in the history
Actually it does not fail but worse, succeed with broken deb-package in
katello due to saving the wrong pulp_href.
  • Loading branch information
m-bucher committed Nov 19, 2024
1 parent 74d6613 commit 330a78b
Show file tree
Hide file tree
Showing 17 changed files with 14,328 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def run
if input[:content_unit_href]
output[:content_unit_href] = input[:content_unit_href]
elsif input[:artifact_output]
output[:content_unit_href] = input[:artifact_output][:content_unit_href] || input[:artifact_output][:pulp_tasks].last[:created_resources].first
output[:content_unit_href] = input[:artifact_output][:content_unit_href] ||
input[:artifact_output][:pulp_tasks].last[:created_resources].find { |href| href.include?("/deb/packages") } ||
input[:artifact_output][:pulp_tasks].last[:created_resources].first
else
output[:content_unit_href] = nil
end
Expand Down
81 changes: 81 additions & 0 deletions test/actions/pulp3/orchestration/deb_upload_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
require 'katello_test_helper'

module ::Actions::Pulp3
class DebUploadTest < ActiveSupport::TestCase
include Katello::Pulp3Support

def setup
@primary = SmartProxy.pulp_primary
@repo = katello_repositories(:debian_10_amd64)
@content = katello_contents(:deb_content)
@repo.content_id = @content.cp_content_id
file1 = File.join(Katello::Engine.root, 'test/fixtures/files/frigg_1.0_ppc64.deb')
file2 = File.join(Katello::Engine.root, 'test/fixtures/files/odin_1.0_ppc64.deb')
@file1 = {path: file1, filename: 'frigg_1.0_ppc64.deb'}
@file2 = {path: file2, filename: 'odin_1.0_ppc64.deb'}
create_repo(@repo, @primary)
::Katello::Resources::Candlepin::Content.stubs(:update)
@content.stubs(:update!)
end

def teardown
@repo.backend_service(@primary).delete_distributions
@repo.backend_service(@primary).delete_publication
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::Repository::Delete, @repo, @primary)
end

def test_upload
@repo.reload
assert @repo.remote_href
deb_count = @repo.debs.count

VCR.use_cassette(cassette_name + '_binary', :match_requests_on => [:method, :path, :params]) do
action_result = ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::UploadContent, @repo, @primary, @file1, 'deb')
assert_equal "success", action_result.result
@repo.reload
repository_reference = Katello::Pulp3::RepositoryReference.find_by(
:root_repository_id => @repo.root.id,
:content_view_id => @repo.content_view.id)
assert_equal repository_reference.repository_href + "versions/2/", @repo.version_href

upload_action = ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::UploadContent, @repo, @primary, @file2, 'deb')
assert_equal "success", upload_action.result
finish_upload_action = ForemanTasks.sync_task(::Actions::Katello::Repository::FinishUpload, @repo, content_type: 'deb', upload_actions: [upload_action.output])
assert_equal "success", finish_upload_action.result
@repo.reload
repository_reference = Katello::Pulp3::RepositoryReference.find_by(
:root_repository_id => @repo.root.id,
:content_view_id => @repo.content_view.id)
assert_equal repository_reference.repository_href + "versions/3/", @repo.version_href
assert_equal @repo.debs.count, deb_count + 1
end
end

def test_duplicate_upload
action_result = ""
@repo.reload
assert @repo.remote_href

VCR.use_cassette(cassette_name + '_binary', :match_requests_on => [:method, :path, :params]) do
action_result = ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::UploadContent, @repo, @primary, @file1, 'deb')
end
assert_equal "success", action_result.result
@repo.reload
repository_reference = Katello::Pulp3::RepositoryReference.find_by(
:root_repository_id => @repo.root.id,
:content_view_id => @repo.content_view.id)
assert_equal repository_reference.repository_href + "versions/2/", @repo.version_href

VCR.use_cassette(cassette_name + '_binary_duplicate', :match_requests_on => [:method, :path, :params]) do
action_result = ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::UploadContent, @repo, @primary, @file1, 'deb')
end
assert_equal "success", action_result.result
@repo.reload
repository_reference = Katello::Pulp3::RepositoryReference.find_by(
:root_repository_id => @repo.root.id,
:content_view_id => @repo.content_view.id)
assert_equal repository_reference.repository_href + "versions/2/", @repo.version_href
end
end
end
83 changes: 83 additions & 0 deletions test/actions/pulp3/orchestration/import_upload_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
require 'katello_test_helper'
require 'pry'

module ::Actions::Pulp3
class ImportUploadTest < ActiveSupport::TestCase
include Katello::Pulp3Support

def setup
@primary = SmartProxy.pulp_primary
@repo1 = katello_repositories(:debian_10_amd64)
create_repo(@repo1, @primary)
@repo2 = katello_repositories(:fedora_17_x86_64)
create_repo(@repo2, @primary)
@repo3 = katello_repositories(:generic_file)
create_repo(@repo3, @primary)
end

def upload_file(content_unit_type, filename, repo)
path = File.join(Katello::Engine.root, 'test/fixtures/files/', filename)
content = File.read(path)
file = {path: path, filename: filename, checksum: Digest::SHA256.hexdigest(content)}

file.merge! repo.backend_content_service(@primary).create_upload(
content.bytesize,
file[:checksum],
content_unit_type,
repo
)
file[:upload_href] = repo.backend_content_service(@primary)
.upload_chunk(
file['upload_id'], 0, content, content.bytesize
).pulp_href

file
end

def teardown
[@repo1, @repo2, @repo3].each do |repo|
repo.backend_service(@primary).delete_distributions
repo.backend_service(@primary).delete_publication
ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::Repository::Delete, repo, @primary)
end
# cleanup orphaned content
::Katello::Pulp3::Api::Core.new(@primary).orphans_api.cleanup(
::PulpcoreClient::OrphansCleanup.new(orphan_protection_time: 0)
)
end

def run_upload_test(content_unit_type, filename, repo, content_path_match)
VCR.use_cassette(cassette_name + '_binary', :match_requests_on => [:method, :path, :params]) do
file = upload_file(content_unit_type, filename, repo)

action_result = ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::Repository::ImportUpload, repo, @primary,
{
unit_type_id: content_unit_type,
upload_id: file['upload_id'],
unit_key: {
name: file[:filename],
checksum: file[:checksum]

Check failure on line 61 in test/actions/pulp3/orchestration/import_upload_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
}

Check failure on line 62 in test/actions/pulp3/orchestration/import_upload_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
}
)

assert_equal 'success', action_result.result
assert_match content_path_match, action_result.output[:content_unit_href]
end
end

def test_deb_upload
run_upload_test('deb', 'frigg_1.0_ppc64.deb', @repo1, %r{^/pulp/api/v3/content/deb/packages/})
end

def test_file_upload
run_upload_test('file', 'frigg_1.0_ppc64.deb', @repo3, %r{^/pulp/api/v3/content/file/files/})
end

def test_rpm_upload
run_upload_test('rpm', 'squirrel-0.3-0.8.noarch.rpm', @repo2, %r{^/pulp/api/v3/content/rpm/packages/})
end
end
end
Binary file added test/fixtures/files/frigg_1.0_ppc64.deb
Binary file not shown.
Binary file added test/fixtures/files/odin_1.0_ppc64.deb
Binary file not shown.
10 changes: 9 additions & 1 deletion test/fixtures/models/katello_contents.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
deb_content:
name: debian
label: debian
cp_content_id: 110
organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
content_url: /custom/Debian_12/Debian_12_amd64_main/?comp=main&rel=bookworm
content_type: "deb"

some_content:
name: Fedora
cp_content_id: 1
Expand All @@ -12,4 +20,4 @@ rhel_content:
cp_content_id: 69
organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
content_url: /content/dist/rhel/server/$releasever/$basearch/os
content_type: "yum"
content_type: "yum"
Loading

0 comments on commit 330a78b

Please sign in to comment.