Skip to content
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

feat: fails transfer if free space below thresh #478

Open
wants to merge 4 commits into
base: transition-to-runkit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/syskit/cli/log_runtime_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CompressionFailed < RuntimeError; end
class LogRuntimeArchive
DEFAULT_MAX_ARCHIVE_SIZE = 10_000_000_000 # 10G

FREE_SPACE_THRESHOLD_FOR_TRANSFER = 10_000_000_000 # 10G

FTPParameters = Struct.new(:host, :port, :certificate, :user, :password,
:implicit_ftps, :max_upload_rate,
keyword_init: true)
Expand Down Expand Up @@ -223,6 +225,15 @@ def self.log_transfer_results(dataset_path, result, logger: null_logger)
#
# @return [LogUploadState:Result]
def self.transfer_file(file, server, root)
free_space = Sys::Filesystem.stat(root).bytes_available

if free_space < FREE_SPACE_THRESHOLD_FOR_TRANSFER
server.raise_error(
552, "Requested file transfer aborted for #{file}. " \
"Exceeded storage allocation for root dir."
)
end

ftp = RobyApp::LogTransferServer::FTPUpload.new(
server.host, server.port, server.certificate, server.user,
server.password, file,
Expand Down
23 changes: 23 additions & 0 deletions test/cli/test_log_runtime_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,29 @@ def create_server(params)
assert(File.exist?(@target_dir / "PATH" / "test.log"))
assert result.success?, "transfer failed: #{result.message}"
end

it "fails file transfer if free space is lower than threshold" do
dataset = make_valid_folder("PATH")
make_random_file "test.log", root: dataset
LogRuntimeArchive::FREE_SPACE_THRESHOLD_FOR_TRANSFER = 666
mock_available_space(665)

assert_raises(StandardError) do
LogRuntimeArchive.transfer_file(
dataset / "test.log", @params, @root
)
end
end

def mock_available_space(free_space, directory: @root)
flexmock(Sys::Filesystem)
.should_receive(:stat).with(directory)
.and_return do
flexmock(
bytes_available: free_space
)
end
end
end
end

Expand Down