Class: Beaker::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/beaker/host.rb

Direct Known Subclasses

Mac::Host, PSWindows::Host, Unix::Host, Windows::Host

Defined Under Namespace

Classes: CommandFailure, PuppetConfigReader

Constant Summary collapse

SELECT_TIMEOUT =
30

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Host

Returns a new instance of Host.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/beaker/host.rb', line 51

def initialize name, options
  @logger = options[:logger]
  @name, @options = name.to_s, options.dup

  # This is annoying and its because of drift/lack of enforcement/lack of having
  # a explict relationship between our defaults, our setup steps and how they're
  # related through 'type' and the differences between the assumption of our two
  # configurations we have for many of our products
  type = @options.get_type
  @defaults = merge_defaults_for_type @options, type
  pkg_initialize
end

Instance Attribute Details

#defaultsObject (readonly)

Returns the value of attribute defaults.



50
51
52
# File 'lib/beaker/host.rb', line 50

def defaults
  @defaults
end

#loggerObject

Returns the value of attribute logger.



49
50
51
# File 'lib/beaker/host.rb', line 49

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



50
51
52
# File 'lib/beaker/host.rb', line 50

def name
  @name
end

Class Method Details

.create(name, options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/beaker/host.rb', line 29

def self.create name, options
  case options['HOSTS'][name]['platform']
  when /windows/
    cygwin = options['HOSTS'][name]['is_cygwin']
    if cygwin.nil? or cygwin == true
      Windows::Host.new name, options
    else
      PSWindows::Host.new name, options
    end
  when /aix/
    Aix::Host.new name, options
  when /osx/
    Mac::Host.new name, options
  when /freebsd/
    FreeBSD::Host.new name, options
  else
    Unix::Host.new name, options
  end
end

Instance Method Details

#+(other) ⇒ Object



165
166
167
# File 'lib/beaker/host.rb', line 165

def + other
  @name + other
end

#[](k) ⇒ Object



138
139
140
141
142
143
# File 'lib/beaker/host.rb', line 138

def [] k
  @deprecated_keys ||= build_deprecated_keys()
  deprecation_message = "deprecated host key '#{k}'. Perhaps you can use host.puppet[] to get what you're looking for."
  @logger.warn( deprecation_message ) if @logger && @deprecated_keys.include?(k.to_sym)
  @defaults[k]
end

#[]=(k, v) ⇒ Object



134
135
136
# File 'lib/beaker/host.rb', line 134

def []= k, v
  @defaults[k] = v
end

#add_env_var(key, val) ⇒ Object

Add the provided key/val to the current ssh environment

Examples:

host.add_env_var('PATH', '/usr/bin:PATH')

Parameters:

  • key (String)

    The key to add the value to

  • val (String)

    The value for the key



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
# File 'lib/beaker/host.rb', line 286

def add_env_var key, val
  key = key.to_s.upcase
  if self.is_cygwin?
    env_file = self[:ssh_env_file]
    escaped_val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
    #see if the key/value pair already exists
    if exec(Beaker::Command.new("grep #{key}=.*#{escaped_val} #{env_file}"), :acceptable_exit_codes => (0..255) ).exit_code == 0
      return #nothing to do here, key value pair already exists
    #see if the key already exists
    elsif exec(Beaker::Command.new("grep #{key} #{env_file}"), :acceptable_exit_codes => (0..255) ).exit_code == 0
      exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=/#{key}=#{escaped_val}:/", env_file))
    else
      exec(Beaker::Command.new("echo \"#{key}=#{val}\" >> #{env_file}"))
    end
    #update the profile.d to current state
    #match it to the contents of ssh_env_file
    mirror_env_to_profile_d(env_file)
  else #powershell windows
    #see if the key/value pair already exists
    result = exec(Beaker::Command.new("set #{key}"), :acceptable_exit_codes => (0..255))
    subbed_result = result.stdout.chomp
    if result.exit_code == 0
      subbed_result = subbed_result.gsub(/#{Regexp.escape(val.gsub(/'|"/, ''))}/, '')
    end
    #not present, add it
    if subbed_result == result.stdout.chomp
      exec(Beaker::Command.new("setx /M #{key} %#{key}%;#{val}"))
      exec(Beaker::Command.new("set #{key}=%#{key}%;#{val}"))
    end
  end
end

#build_deprecated_keysArray<Symbol>

Note:

an unsupported host type (meaning it has no aio_defaults) will return an empty hash

Builds a deprecated keys array, for checking to see if a key is deprecated. The recommended check after using this method is result.include?(key)

Returns:

  • (Array<Symbol>)

    An array of keys that are deprecated for a host



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/beaker/host.rb', line 71

def build_deprecated_keys()
  begin
    deprecated_keys_hash = self.class.send "foss_defaults".to_sym
    delete_exceptions_hash = self.class.send "aio_defaults".to_sym
    deprecated_keys_hash.delete_if do |key, value|
      delete_exceptions_hash.has_key?(key)
    end
  rescue NoMethodError
    deprecated_keys_hash = {}
  end
  deprecated_keys_hash.keys()
end

#closeObject



366
367
368
369
# File 'lib/beaker/host.rb', line 366

def close
  @connection.close if @connection
  @connection = nil
end

#connectionObject



360
361
362
363
364
# File 'lib/beaker/host.rb', line 360

def connection
  @connection ||= SshConnection.connect( reachable_name,
                                         self['user'],
                                         self['ssh'], { :logger => @logger } )
end

#delete_env_var(key, val) ⇒ Object

Delete the provided key/val from the current ssh environment

Examples:

host.delete_env_var('PATH', '/usr/bin:PATH')

Parameters:

  • key (String)

    The key to delete the value from

  • val (String)

    The value to delete for the key



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
357
358
# File 'lib/beaker/host.rb', line 332

def delete_env_var key, val
  key = key.to_s.upcase
  if self.is_cygwin?
    env_file = self[:ssh_env_file]
    val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
    #if the key only has that single value remove the entire line
    exec(Beaker::SedCommand.new(self['platform'], "/#{key}=#{val}$/d", env_file))
    #value in middle of list
    exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=\\(.*\\)[;:]#{val}/#{key}=\\1/", env_file))
    #value in start of list
    exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=#{val}[;:]/#{key}=/", env_file))
    #update the profile.d to current state
    #match it to the contents of ssh_env_file
    mirror_env_to_profile_d(env_file)
  else #powershell windows
    #get the current value of the key
    result = exec(Beaker::Command.new("set #{key}"), :acceptable_exit_codes => (0..255))
    subbed_result = result.stdout.chomp
    if result.exit_code == 0
      subbed_result = subbed_result.gsub(/#{Regexp.escape(val.gsub(/'|"/, ''))}/, '')
    end
    if subbed_result != result
      #set to the truncated value
      self.add_env_var(key, subbed_result)
    end
  end
end

#determine_if_x86_64Boolean

Examine the host system to determine the architecture

Returns:

  • (Boolean)

    true if x86_64, false otherwise



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/beaker/host.rb', line 238

def determine_if_x86_64
  if is_cygwin?
    if self[:platform] =~ /osx|solaris/
      result = exec(Beaker::Command.new("uname -a | grep x86_64"), :acceptable_exit_codes => (0...127))
      result.exit_code == 0
    else
      result = exec(Beaker::Command.new("arch | grep x86_64"), :acceptable_exit_codes => (0...127))
      result.exit_code == 0
    end
  else
    result = exec(Beaker::Command.new("wmic os get osarchitecture"), :acceptable_exit_codes => (0...127))
    result.stdout =~ /64/
  end
end

#do_rsync_to(from_path, to_path, opts = {}) ⇒ Object

rsync a file or directory from the localhost to this test host

Parameters:

  • from_path (String)

    The path to the file/dir to upload

  • to_path (String)

    The destination path on the host

  • opts (Hash{Symbol=>String}) (defaults to: {})

    Options to alter execution

Options Hash (opts):

  • :ignore (Array<String>)

    An array of file/dir paths that will not be copied to the host



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/beaker/host.rb', line 540

def do_rsync_to from_path, to_path, opts = {}
  ssh_opts = self['ssh']
  rsync_args = []
  ssh_args = []

  if not File.file?(from_path) and not File.directory?(from_path)
    raise IOError, "No such file or directory - #{from_path}"
  end

  # We enable achieve mode and compression
  rsync_args << "-az"

  if not self['user']
    user = "root"
  else
    user = self['user']
  end
  hostname_with_user = "#{user}@#{self}"

  Rsync.host = hostname_with_user

  if ssh_opts.has_key?('keys') and
    ssh_opts.has_key?('auth_methods') and
    ssh_opts['auth_methods'].include?('publickey')

    key = ssh_opts['keys']

    # If an array was set, then we use the first value
    if key.is_a? Array
      key = key.first
    end

    # We need to expand tilde manually as rsync can be
    # funny sometimes
    key = File.expand_path(key)

    ssh_args << "-i #{key}"
  end

  if ssh_opts.has_key?('port') and
    ssh_args << "-p #{ssh_opts['port']}"
  end

  # We disable prompt when host isn't known
  ssh_args << "-o 'StrictHostKeyChecking no'"

  if not ssh_args.empty?
    rsync_args << "-e \"ssh #{ssh_args.join(' ')}\""
  end

  if opts.has_key?(:ignore) and not opts[:ignore].empty?
    opts[:ignore].map! do |value|
      "--exclude '#{value}'"
    end
    rsync_args << opts[:ignore].join(' ')
  end

  # We assume that the *contents* of the directory 'from_path' needs to be
  # copied into the directory 'to_path'
  if File.directory?(from_path) and not from_path.end_with?('/')
    from_path += '/'
  end

  @logger.notify "rsync: localhost:#{from_path} to #{hostname_with_user}:#{to_path} {:ignore => #{opts[:ignore]}}"
  result = Rsync.run(from_path, to_path, rsync_args)
  result
end

#do_scp_from(source, target, options) ⇒ Object



527
528
529
530
531
532
533
# File 'lib/beaker/host.rb', line 527

def do_scp_from source, target, options

  @logger.debug "localhost $ scp #{@name}:#{source} #{target}"
  result = connection.scp_from(source, target, options, $dry_run)
  @logger.debug result.stdout
  return result
end

#do_scp_to(source, target, 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.

Examples:

do_scp_to('source/dir1/dir2/dir3', 'target')
-> will result in creation of target/source/dir1/dir2/dir3 on host

do_scp_to('source/file.rb', 'target', { :ignore => 'file.rb' }
-> will result in not files copyed to the host, all are ignored

Parameters:

  • source (String)

    The path to the file/dir to upload

  • target (String)

    The destination path on the host

  • options (Hash{Symbol=>String})

    Options to alter execution

Options Hash (options):

  • :ignore (Array<String>)

    An array of file/dir paths that will not be copied to the host



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
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
# File 'lib/beaker/host.rb', line 459

def do_scp_to source, target, options
  @logger.notify "localhost $ scp #{source} #{@name}:#{target} {:ignore => #{options[:ignore]}}"

  result = Result.new(@name, [source, target])
  has_ignore = options[:ignore] and not options[:ignore].empty?
  # construct the regex for matching ignored files/dirs
  ignore_re = nil
  if has_ignore
    ignore_arr = Array(options[: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
  if not File.file?(source) and not File.directory?(source)
    raise IOError, "No such file or directory - #{source}"
  end
  if File.file?(source) or (File.directory?(source) and not has_ignore)
    source_file = source
    if has_ignore and (source =~ ignore_re)
      @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, options, $dry_run)
      @logger.trace result.stdout
    end
  else # a directory with ignores
    dir_source = Dir.glob("#{source}/**/*").reject do |f|
      f.gsub(/\A#{Regexp.escape(source)}/, '') =~ ignore_re #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?
        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|
      s_path = Pathname.new(s)
      if s_path.absolute?
        file_path = File.join(target, File.dirname(s).gsub(/#{Regexp.escape(File.dirname(File.absolute_path(source)))}/,''))
      else
        file_path = File.join(target, File.dirname(s))
      end
      result = connection.scp_to(s, file_path, options, $dry_run)
      @logger.trace result.stdout
    end
  end

  return result
end

#exec(command, options = {}) ⇒ Object



371
372
373
374
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
# File 'lib/beaker/host.rb', line 371

def exec command, options={}
  # I've always found this confusing
  cmdline = command.cmd_line(self)

  if options[:silent]
    output_callback = nil
  else
    @logger.debug "\n#{log_prefix} #{Time.new.strftime('%H:%M:%S')}$ #{cmdline}"
    output_callback = logger.method(:host_output)
  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
    result = nil

    seconds = Benchmark.realtime {
      result = connection.execute(cmdline, options, output_callback)
    }

    if not options[:silent]
      @logger.debug "\n#{log_prefix} executed in %0.2f seconds" % seconds
    end

    unless options[:silent]
      # What?
      result.log(@logger)
      if !options[: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 options[:expect_connection_failure] && result.exit_code
        # should have had a connection failure, but didn't
        # this can happen because of timing issues, so just raise a warning for now
        @logger.warn "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
      # 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 !options[:accept_all_exit_codes] && !result.exit_code_in?(Array(options[: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
    # Danger, so we have to return this result?
    result
  end
end

#get_env_var(key) ⇒ Object

Return the value of a specific env var

Examples:

host.get_env_var('path')

Parameters:

  • key (String)

    The key to look for



322
323
324
325
# File 'lib/beaker/host.rb', line 322

def get_env_var key
  key = key.to_s.upcase
  exec(Beaker::Command.new("env | grep #{key}"), :acceptable_exit_codes => (0..255)).stdout.chomp
end

#get_ipObject

Determine the ip address of this host



227
228
229
# File 'lib/beaker/host.rb', line 227

def get_ip
  @logger.warn("Uh oh, this should be handled by sub-classes but hasn't been")
end

#graceful_restarts?Boolean

Mirrors the true/false value of the host’s ‘graceful-restarts’ property, or falls back to the value of is_using_passenger? if ‘graceful-restarts’ is nil, but only if this is not a PE run (foss only).

Returns:

  • (Boolean)


189
190
191
192
193
194
195
196
197
# File 'lib/beaker/host.rb', line 189

def graceful_restarts?
  graceful =
  if !self['graceful-restarts'].nil?
    self['graceful-restarts']
  else
    !is_pe? && is_using_passenger?
  end
  graceful
end

#has_key?(k) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/beaker/host.rb', line 145

def has_key? k
  @defaults.has_key?(k)
end

#hostnameObject

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.



161
162
163
# File 'lib/beaker/host.rb', line 161

def hostname
  @defaults['vmhostname'] || @name
end

#ipObject

Return the ip address of this host



232
233
234
# File 'lib/beaker/host.rb', line 232

def ip
  self[:ip] ||= get_ip
end

#is_cygwin?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/beaker/host.rb', line 173

def is_cygwin?
  self['is_cygwin'] == nil || self['is_cygwin'] == true
end

#is_pe?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/beaker/host.rb', line 169

def is_pe?
  @options.is_pe?
end

#is_using_passenger?Boolean

True if this is a PE run, or if the host’s ‘passenger’ property has been set.

Returns:

  • (Boolean)


214
215
216
# File 'lib/beaker/host.rb', line 214

def is_using_passenger?
  is_pe? || self['passenger']
end

#is_x86_64?Boolean

Returns true if x86_64, false otherwise.

Returns:

  • (Boolean)

    true if x86_64, false otherwise



254
255
256
# File 'lib/beaker/host.rb', line 254

def is_x86_64?
  @x86_64 ||= determine_if_x86_64
end

#log_prefixObject



218
219
220
221
222
223
224
# File 'lib/beaker/host.rb', line 218

def log_prefix
  if @defaults['vmhostname']
    "#{self} (#{@name})"
  else
    self.to_s
  end
end

#merge_defaults_for_type(options, type) ⇒ Object



89
90
91
92
# File 'lib/beaker/host.rb', line 89

def merge_defaults_for_type options, type
  defaults = self.class.send "#{type}_defaults".to_sym
  defaults.merge(options.merge((options['HOSTS'][name])))
end

#mirror_env_to_profile_d(env_file) ⇒ Object

Converts the provided environment file to a new shell script in /etc/profile.d, then sources that file. This is for sles based hosts.

Parameters:

  • env_file (String)

    The ssh environment file to read from



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/beaker/host.rb', line 261

def mirror_env_to_profile_d env_file
  if self[:platform] =~ /sles-/
    @logger.debug("mirroring environment to /etc/profile.d on sles platform host")
    cur_env = exec(Beaker::Command.new("cat #{env_file}")).stdout
    shell_env = ''
    cur_env.each_line do |env_line|
      shell_env << "export #{env_line}"
    end
    #here doc it over
    exec(Beaker::Command.new("cat << EOF > #{self[:profile_d_env_file]}\n#{shell_env}EOF"))
    #set permissions
    exec(Beaker::Command.new("chmod +x #{self[:profile_d_env_file]}"))
    #keep it current
    exec(Beaker::Command.new("source #{self[:profile_d_env_file]}"))
  else
    #noop
    @logger.debug("will not mirror environment to /etc/profile.d on non-sles platform host")
  end
end

#mkdir_p(dir) ⇒ Boolean

Create the provided directory structure on the host

Parameters:

  • dir (String)

    The directory structure to create on the host

Returns:

  • (Boolean)

    True, if directory construction succeeded, otherwise False



430
431
432
433
434
435
436
437
438
439
440
# File 'lib/beaker/host.rb', line 430

def mkdir_p dir
  if self.is_cygwin?
    cmd = "mkdir -p #{dir}"
  else
    windows_dirstring = dir.gsub('/','\\')
    cmd = "if not exist #{windows_dirstring} (md #{windows_dirstring})"
  end

  result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
  result.exit_code == 0
end

#node_nameObject



94
95
96
97
98
99
# File 'lib/beaker/host.rb', line 94

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.
  result = puppet['node_name_value'].strip
end

#pkg_initializeObject



84
85
86
87
# File 'lib/beaker/host.rb', line 84

def pkg_initialize
  # This method should be overridden by platform-specific code to
  # handle whatever packaging-related initialization is necessary.
end

#platformObject



177
178
179
# File 'lib/beaker/host.rb', line 177

def platform
  self['platform']
end

#port_open?(port) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
107
108
109
110
# File 'lib/beaker/host.rb', line 101

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
    return false
  end
end

#puppet(command = 'agent') ⇒ Object

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’)



130
131
132
# File 'lib/beaker/host.rb', line 130

def puppet(command='agent')
  PuppetConfigReader.new(self, command)
end

#reachable_nameObject

Return the preferred method to reach the host, will use IP is available and then default to #hostname.



122
123
124
# File 'lib/beaker/host.rb', line 122

def reachable_name
  self['ip'] || hostname
end

#rm_rf(path) ⇒ Object

Recursively remove the path provided

Parameters:

  • path (String)

    The path to remove



423
424
425
# File 'lib/beaker/host.rb', line 423

def rm_rf path
  exec(Beaker::Command.new("rm -rf #{path}"))
end

#to_sObject

The #hostname of this host.



155
156
157
# File 'lib/beaker/host.rb', line 155

def to_s
  hostname
end

#to_strObject

The #hostname of this host.



150
151
152
# File 'lib/beaker/host.rb', line 150

def to_str
  hostname
end

#up?Boolean

Returns:

  • (Boolean)


112
113
114
115
116
117
118
119
# File 'lib/beaker/host.rb', line 112

def up?
  begin
    Socket.getaddrinfo( reachable_name, nil )
    return true
  rescue SocketError
    return false
  end
end

#use_service_scripts?Boolean

True if this is a pe run, or if the host has had a ‘use-service’ property set.

Returns:

  • (Boolean)


182
183
184
# File 'lib/beaker/host.rb', line 182

def use_service_scripts?
  is_pe? || self['use-service']
end

#uses_passenger!(puppetservice = 'apache2') ⇒ Object

Modifies the host settings to indicate that it will be using passenger service scripts, (apache2) by default. Does nothing if this is a PE host, since it is already using passenger.

Parameters:

  • puppetservice (String) (defaults to: 'apache2')

    Name of the service script that should be called to stop/startPuppet on this host. Defaults to ‘apache2’.



204
205
206
207
208
209
210
211
# File 'lib/beaker/host.rb', line 204

def uses_passenger!(puppetservice = 'apache2')
  if !is_pe?
    self['passenger'] = true
    self['puppetservice'] = puppetservice
    self['use-service'] = true
  end
  return true
end