Skip to content

Commit

Permalink
(puppetlabsGH-1256) Add debug logging for transport file transfer
Browse files Browse the repository at this point in the history
With this commit a debug log message is produced when a transport uploads a file to a target. Note this excludes the orch transport.
  • Loading branch information
donoghuc committed Oct 7, 2019
1 parent d93101e commit 9b1de60
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bolt/transport/docker/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ def execute(*command, options)
end

def write_remote_file(source, destination)
@logger.debug { "Uploading #{source}, to #{destination}" }
_, stdout_str, status = execute_local_docker_command('cp', [source, "#{container_id}:#{destination}"])
raise "Error writing file to container #{@container_id}: #{stdout_str}" unless status.exitstatus.zero?
rescue StandardError => e
raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
end

def write_remote_directory(source, destination)
@logger.debug { "Uploading #{source}, to #{destination}" }
_, stdout_str, status = execute_local_docker_command('cp', [source, "#{container_id}:#{destination}"])
raise "Error writing directory to container #{@container_id}: #{stdout_str}" unless status.exitstatus.zero?
rescue StandardError => e
Expand Down
1 change: 1 addition & 0 deletions lib/bolt/transport/local/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def handle_sudo_errors(err, pid)
end

def copy_file(source, dest)
@logger.debug { "Uploading #{source}, to #{dest}" }
if source.is_a?(StringIO)
File.open("tempfile", "w") { |f| f.write(source.read) }
execute(['mv', 'tempfile', dest])
Expand Down
1 change: 1 addition & 0 deletions lib/bolt/transport/local_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def in_tmpdir(base)
private :in_tmpdir

def copy_file(source, destination)
logger.debug { "Uploading #{source}, to #{destination}" }
FileUtils.cp_r(source, destination, remove_destination: true)
rescue StandardError => e
raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
Expand Down
2 changes: 2 additions & 0 deletions lib/bolt/transport/ssh/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def execute(command, sudoable: false, **options)
end

def copy_file(source, destination)
# Do not log wrapper script content
@logger.debug { "Uploading #{source}, to #{destination}" } unless source.is_a(StringIO)
@session.scp.upload!(source, destination, recursive: true)
rescue StandardError => e
raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
Expand Down
1 change: 1 addition & 0 deletions lib/bolt/transport/winrm/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def mkdirs(dirs)
end

def write_remote_file(source, destination)
@logger.debug { "Uploading #{source}, to #{destination}" }
if target.options['file-protocol'] == 'smb'
write_remote_file_smb(source, destination)
else
Expand Down

0 comments on commit 9b1de60

Please sign in to comment.