class Kitchen::Transport::Exec::Connection
Fake connection which just does local operations.
Attributes
instance_name[R]
@return [String] display name for the associated instance @api private
kitchen_root[R]
@return [String] local path to the root of the project @api private
Public Instance Methods
close()
click to toggle source
# File lib/kitchen/transport/exec.rb, line 51 def close if host_os_windows? FileUtils.remove(exec_script_file) end end
execute(command)
click to toggle source
(see Base#execute)
# File lib/kitchen/transport/exec.rb, line 40 def execute(command) return if command.nil? if host_os_windows? run_command(run_from_file_command(command)) close else run_command(command) end end
init_options(options)
click to toggle source
(see Base#init_options)
Calls superclass method
Kitchen::Transport::Base::Connection#init_options
# File lib/kitchen/transport/exec.rb, line 70 def init_options(options) super @instance_name = @options.delete(:instance_name) @kitchen_root = @options.delete(:kitchen_root) end
upload(locals, remote)
click to toggle source
“Upload” the files by copying them locally.
@see Base#upload
# File lib/kitchen/transport/exec.rb, line 60 def upload(locals, remote) # evaluate $env:temp on Windows real_remote = remote.to_s == "\$env:TEMP\\kitchen" ? kitchen_temp : remote FileUtils.mkdir_p(real_remote) Array(locals).each do |local| FileUtils.cp_r(local, real_remote) end end
Private Instance Methods
exec_script_file()
click to toggle source
@return [String] file path for exec script to be run @api private
# File lib/kitchen/transport/exec.rb, line 115 def exec_script_file File.join(kitchen_root, ".kitchen", exec_script_name) end
exec_script_name()
click to toggle source
@return [String] name of script using instance name @api private
# File lib/kitchen/transport/exec.rb, line 109 def exec_script_name "#{instance_name}-exec-script.ps1" end
host_os_windows?()
click to toggle source
# File lib/kitchen/transport/exec.rb, line 119 def host_os_windows? case RbConfig::CONFIG["host_os"] when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ true else false end end
kitchen_temp()
click to toggle source
@return [String] evaluated $env:temp variable @api private
# File lib/kitchen/transport/exec.rb, line 103 def kitchen_temp "#{ENV["temp"]}/kitchen" end
run_from_file_command(command)
click to toggle source
Takes a long command and saves it to a file and uploads it to the test instance. Windows has cli character limits.
@param command [String] a long command to be saved and uploaded @return [String] a command that executes the uploaded script @api private
# File lib/kitchen/transport/exec.rb, line 92 def run_from_file_command(command) if logger.debug? debug("Creating exec script for #{instance_name} (#{exec_script_file})") debug("Executing #{exec_script_file}") end File.open(exec_script_file, "wb") { |file| file.write(command) } %{powershell -file "#{exec_script_file}"} end