lib/beaker/dsl/helpers/host_helpers.rb in beaker-4.38.1 vs lib/beaker/dsl/helpers/host_helpers.rb in beaker-4.39.0
- old
+ new
@@ -81,11 +81,11 @@
raise ArgumentError, msg
end
@result = host.exec(command_object, opts)
# Also, let additional checking be performed by the caller.
- if block_given?
+ if block
case block.arity
#block with arity of 0, just hand back yourself
when 0
yield self
#block with arity of 1 or greater, hand back the result object
@@ -191,11 +191,11 @@
# @!macro common_opts
#
# @return [Result] Returns the result of the SCP operation
def scp_to host, from_path, to_path, opts = {}
block_on host do | host |
- if host['platform'] =~ /windows/ && to_path.match('`cygpath')
+ if host['platform'].include?('windows') && to_path.match('`cygpath')
result = on host, "echo #{to_path}"
to_path = result.raw_output.chomp
end
@result = host.do_scp_to(from_path, to_path, opts)
@result.log logger
@@ -213,11 +213,11 @@
# @!macro common_opts
#
# @return [Result] Returns the result of the rsync operation
def rsync_to host, from_path, to_path, opts = {}
block_on host do | host |
- if host['platform'] =~ /windows/ && to_path.match('`cygpath')
+ if host['platform'].include?('windows') && to_path.match('`cygpath')
result = host.echo "#{to_path}"
to_path = result.raw_output.chomp
end
@result = host.do_rsync_to(from_path, to_path, opts)
@result
@@ -266,11 +266,11 @@
# full path to check for existance later
filename = "#{targetdir}/" + File.basename(from_path)
FileUtils.mkdir_p(targetdir)
scp_from(host, from_path, targetdir, opts)
# scp_from does succeed on a non-existant file, checking if the file/folder actually exists
- if not File.exists?(filename)
+ if not File.exist?(filename)
raise IOError, "No such file or directory - #{filename}"
end
create_tarball(archive_root, archive_name)
end
@@ -346,11 +346,11 @@
# @return [Result] Returns the result of the powershell command execution
def execute_powershell_script_on(hosts, powershell_script, opts = {})
block_on hosts, opts do |host|
script_path = "beaker_powershell_script_#{Time.now.to_i}.ps1"
create_remote_file(host, script_path, powershell_script, opts)
- native_path = script_path.gsub(/\//, "\\")
+ native_path = script_path.tr('/', "\\")
on host, powershell("", {"File" => native_path }), opts
end
end
@@ -489,11 +489,11 @@
# @param host [Beaker::Host] The target host
# @param file_path [String] The absolute path of the file
#
# @return [Boolean] Whether the file exists on the host (using `test -f`)
def file_exists_on(host, file_path)
- if host['platform'] =~ /windows/
+ if host[:platform].include?('windows')
command = %(Test-Path #{file_path})
if file_path.include?(':')
split_path = win_ads_path(file_path)
@@ -514,11 +514,11 @@
# @param host [Beaker::Host] The target host
# @param dir_path [String] The absolute path of the directory
#
# @return [Boolean] Whether the directory exists on the host (using `test -d`)
def directory_exists_on(host, dir_path)
- if host['platform'] =~ /windows/
+ if host[:platform].include?('windows')
dir_path = "#{dir_path}\\" unless (dir_path[-1].chr == '\\')
command = Command.new(%{IF exist "#{dir_path}" ( exit 0 ) ELSE ( exit 1 )}, [], { :cmdexe => true })
else
command = Command.new(%(test -d "#{dir_path}"), [])
@@ -533,11 +533,11 @@
# @param link_path [String] The absolute path of the symlink
#
# @return [Boolean] Whether the symlink exists on the host (using `test -L`)
def link_exists_on(host, link_path)
# Links are weird on windows, fall back to seeing if the file exists
- return file_exists_on(host, link_path) if host['platform'] =~ /windows/
+ return file_exists_on(host, link_path) if host[:platform].include?('windows')
return on(host, Command.new(%(test -L "#{link_path}"), accept_all_exit_codes: true)).exit_code.zero?
end
# Get the contents of a file on the host
@@ -549,12 +549,12 @@
def file_contents_on(host, file_path)
file_contents = nil
split_path = win_ads_path(file_path)
if file_exists_on(host, split_path[:path])
- if host['platform'] =~ /windows/
- file_path.gsub!('/', '\\')
+ if host[:platform].include?('windows')
+ file_path.tr!('/', '\\')
command = %{Get-Content -Raw -Path #{file_path}}
command += %{ -Stream #{split_path[:ads]}} if split_path[:ads]
file_contents = on(host, powershell(command))&.stdout&.strip
@@ -578,10 +578,10 @@
#
def curl_on(host, cmd, opts = {}, &block)
on host, "curl --tlsv1 %s" % cmd, opts, &block
end
- def curl_with_retries(desc, host, url, desired_exit_codes, max_retries = 60, retry_interval = 1)
+ def curl_with_retries(_desc, host, url, desired_exit_codes, max_retries = 60, retry_interval = 1)
opts = {
:desired_exit_codes => desired_exit_codes,
:max_retries => max_retries,
:retry_interval => retry_interval
}