Created
July 8, 2019 19:31
-
-
Save sjha4/65078285778b3d80891202ec4c3fb569 to your computer and use it in GitHub Desktop.
Steps to test content upload error
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
require 'pulpcore_client' | |
PulpcoreClient.configure do |config| | |
config.host= "http://localhost:24817" | |
config.username= 'admin' | |
config.password= 'password' | |
config.debugging=true | |
end | |
uploads_api = PulpcoreClient::UploadsApi.new | |
upload_chunk_size = 1000 | |
file = File.new('katello.gemspec') # File | A chunk of a file to upload. | |
total_size = File.size(file) | |
offset = 0 | |
upload_data = PulpcoreClient::Upload.new({size: total_size}) | |
response = uploads_api.create(upload_data) | |
upload_href = response._href | |
def content_range(start, finish, total) | |
finish = finish > total ? total : finish | |
"bytes #{start}-#{finish}/#{total}" | |
end | |
def tmp_file(file, upload_chunk_size) | |
tmp_path = File.path(file) + "_tmp_upload" | |
File.delete(tmp_path) if File.exist?(tmp_path) | |
File.new(tmp_path, 'wb+', 0600) | |
File.open(tmp_path, "wb+") do |temp_file| | |
temp_file.write(file.read(upload_chunk_size)) | |
end | |
tmp_path | |
end | |
def clean_temps(file) | |
tmp_path = File.path(file) + "_tmp_upload" | |
File.delete(tmp_path) if File.exist?(tmp_path) | |
end | |
file_full = file | |
File.open(file_full, "rb") do |file| | |
while (chunk = tmp_file(file, upload_chunk_size)) | |
response = uploads_api.update(upload_href, content_range(offset, offset + upload_chunk_size, total_size), chunk) | |
offset += upload_chunk_size | |
break if (offset + upload_chunk_size >= total_size) | |
end | |
end | |
clean_temps file_full |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If running on a pulp3 only box:
Install ruby, pulpcore-client gem and setup a temp file
sudo yum -y install ruby
sudo yum -y install ruby-devel
sudo yum -y install gcc
gem install pulpcore_client --pre
curl -o katello.gemspec https://github.com/Katello/katello/blob/master/katello.gemspec
ruby test_upload.rb