Skip to content

Commit

Permalink
Fixes #38035 - fix hammer upload existing deb
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Nov 21, 2024
1 parent 8201a7a commit 4821189
Show file tree
Hide file tree
Showing 3 changed files with 580 additions and 110 deletions.
16 changes: 15 additions & 1 deletion app/lib/actions/pulp3/orchestration/repository/import_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@ def plan(repository, smart_proxy, args)
plan_action(Pulp3::Repository::SaveVersion, repository, {force_fetch_version: true, tasks: tag_manifest_output[:pulp_tasks]})
else
if content_unit_href
artifact_output = { :content_unit_href => content_unit_href }
commit_output = {}
if repository.deb?
# find artifact-href
content_backend_service = smart_proxy.content_service('deb')
artifact_href = content_backend_service.content_api.read(content_unit_href).artifact

artifact_output = plan_action(Pulp3::Repository::SaveArtifact,
file,
repository,
smart_proxy,
nil,
args.dig(:unit_type_id),
args.merge({artifact_href: artifact_href})).output
else
artifact_output = { :content_unit_href => content_unit_href }
end
else
commit_output = plan_action(Pulp3::Repository::CommitUpload,
repository,
Expand Down
62 changes: 58 additions & 4 deletions test/actions/pulp3/orchestration/import_upload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
module ::Actions::Pulp3
class ImportUploadTest < ActiveSupport::TestCase
include Katello::Pulp3Support
include Dynflow::Testing

def setup
@action_class = ::Actions::Pulp3::Orchestration::Repository::ImportUpload
@action = create_action @action_class
@primary = SmartProxy.pulp_primary
@repo1 = katello_repositories(:debian_10_amd64)
create_repo(@repo1, @primary)
Expand Down Expand Up @@ -51,7 +54,7 @@ def run_upload_test(content_unit_type, filename, repo, content_path_match)
file = upload_file(content_unit_type, filename, repo)

action_result = ForemanTasks.sync_task(
::Actions::Pulp3::Orchestration::Repository::ImportUpload, repo, @primary,
@action_class, repo, @primary,
{
unit_type_id: content_unit_type,
upload_id: file['upload_id'],
Expand All @@ -64,19 +67,70 @@ def run_upload_test(content_unit_type, filename, repo, content_path_match)

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

return action_result
end
end

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

# test re-upload
VCR.use_cassette(cassette_name + '_binary', :match_requests_on => [:method, :path, :params]) do
plan_action(@action, @repo1, @primary,
{
unit_type_id: content_unit_type,
upload_id: 'duplicate',
unit_key: {
content_unit_id: action_result.output[:content_unit_href],
},
}
)
assert_action_planned_with(@action, ::Actions::Pulp3::Repository::SaveArtifact) do |_file, repo, smart_proxy, _tasks, unit_type_id, options|
assert_match %r{^/pulp/api/v3/artifacts/}, options[:artifact_href]
assert_equal @repo1, repo
assert_equal @primary, smart_proxy
assert_equal content_unit_type, unit_type_id
end
refute_action_planned(@action, ::Actions::Pulp3::Repository::CommitUpload)
end
end

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

# test re-upload
plan_action(@action, @repo2, @primary,
{
unit_type_id: content_unit_type,
upload_id: 'duplicate',
unit_key: {
content_unit_id: action_result.output[:content_unit_href],
},
}
)
refute_action_planned(@action, ::Actions::Pulp3::Repository::SaveArtifact)
refute_action_planned(@action, ::Actions::Pulp3::Repository::CommitUpload)
end

def test_rpm_upload
run_upload_test('rpm', 'squirrel-0.3-0.8.noarch.rpm', @repo2, %r{^/pulp/api/v3/content/rpm/packages/})
content_unit_type = 'rpm'
action_result = run_upload_test(content_unit_type, 'squirrel-0.3-0.8.noarch.rpm', @repo2, %r{^/pulp/api/v3/content/rpm/packages/})

# test re-upload
plan_action(@action, @repo2, @primary,
{
unit_type_id: content_unit_type,
upload_id: 'duplicate',
unit_key: {
content_unit_id: action_result.output[:content_unit_href],
},
}
)
refute_action_planned(@action, ::Actions::Pulp3::Repository::SaveArtifact)
refute_action_planned(@action, ::Actions::Pulp3::Repository::CommitUpload)
end
end
end
Loading

0 comments on commit 4821189

Please sign in to comment.