Class: Beaker::Host
- Inherits:
-
Object
- Object
- Beaker::Host
- Includes:
- DSL::Helpers, DSL::Patterns
- Defined in:
- lib/beaker/host.rb
Direct Known Subclasses
Defined Under Namespace
Classes: CommandFailure, PuppetConfigReader, RebootFailure, RebootWarning
Constant Summary collapse
- SELECT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#host_hash ⇒ Object
readonly
Returns the value of attribute host_hash.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#[](k) ⇒ Object
Does this host have this key? Either as defined in the host itself, or globally?.
- #[]=(k, v) ⇒ Object
- #add_env_var(key, val) ⇒ Object
- #close ⇒ Object
- #connection ⇒ Object
- #delete(k) ⇒ Object
-
#do_rsync_to(from_path, to_path, opts = {}) ⇒ Rsync::Result
rsync a file or directory from the localhost to this test host.
- #do_scp_from(source, target, options) ⇒ Object
-
#do_scp_to(source, target_path, options) ⇒ Object
scp files from the localhost to this test host, if a directory is provided it is recursively copied.
- #exec(command, options = {}) ⇒ Object
-
#fips_mode? ⇒ Boolean
Returns true if the host is running in FIPS mode.
-
#get_ip ⇒ Object
Determine the ip address of this host.
-
#get_public_ip ⇒ Object
Determine the ip address using logic specific to the hypervisor.
-
#has_key?(k) ⇒ Boolean
Does this host have this key? Either as defined in the host itself, or globally?.
-
#hostname ⇒ Object
Return the public name of the particular host, which may be different then the name of the host provided in the configuration file as some provisioners create random, unique hostnames.
-
#initialize(name, host_hash, options) ⇒ Host
constructor
A new instance of Host.
- #install_package(package, cmdline_args = nil, _version = nil, opts = {}) ⇒ Object
-
#ip ⇒ Object
Return the ip address of this host Always pull fresh, because this can sometimes change.
- #is_cygwin? ⇒ Boolean
- #is_pe? ⇒ Boolean
- #is_powershell? ⇒ Boolean
-
#is_x86_64? ⇒ Boolean
True if x86_64, false otherwise.
- #log_prefix ⇒ Object
- #node_name ⇒ Object
- #path_split(paths) ⇒ Object
- #pkg_initialize ⇒ Object
- #platform ⇒ Object
- #port_open?(port) ⇒ Boolean
-
#puppet_configprint(command = 'agent') ⇒ Object
(also: #puppet)
Returning our PuppetConfigReader here allows users of the Host class to do things like ‘host.puppet` to query the ’main’ section or, if they want the configuration for a particular run type, ‘host.puppet(’agent’)‘.
-
#reachable_name ⇒ Object
Return the preferred method to reach the host, will use IP is available and then default to #hostname.
- #rm_rf(path) ⇒ Object
- #tmpdir(name = '') ⇒ Object
- #tmpfile(name = '') ⇒ Object
-
#to_s ⇒ Object
The #hostname of this host.
-
#to_str ⇒ Object
The #hostname of this host.
- #up? ⇒ Boolean
-
#wait_for_port(port, attempts = 15) ⇒ Object
Wait for a port on the host.
Methods included from DSL::Patterns
Methods included from DSL::Helpers::HoconHelpers
#hocon_file_edit_in_place_on, #hocon_file_edit_on, #hocon_file_read_on
Methods included from DSL::Helpers::WebHelpers
#link_exists?, #port_open_within?
Methods included from DSL::Helpers::TestHelpers
#current_step_name, #current_test_filename, #current_test_name, #set_current_step_name, #set_current_test_filename, #set_current_test_name
Methods included from DSL::Helpers::HostHelpers
#add_system32_hosts_entry, #archive_file_from, #backup_the_file, #check_for_package, #create_remote_file, #curl_on, #curl_with_retries, #directory_exists_on, #echo_on, #execute_powershell_script_on, #file_contents_on, #file_exists_on, #link_exists_on, #on, #retry_on, #rsync_to, #run_script, #run_script_on, #scp_from, #scp_to, #shell, #uninstall_package, #upgrade_package, #win_ads_path
Constructor Details
#initialize(name, host_hash, options) ⇒ Host
Returns a new instance of Host.
72 73 74 75 76 77 78 79 |
# File 'lib/beaker/host.rb', line 72 def initialize name, host_hash, @logger = host_hash[:logger] || [:logger] @name, @host_hash, @options = name.to_s, host_hash.dup, .dup @host_hash['packaging_platform'] ||= @host_hash['platform'] @host_hash = self.platform_defaults.merge(@host_hash) pkg_initialize end |
Instance Attribute Details
#host_hash ⇒ Object (readonly)
Returns the value of attribute host_hash.
70 71 72 |
# File 'lib/beaker/host.rb', line 70 def host_hash @host_hash end |
#logger ⇒ Object
Returns the value of attribute logger.
69 70 71 |
# File 'lib/beaker/host.rb', line 69 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
70 71 72 |
# File 'lib/beaker/host.rb', line 70 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
70 71 72 |
# File 'lib/beaker/host.rb', line 70 def @options end |
Class Method Details
.create(name, host_hash, options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/beaker/host.rb', line 45 def self.create name, host_hash, case host_hash['platform'] when /windows/ cygwin = host_hash['is_cygwin'] if cygwin.nil? or cygwin == true Windows::Host.new name, host_hash, else PSWindows::Host.new name, host_hash, end when /aix/ Aix::Host.new name, host_hash, when /osx/ Mac::Host.new name, host_hash, when /freebsd/ FreeBSD::Host.new name, host_hash, when /eos/ Eos::Host.new name, host_hash, when /cisco/ Cisco::Host.new name, host_hash, else Unix::Host.new name, host_hash, end end |
Instance Method Details
#+(other) ⇒ Object
176 177 178 |
# File 'lib/beaker/host.rb', line 176 def + other @name + other end |
#[](k) ⇒ Object
Does this host have this key? Either as defined in the host itself, or globally?
147 148 149 |
# File 'lib/beaker/host.rb', line 147 def [] k host_hash[k] || [k] end |
#[]=(k, v) ⇒ Object
142 143 144 |
# File 'lib/beaker/host.rb', line 142 def []= k, v host_hash[k] = v end |
#add_env_var(key, val) ⇒ Object
571 572 573 |
# File 'lib/beaker/host.rb', line 571 def add_env_var(key, val) raise NotImplementedError end |
#close ⇒ Object
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/beaker/host.rb', line 270 def close if @connection @connection.close # update connection information @connection.ip = self['ip'] if self['ip'] @connection.vmhostname = self['vmhostname'] if self['vmhostname'] @connection.hostname = @name end @connection = nil end |
#connection ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/beaker/host.rb', line 253 def connection # create new connection object if necessary if self['hypervisor'] == 'none' && @name == 'localhost' @connection ||= LocalConnection.connect({ :ssh_env_file => self['ssh_env_file'], :logger => @logger }) return @connection end @connection ||= SshConnection.connect({ :ip => self['ip'], :vmhostname => self['vmhostname'], :hostname => @name }, self['user'], self['ssh'], { :logger => @logger, :ssh_connection_preference => self[:ssh_connection_preference] }) # update connection information @connection.ip = self['ip'] if self['ip'] && (@connection.ip != self['ip']) @connection.vmhostname = self['vmhostname'] if self['vmhostname'] && (@connection.vmhostname != self['vmhostname']) @connection.hostname = @name if @name && (@connection.hostname != @name) @connection end |
#delete(k) ⇒ Object
156 157 158 |
# File 'lib/beaker/host.rb', line 156 def delete k host_hash.delete(k) end |
#do_rsync_to(from_path, to_path, opts = {}) ⇒ Rsync::Result
rsync a file or directory from the localhost to this test host
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/beaker/host.rb', line 482 def do_rsync_to from_path, to_path, opts = {} ssh_opts = self['ssh'] rsync_args = [] ssh_args = [] raise IOError, "No such file or directory - #{from_path}" if not File.file?(from_path) and not File.directory?(from_path) # We enable achieve mode and compression rsync_args << "-az" user = if not self['user'] "root" else self['user'] end hostname_with_user = "#{user}@#{reachable_name}" Rsync.host = hostname_with_user # vagrant uses temporary ssh configs in order to use dynamic keys # without this config option using ssh may prompt for password # # We still want any user-set SSH config to win though filesystem_ssh_config = nil if ssh_opts[:config] && File.exist?(ssh_opts[:config]) filesystem_ssh_config = ssh_opts[:config] elsif self[:vagrant_ssh_config] && File.exist?(self[:vagrant_ssh_config]) filesystem_ssh_config = self[:vagrant_ssh_config] end if filesystem_ssh_config ssh_args << "-F #{filesystem_ssh_config}" elsif ssh_opts.has_key?('keys') and ssh_opts.has_key?('auth_methods') and ssh_opts['auth_methods'].include?('publickey') key = Array(ssh_opts['keys']).find do |k| File.exist?(k) end if key # rsync doesn't always play nice with tilde, so be sure to expand first ssh_args << "-i #{File.(key)}" end # find the first SSH key that exists end ssh_args << "-p #{ssh_opts[:port]}" if ssh_opts.has_key?(:port) # We disable prompt when host isn't known ssh_args << "-o 'StrictHostKeyChecking no'" rsync_args << "-e \"ssh #{ssh_args.join(' ')}\"" if not ssh_args.empty? rsync_args << opts[:ignore].map { |value| "--exclude '#{value}'" }.join(' ') if opts.has_key?(:ignore) and not opts[:ignore].empty? # We assume that the *contents* of the directory 'from_path' needs to be # copied into the directory 'to_path' from_path += '/' if File.directory?(from_path) and not from_path.end_with?('/') @logger.notify "rsync: localhost:#{from_path} to #{hostname_with_user}:#{to_path} {:ignore => #{opts[:ignore]}}" result = Rsync.run(from_path, to_path, rsync_args) @logger.debug("rsync returned #{result.inspect}") return result if result.success? raise Beaker::Host::CommandFailure, result.error end |
#do_scp_from(source, target, options) ⇒ Object
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/beaker/host.rb', line 458 def do_scp_from source, target, # use the value of :dry_run passed to the method unless # undefined, then use parsed @options hash. [:dry_run] ||= @options[:dry_run] if [:dry_run] scp_cmd = "scp #{@name}:#{source} #{target}" @logger.debug "\n Running in :dry_run mode. localhost $ #{scp_cmd} not executed." return NullResult.new(self, scp_cmd) end @logger.debug "localhost $ scp #{@name}:#{source} #{target}" result = connection.scp_from(source, target, ) @logger.debug result.stdout return result end |
#do_scp_to(source, target_path, options) ⇒ Object
scp files from the localhost to this test host, if a directory is provided it is recursively copied. If the provided source is a directory both the contents of the directory and the directory itself will be copied to the host, if you only want to copy directory contents you will either need to specify the contents file by file or do a separate ‘mv’ command post scp_to to create the directory structure as desired. To determine if a file/dir is ‘ignored’ we compare to any contents of the source dir and NOT any part of the path to that source dir.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/beaker/host.rb', line 375 def do_scp_to source, target_path, target = self.scp_path(target_path) # use the value of :dry_run passed to the method unless # undefined, then use parsed @options hash. [:dry_run] ||= @options[:dry_run] if [:dry_run] scp_cmd = "scp #{source} #{@name}:#{target}" @logger.debug "\n Running in :dry_run mode. localhost $ #{scp_cmd} not executed." return NullResult.new(self, scp_cmd) end @logger.notify "localhost $ scp #{source} #{@name}:#{target} {:ignore => #{[:ignore]}}" result = Result.new(@name, [source, target]) has_ignore = [:ignore] and not [:ignore].empty? # construct the regex for matching ignored files/dirs ignore_re = nil if has_ignore ignore_arr = Array([:ignore]).map do |entry| "((\/|\\A)#{Regexp.escape(entry)}(\/|\\z))" end ignore_re = Regexp.new(ignore_arr.join('|')) @logger.debug("going to ignore #{ignore_re}") end # either a single file, or a directory with no ignores raise IOError, "No such file or directory - #{source}" if not File.file?(source) and not File.directory?(source) if File.file?(source) or (File.directory?(source) and not has_ignore) source_file = source if has_ignore and ignore_re&.match?(source) @logger.trace "After rejecting ignored files/dirs, there is no file to copy" source_file = nil result.stdout = "No files to copy" result.exit_code = 1 end if source_file result = connection.scp_to(source_file, target, ) @logger.trace result.stdout end else # a directory with ignores dir_source = Dir.glob("#{source}/**/*").reject do |f| ignore_re&.match?(f.gsub(/\A#{Regexp.escape(source)}/, '')) # only match against subdirs, not full path end @logger.trace "After rejecting ignored files/dirs, going to scp [#{dir_source.join(', ')}]" # create necessary directory structure on host # run this quietly (no STDOUT) @logger.quiet(true) required_dirs = (dir_source.map { |dir| File.dirname(dir) }).uniq require 'pathname' required_dirs.each do |dir| dir_path = Pathname.new(dir) if dir_path.absolute? and (File.dirname(File.absolute_path(source)).to_s != '/') mkdir_p(File.join(target, dir.gsub(/#{Regexp.escape(File.dirname(File.absolute_path(source)))}/, ''))) else mkdir_p(File.join(target, dir)) end end @logger.quiet(false) # copy each file to the host dir_source.each do |s| # Copy files, not directories (as they are copied recursively) next if File.directory?(s) s_path = Pathname.new(s) file_path = if s_path.absolute? and (File.dirname(File.absolute_path(source)).to_s != '/') File.join(target, File.dirname(s).gsub(/#{Regexp.escape(File.dirname(File.absolute_path(source)))}/, '')) else File.join(target, File.dirname(s)) end result = connection.scp_to(s, file_path, ) @logger.trace result.stdout end end self.scp_post_operations(target, target_path) return result end |
#exec(command, options = {}) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/beaker/host.rb', line 281 def exec command, = {} result = nil # I've always found this confusing cmdline = command.cmd_line(self) # use the value of :dry_run passed to the method unless # undefined, then use parsed @options hash. [:dry_run] ||= @options[:dry_run] if [:dry_run] @logger.debug "\n Running in :dry_run mode. Command #{cmdline} not executed." result = Beaker::NullResult.new(self, command) return result end if [:silent] output_callback = nil else @logger.debug "\n#{log_prefix} #{Time.new.strftime('%H:%M:%S')}$ #{cmdline}" output_callback = if @options[:color_host_output] logger.method(:color_host_output) else logger.method(:host_output) end end unless [:dry_run] # is this returning a result object? # the options should come at the end of the method signature (rubyism) # and they shouldn't be ssh specific seconds = Benchmark.realtime do @logger.with_indent do result = connection.execute(cmdline, , output_callback) end end @logger.debug "\n#{log_prefix} executed in %0.2f seconds" % seconds if not [:silent] if [:reset_connection] # Expect the connection to fail hard and possibly take a long time timeout. # Pre-emptively reset it so we don't wait forever. close return result end unless [:silent] # What? result.log(@logger) if ![:expect_connection_failure] && !result.exit_code # no exit code was collected, so the stream failed raise CommandFailure, "Host '#{self}' connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}" end if [:expect_connection_failure] && result.exit_code # should have had a connection failure, but didn't # wait to see if the connection failure will be generation, otherwise raise error if not connection.wait_for_connection_failure(, output_callback) raise CommandFailure, "Host '#{self}' should have resulted in a connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}" end end # No, TestCase has the knowledge about whether its failed, checking acceptable # exit codes at the host level and then raising... # is it necessary to break execution?? if [:accept_all_exit_codes] && [:acceptable_exit_codes] @logger.warn ":accept_all_exit_codes & :acceptable_exit_codes set. :acceptable_exit_codes overrides, but they shouldn't both be set at once" [:accept_all_exit_codes] = false end if ![:accept_all_exit_codes] && !result.exit_code_in?(Array([:acceptable_exit_codes] || [0, nil])) raise CommandFailure, "Host '#{self}' exited with #{result.exit_code} running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}" end end end result end |
#fips_mode? ⇒ Boolean
Returns true if the host is running in FIPS mode.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/beaker/host.rb', line 197 def fips_mode? if self.file_exist?('/proc/sys/crypto/fips_enabled') begin execute("cat /proc/sys/crypto/fips_enabled") == "1" rescue Beaker::Host::CommandFailure false end else false end end |
#get_ip ⇒ Object
Determine the ip address of this host
218 219 220 |
# File 'lib/beaker/host.rb', line 218 def get_ip @logger.warn("Uh oh, this should be handled by sub-classes but hasn't been") end |
#get_public_ip ⇒ Object
Determine the ip address using logic specific to the hypervisor
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/beaker/host.rb', line 223 def get_public_ip case host_hash[:hypervisor] when /^(ec2|openstack)$/ if self[:hypervisor] == 'ec2' && self[:instance] return self[:instance].ip_address elsif self[:hypervisor] == 'openstack' && self[:ip] return self[:ip] elsif self.instance_of?(Windows::Host) # In the case of using ec2 instances with the --no-provision flag, the ec2 # instance object does not exist and we should just use the curl endpoint # specified here: # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html execute("wget http://169.254.169.254/latest/meta-data/public-ipv4").strip else execute("curl http://169.254.169.254/latest/meta-data/public-ipv4").strip end end end |
#has_key?(k) ⇒ Boolean
Does this host have this key? Either as defined in the host itself, or globally?
152 153 154 |
# File 'lib/beaker/host.rb', line 152 def has_key? k host_hash.has_key?(k) || .has_key?(k) end |
#hostname ⇒ Object
Return the public name of the particular host, which may be different then the name of the host provided in the configuration file as some provisioners create random, unique hostnames.
172 173 174 |
# File 'lib/beaker/host.rb', line 172 def hostname host_hash['vmhostname'] || @name end |
#install_package(package, cmdline_args = nil, _version = nil, opts = {}) ⇒ Object
567 568 569 |
# File 'lib/beaker/host.rb', line 567 def install_package(package, cmdline_args = nil, _version = nil, opts = {}) raise NotImplementedError end |
#ip ⇒ Object
Return the ip address of this host Always pull fresh, because this can sometimes change
244 245 246 |
# File 'lib/beaker/host.rb', line 244 def ip self['ip'] = get_public_ip || get_ip end |
#is_cygwin? ⇒ Boolean
184 185 186 |
# File 'lib/beaker/host.rb', line 184 def is_cygwin? self.instance_of?(Windows::Host) end |
#is_pe? ⇒ Boolean
180 181 182 |
# File 'lib/beaker/host.rb', line 180 def is_pe? self['type'] && self['type'].to_s.include?('pe') end |
#is_powershell? ⇒ Boolean
188 189 190 |
# File 'lib/beaker/host.rb', line 188 def is_powershell? self.instance_of?(PSWindows::Host) end |
#is_x86_64? ⇒ Boolean
Returns true if x86_64, false otherwise.
249 250 251 |
# File 'lib/beaker/host.rb', line 249 def is_x86_64? @x86_64 ||= determine_if_x86_64 end |
#log_prefix ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/beaker/host.rb', line 209 def log_prefix if host_hash['vmhostname'] "#{self} (#{@name})" else self.to_s end end |
#node_name ⇒ Object
86 87 88 89 90 91 |
# File 'lib/beaker/host.rb', line 86 def node_name # TODO: might want to consider caching here; not doing it for now because # I haven't thought through all of the possible scenarios that could # cause the value to change after it had been cached. puppet_configprint['node_name_value'].strip end |
#path_split(paths) ⇒ Object
559 560 561 |
# File 'lib/beaker/host.rb', line 559 def path_split(paths) raise NotImplementedError end |
#pkg_initialize ⇒ Object
81 82 83 84 |
# File 'lib/beaker/host.rb', line 81 def pkg_initialize # This method should be overridden by platform-specific code to # handle whatever packaging-related initialization is necessary. end |
#platform ⇒ Object
192 193 194 |
# File 'lib/beaker/host.rb', line 192 def platform self['platform'] end |
#port_open?(port) ⇒ Boolean
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/beaker/host.rb', line 93 def port_open? port begin Timeout.timeout SELECT_TIMEOUT do TCPSocket.new(reachable_name, port).close return true end rescue Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, Errno::EHOSTUNREACH return false end end |
#puppet_configprint(command = 'agent') ⇒ Object Also known as: puppet
Returning our PuppetConfigReader here allows users of the Host class to do things like ‘host.puppet` to query the ’main’ section or, if they want the configuration for a particular run type, ‘host.puppet(’agent’)‘
137 138 139 |
# File 'lib/beaker/host.rb', line 137 def puppet_configprint(command = 'agent') PuppetConfigReader.new(self, command) end |
#reachable_name ⇒ Object
Return the preferred method to reach the host, will use IP is available and then default to #hostname.
129 130 131 |
# File 'lib/beaker/host.rb', line 129 def reachable_name self['ip'] || hostname end |
#rm_rf(path) ⇒ Object
563 564 565 |
# File 'lib/beaker/host.rb', line 563 def rm_rf(path) raise NotImplementedError end |
#tmpdir(name = '') ⇒ Object
555 556 557 |
# File 'lib/beaker/host.rb', line 555 def tmpdir(name = '') raise NotImplementedError end |
#tmpfile(name = '') ⇒ Object
551 552 553 |
# File 'lib/beaker/host.rb', line 551 def tmpfile(name = '') raise NotImplementedError end |
#to_s ⇒ Object
The #hostname of this host.
166 167 168 |
# File 'lib/beaker/host.rb', line 166 def to_s hostname end |
#to_str ⇒ Object
The #hostname of this host.
161 162 163 |
# File 'lib/beaker/host.rb', line 161 def to_str hostname end |
#up? ⇒ Boolean
119 120 121 122 123 124 125 126 |
# File 'lib/beaker/host.rb', line 119 def up? begin Socket.getaddrinfo(reachable_name, nil) return true rescue SocketError return false end end |
#wait_for_port(port, attempts = 15) ⇒ Object
Wait for a port on the host. Useful for those occasions when you’ve called host.reboot and want to avoid spam from subsequent SSH connections retrying to connect from say retry_on()
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/beaker/host.rb', line 107 def wait_for_port(port, attempts = 15) @logger.debug(" Waiting for port #{port} ... ", false) start = Time.now done = repeat_fibonacci_style_for(attempts) { port_open?(port) } if done @logger.debug(format('connected in %0.2f seconds', (Time.now - start))) else @logger.debug('timeout') end done end |