-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #27517 - Pulp3 content upload via hammer (#8304)
* Fixes #27517 - Pulp3 content upload via hammer * Fixes #27517 - Rubocop fixes * Fixes #27517 - Add tests * Fixes #27517 - Fix test
- Loading branch information
Showing
11 changed files
with
164 additions
and
47 deletions.
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
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
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/orchestration/repository/import_upload.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 Orchestration | ||
module Repository | ||
class ImportUpload < Pulp3::AbstractAsyncTask | ||
def plan(repository, smart_proxy, args) | ||
file = {:filename => args.dig(:unit_key, :name)} | ||
sequence do | ||
action_output = plan_self(:repository_id => repository.id, :smart_proxy_id => smart_proxy.id, :upload_href => "/pulp/api/v3/uploads/" + args.dig(:upload_id) + "/", :sha256 => args.dig(:unit_key, :checksum)).output | ||
artifact_action_output = plan_action(Pulp3::Repository::SaveArtifact, file, repository, action_output[:pulp_tasks], args.dig(:unit_type_id)).output | ||
action_output = plan_action(Pulp3::Repository::ImportUpload, artifact_action_output[:content_unit_href], repository, smart_proxy).output | ||
plan_action(Pulp3::Repository::SaveVersion, repository, action_output[:pulp_tasks]).output | ||
end | ||
end | ||
|
||
def invoke_external_task | ||
repo = ::Katello::Repository.find(input[:repository_id]) | ||
repo_backend_service = repo.backend_service(smart_proxy) | ||
uploads_api = repo_backend_service.uploads_api | ||
output[:pulp_tasks] = [uploads_api.commit(input[:upload_href], sha256: input[:sha256])] | ||
end | ||
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,53 @@ | ||
require "pulpcore_client" | ||
module Katello | ||
module Pulp3 | ||
class Content | ||
extend Katello::Abstract::Pulp::Content | ||
class << self | ||
def create_upload(size = 0) | ||
upload_href = uploads_api.create(upload_class.new(size: size))._href | ||
{"upload_id" => upload_href.split("/").last} | ||
end | ||
|
||
def delete_upload(upload_href) | ||
#Commit deletes upload request for pulp3. Not needed other than to implement abstract method. | ||
end | ||
|
||
def upload_chunk(upload_href, offset, content, size) | ||
upload_href = "/pulp/api/v3/uploads/" + upload_href + "/" | ||
offset = offset.try(:to_i) | ||
size = size.try(:to_i) | ||
begin | ||
filechunk = Tempfile.new('filechunk', :encoding => 'ascii-8bit') | ||
filechunk.write(content) | ||
filechunk.flush | ||
actual_chunk_size = File.size(filechunk) | ||
uploads_api.update(upload_href, content_range(offset, offset + actual_chunk_size - 1, size), filechunk) | ||
ensure | ||
filechunk.close | ||
filechunk.unlink | ||
end | ||
end | ||
|
||
private | ||
|
||
def core_api_client | ||
PulpcoreClient::ApiClient.new(SmartProxy.pulp_master.pulp3_configuration(PulpcoreClient::Configuration)) | ||
end | ||
|
||
def uploads_api | ||
PulpcoreClient::UploadsApi.new(core_api_client) | ||
end | ||
|
||
def upload_class | ||
PulpcoreClient::Upload | ||
end | ||
|
||
def content_range(start, finish, total) | ||
finish = finish > total ? total : finish | ||
"bytes #{start}-#{finish}/#{total}" | ||
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
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