Skip to content

Commit

Permalink
Merge 36fac9f into 21ef793
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasundhara Jagdale committed Jul 9, 2019
2 parents 21ef793 + 36fac9f commit 841f1e7
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/train/platforms/detect/helpers/os_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Train::Platforms::Detect::Helpers
module Windows
def detect_windows
# try to detect windows, use cmd.exe to also support Microsoft OpenSSH
res = @backend.run_command("cmd.exe /c ver")
res = @backend.run_command("cmd.exe /c ver", pty: false)
return false if (res.exit_status != 0) || res.stdout.empty?

# if the ver contains `Windows`, we know its a Windows system
Expand All @@ -29,7 +29,7 @@ def detect_windows
# @see https://msdn.microsoft.com/en-us/library/bb742610.aspx#EEAA
# Thanks to Matt Wrock (https://github.com/mwrock) for this hint
def read_wmic
res = @backend.run_command("wmic os get * /format:list")
res = @backend.run_command("wmic os get * /format:list", pty: false)
if res.exit_status == 0
sys_info = {}
res.stdout.lines.each do |line|
Expand All @@ -41,15 +41,15 @@ def read_wmic
# additional info on windows
@platform[:build] = sys_info[:BuildNumber]
@platform[:name] = sys_info[:Caption]
@platform[:name] = @platform[:name].gsub("Microsoft", "").strip unless @platform[:name].empty?
@platform[:name] = @platform[:name].gsub("Microsoft", "").strip unless @platform[:name].nil?
@platform[:arch] = read_wmic_cpu
end
end

# `OSArchitecture` from `read_wmic` does not match a normal standard
# For example, `x86_64` shows as `64-bit`
def read_wmic_cpu
res = @backend.run_command("wmic cpu get architecture /format:list")
res = @backend.run_command("wmic cpu get architecture /format:list", pty: false)
if res.exit_status == 0
sys_info = {}
res.stdout.lines.each do |line|
Expand Down
9 changes: 4 additions & 5 deletions lib/train/plugins/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ def platform
# This command accepts an optional data handler block. When provided,
# inbound data will be published vi `data_handler.call(data)`. This can allow
# callers to receive and render updates from remote command execution.
def run_command(cmd, &data_handler)
return run_command_via_connection(cmd, &data_handler) unless cache_enabled?(:command)

@cache[:command][cmd] ||= run_command_via_connection(cmd, &data_handler)
def run_command(cmd, **opts, &data_handler)
return run_command_via_connection(cmd, opts, &data_handler) unless cache_enabled?(:command)
@cache[:command][cmd] ||= run_command_via_connection(cmd, opts, &data_handler)
end

# This is the main file call for all connections. This will call the private
Expand Down Expand Up @@ -160,7 +159,7 @@ def wait_until_ready
# if they do not, the block is ignored and will not be used to report data back to the caller.
#
# @return [CommandResult] contains the result of running the command
def run_command_via_connection(_command, &_data_handler)
def run_command_via_connection(_command, **_opts, &_data_handler)
raise NotImplementedError, "#{self.class} does not implement #run_command_via_connection()"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/train/transports/cisco_ios_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def session
@session
end

def run_command_via_connection(cmd, &_data_handler)
def run_command_via_connection(cmd, **_opts, &_data_handler)
# Ensure buffer is empty before sending data
@buf = ""

Expand Down
2 changes: 1 addition & 1 deletion lib/train/transports/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def file_via_connection(path)
end
end

def run_command_via_connection(cmd, &_data_handler)
def run_command_via_connection(cmd, **_opts, &_data_handler)
cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
stdout, stderr, exit_status = @container.exec(
[
Expand Down
2 changes: 1 addition & 1 deletion lib/train/transports/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def force_runner(command_runner)
end
end

def run_command_via_connection(cmd, &_data_handler)
def run_command_via_connection(cmd, **_opts, &_data_handler)
# Use the runner if it is available
return @runner.run_command(cmd) if defined?(@runner)

Expand Down
2 changes: 1 addition & 1 deletion lib/train/transports/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def to_s

private

def run_command_via_connection(cmd, &_data_handler)
def run_command_via_connection(cmd, **_opts, &_data_handler)
@cache[:command][Digest::SHA256.hexdigest cmd.to_s] ||
command_not_found(cmd)
end
Expand Down
10 changes: 6 additions & 4 deletions lib/train/transports/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ def file_via_connection(path)
end
end

def run_command_via_connection(cmd, &data_handler)
def run_command_via_connection(cmd, **opts, &data_handler)
cmd.dup.force_encoding("binary") if cmd.respond_to?(:force_encoding)
logger.debug("[SSH] #{self} (#{cmd})")

reset_session if session.closed?
exit_status, stdout, stderr = execute_on_channel(cmd, &data_handler)
exit_status, stdout, stderr = execute_on_channel(cmd, opts, &data_handler)

# Since `@session.loop` succeeded, reset the IOS command retry counter
@ios_cmd_retries = 0
Expand Down Expand Up @@ -273,18 +273,20 @@ def to_s
# not received.
#
# @api private
def execute_on_channel(cmd, &data_handler)
def execute_on_channel(cmd, **opts, &data_handler)
stdout = stderr = ""
exit_status = nil
session.open_channel do |channel|
# wrap commands if that is configured
cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?

if @transport_options[:pty]
# In case of Windows SSH we are checking opts[:pty] flag
if opts[:pty].nil? ? opts[:pty] : @transport_options[:pty]
channel.request_pty do |_ch, success|
raise Train::Transports::SSHPTYFailed, "Requesting PTY failed" unless success
end
end

channel.exec(cmd) do |_, success|
abort "Couldn't execute command on SSH." unless success
channel.on_data do |_, data|
Expand Down
2 changes: 1 addition & 1 deletion lib/train/transports/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def platform
force_platform!("vmware", @platform_details)
end

def run_command_via_connection(cmd, &_data_handler)
def run_command_via_connection(cmd, **_opts, &_data_handler)
if @powershell_binary == :pwsh
result = parse_pwsh_output(cmd)

Expand Down
2 changes: 1 addition & 1 deletion lib/train/transports/winrm_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def file_via_connection(path)
Train::File::Remote::Windows.new(self, path)
end

def run_command_via_connection(command, &data_handler)
def run_command_via_connection(command, **_opts, &data_handler)
return if command.nil?
logger.debug("[WinRM] #{self} (#{command})")
out = ""
Expand Down

0 comments on commit 841f1e7

Please sign in to comment.