Module: Beaker::HostPrebuiltSteps

Includes:
DSL::Patterns
Included in:
Hypervisor
Defined in:
lib/beaker/host_prebuilt_steps.rb

Overview

Provides convienience methods for commonly run actions on hosts

Constant Summary collapse

NTPSERVER =
'pool.ntp.org'
SLEEPWAIT =
5
TRIES =
5
UNIX_PACKAGES =
['curl', 'ntpdate']
WINDOWS_PACKAGES =
['curl']
SLES_PACKAGES =
['curl', 'ntp']
DEBIAN_PACKAGES =
['curl', 'ntpdate', 'lsb-release']
CUMULUS_PACKAGES =
['addons', 'ntpdate', 'lsb-release']
ETC_HOSTS_PATH =
"/etc/hosts"
ETC_HOSTS_PATH_SOLARIS =
"/etc/inet/hosts"
ROOT_KEYS_SCRIPT =
"https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
ROOT_KEYS_SYNC_CMD =
"curl -k -o - -L #{ROOT_KEYS_SCRIPT} %s"
APT_CFG =
%q{ Acquire::http::Proxy "http://proxy.puppetlabs.net:3128/"; }
IPS_PKG_REPO =
"http://solaris-11-internal-repo.delivery.puppetlabs.net"

Instance Method Summary collapse

Methods included from DSL::Patterns

#block_on

Instance Method Details

#add_el_extras(host, opts) ⇒ Object

Install EPEL on host or hosts with platform = /el-(5|6)/. Do nothing on host or hosts of other platforms.

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon. Will use individual host epel_url, epel_arch and epel_pkg before using defaults provided in opts.

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):

  • :debug (Boolean)

    If true, print verbose rpm information when installing EPEL

  • :logger (Beaker::Logger)

    A Logger object

  • :epel_url (String)

    Link to download from

  • :epel_arch (String)

    Architecture of epel to download (i386, x86_64, etc)

  • :epel_6_pkg (String)

    Package to download from provided link for el-6

  • :epel_5_pkg (String)

    Package to download from provided link for el-5



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/beaker/host_prebuilt_steps.rb', line 240

def add_el_extras( host, opts )
  #add_el_extras
  #only supports el-* platforms
  logger = opts[:logger]
  debug_opt = opts[:debug] ? 'vh' : ''
  block_on host do |host|
    case
    when el_based?(host) && ['5','6'].include?(host['platform'].version)
      result = host.exec(Command.new('rpm -qa | grep epel-release'), :acceptable_exit_codes => [0,1])
      if result.exit_code == 1
        url, arch, pkg = epel_info_for host, opts
        host.exec(Command.new("rpm -i#{debug_opt} #{url}/#{arch}/#{pkg}"))
        #update /etc/yum.repos.d/epel.repo for new baseurl
        host.exec(Command.new("sed -i -e 's;#baseurl.*$;baseurl=#{Regexp.escape(url)}/\$basearch;' /etc/yum.repos.d/epel.repo"))
        #remove mirrorlist
        host.exec(Command.new("sed -i -e '/mirrorlist/d' /etc/yum.repos.d/epel.repo"))
        host.exec(Command.new('yum clean all && yum makecache'))
      end
    else
      logger.debug "#{host}: package repo configuration not modified"
    end
  end
rescue => e
  report_and_raise(logger, e, "add_repos")
end

#additive_hash_merge(h1, h2) ⇒ Hash

Merge the two provided hashes so that an array of values is created from collisions

Examples:

> h1 = {:PATH=>"/1st/path"}
> h2 = {:PATH=>"/2nd/path"}
> additive_hash_merge(h1, h2)
=> {:PATH=>["/1st/path", "/2nd/path"]}

Parameters:

  • h1 (Hash)

    The first hash

  • h2 (Hash)

    The second hash

Returns:

  • (Hash)

    A merged hash with arrays of values where collisions between the two hashes occured.



418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/beaker/host_prebuilt_steps.rb', line 418

def additive_hash_merge h1, h2
  merged_hash = {}
  normalized_h2 = h2.inject({}) { |h, (k, v)| h[k.to_s.upcase] = v; h }
  h1.each_pair do |key, val|
    normalized_key = key.to_s.upcase
    if normalized_h2.has_key?(normalized_key)
      merged_hash[key] = [h1[key], normalized_h2[normalized_key]]
      merged_hash[key] = merged_hash[key].uniq #remove dupes
    end
  end
  merged_hash
end

#apt_get_update(hosts) ⇒ Object

Run ‘apt-get update’ on the provided host or hosts. If the platform of the provided host is not ubuntu, debian or cumulus: do nothing.

Parameters:

  • hosts (Host, Array<Host>)

    One or more hosts to act upon



179
180
181
182
183
184
185
# File 'lib/beaker/host_prebuilt_steps.rb', line 179

def apt_get_update hosts
  block_on hosts do |host|
    if host[:platform] =~ /ubuntu|debian|cumulus/
      host.exec(Command.new("apt-get update"))
    end
  end
end

#check_and_install_packages_if_needed(host, package_list) ⇒ Object

Installs the given packages if they aren’t already on a host

Parameters:

  • host (Host)

    Host to act on

  • package_list (Array<String>)

    List of package names to install



106
107
108
109
110
111
112
# File 'lib/beaker/host_prebuilt_steps.rb', line 106

def check_and_install_packages_if_needed host, package_list
  package_list.each do |pkg|
    if not host.check_for_package pkg
      host.install_package pkg
    end
  end
end

#construct_env(host, opts) ⇒ Hash

Create the hash of default environment from host (:host_env), global options hash (:host_env) and default PE/Foss puppet variables

Parameters:

  • host (Host)

    The host to construct the environment hash for, host specific environment should be in :host_env in a hash

  • opts (Hash)

    Hash of options, including optional global host_env to be applied to each provided host

Returns:

  • (Hash)

    A hash of environment variables for provided host



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/beaker/host_prebuilt_steps.rb', line 443

def construct_env host, opts
  env = additive_hash_merge(host[:host_env], opts[:host_env])

  #Add PATH and RUBYLIB

  #prepend any PATH already set for this host

  env['PATH'] = (%w(puppetbindir facterbindir hierabindir) << env['PATH']).compact.reject(&:empty?)
  #get the PATH defaults
  env['PATH'].map! { |val| host[val] }
  env['PATH'] = env['PATH'].compact.reject(&:empty?)
  #run the paths through echo to see if they have any subcommands that need processing
  env['PATH'].map! { |val| echo_on_host(host, val) }

  #prepend any RUBYLIB already set for this host
  env['RUBYLIB'] =  (%w(hieralibdir hierapuppetlibdir pluginlibpath puppetlibdir facterlibdir) << env['RUBYLIB']).compact.reject(&:empty?)
  #get the RUBYLIB defaults
  env['RUBYLIB'].map! { |val| host[val] }
  env['RUBYLIB'] = env['RUBYLIB'].compact.reject(&:empty?)
  #run the paths through echo to see if they have any subcommands that need processing
  env['RUBYLIB'].map! { |val| echo_on_host(host, val) }

  env.each_key do |key|
    env[key] = env[key].join(':')
  end
  env
end

#copy_file_to_remote(host, file_path, file_content) ⇒ Object

Create a file on host or hosts at the provided file path with the provided file contents.

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • file_path (String)

    The path at which the new file will be created on the host or hosts.

  • file_content (String)

    The contents of the file to be created on the host or hosts.



191
192
193
194
195
196
197
198
199
# File 'lib/beaker/host_prebuilt_steps.rb', line 191

def copy_file_to_remote(host, file_path, file_content)
  block_on host do |host|
    Tempfile.open 'beaker' do |tempfile|
      File.open(tempfile.path, 'w') {|file| file.puts file_content }

      host.do_scp_to(tempfile.path, file_path, @options)
    end
  end
end

#copy_ssh_to_root(host, opts) ⇒ Object

Make it possible to log in as root by copying the current users ssh keys to the root account

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/beaker/host_prebuilt_steps.rb', line 301

def copy_ssh_to_root host, opts
  logger = opts[:logger]
  block_on host do |host|
    logger.debug "Give root a copy of current user's keys, on #{host.name}"
    if host['platform'] =~ /windows/
      host.exec(Command.new('cp -r .ssh /cygdrive/c/Users/Administrator/.'))
      host.exec(Command.new('chown -R Administrator /cygdrive/c/Users/Administrator/.ssh'))
    else
      host.exec(Command.new('sudo su -c "cp -r .ssh /root/."'), {:pty => true})
    end
  end
end

#disable_iptables(host, opts) ⇒ Object

Disable iptables on centos, does nothing on other platforms

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



374
375
376
377
378
379
380
381
382
383
384
# File 'lib/beaker/host_prebuilt_steps.rb', line 374

def disable_iptables host, opts
  logger = opts[:logger]
  block_on host do |host|
    if host['platform'] =~ /centos|el-|redhat|fedora|eos/
      logger.debug("Disabling iptables on #{host.name}")
      host.exec(Command.new("sudo su -c \"/etc/init.d/iptables stop\""), {:pty => true})
    else
      logger.warn("Attempting to disable iptables on non-supported platform: #{host.name}: #{host['platform']}")
    end
  end
end

#disable_se_linux(host, opts) ⇒ Object

Disable SELinux on centos, does nothing on other platforms

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



358
359
360
361
362
363
364
365
366
367
368
# File 'lib/beaker/host_prebuilt_steps.rb', line 358

def disable_se_linux host, opts
  logger = opts[:logger]
  block_on host do |host|
    if host['platform'] =~ /centos|el-|redhat|fedora|eos/
      @logger.debug("Disabling se_linux on #{host.name}")
      host.exec(Command.new("sudo su -c \"setenforce 0\""), {:pty => true})
    else
      @logger.warn("Attempting to disable SELinux on non-supported platform: #{host.name}: #{host['platform']}")
    end
  end
end

#echo_on_host(host, val) ⇒ Object

‘echo’ the provided value on the given host

Parameters:

  • host (Host)

    The host to execute the ‘echo’ on

  • val (String)

    The string to ‘echo’ on the host



434
435
436
437
# File 'lib/beaker/host_prebuilt_steps.rb', line 434

def echo_on_host host, val
  #val = val.gsub(/"/, "\"").gsub(/\(/, "\(")
  host.exec(Command.new("echo \"#{val}\"")).stdout.chomp
end

#enable_root_login(host, opts) ⇒ Object

Update sshd_config on debian, ubuntu, centos, el, redhat, cumulus, and fedora boxes to allow for root login

Does nothing on other platfoms.

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/beaker/host_prebuilt_steps.rb', line 336

def  host, opts
  logger = opts[:logger]
  block_on host do |host|
    logger.debug "Update /etc/ssh/sshd_config to allow root login"
    # note: this sed command only works on gnu sed
    host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), {:pty => true}
    )
    #restart sshd
    if host['platform'] =~ /debian|ubuntu|cumulus/
      host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true})
    elsif host['platform'] =~ /centos|el-|redhat|fedora|eos/
      host.exec(Command.new("sudo -E service sshd restart"))
    else
      @logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}")
    end
  end
end

#epel_info_for(host, opts) ⇒ String

Determine the Extra Packages for Enterprise Linux URL for the provided Enterprise Linux host.

Parameters:

  • host (Host, Array<Host>)

    One host to act on. Will use host epel_url, epel_arch and epel_pkg before using defaults provided in opts.

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):

  • :epel_url (String)

    Link to download

  • :epel_arch (String)

    Architecture to download (i386, x86_64, etc), defaults to i386

  • :epel_6_pkg (String)

    Package to download from provided link for el-6

  • :epel_5_pkg (String)

    Package to download from provided link for el-5

Returns:

  • (String, String, String)

    The URL, arch and package name for EPL for the provided host

Raises:

  • (Exception)

    Raises an error if the host provided’s platform != /el-(5|6)/



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/beaker/host_prebuilt_steps.rb', line 157

def epel_info_for host, opts
  if !el_based?(host)
    raise "epel_info_for! not available for #{host.name} on platform #{host['platform']}"
  end

  version = host['platform'].version
  if version == '6'
    url = "#{host[:epel_url] || opts[:epel_url]}/#{version}"
    pkg = host[:epel_pkg] || opts[:epel_6_pkg]
  elsif version == '5'
    url = "#{host[:epel_url] || opts[:epel_url]}/#{version}"
    pkg = host[:epel_pkg] || opts[:epel_5_pkg]
  else
    raise "epel_info_for does not support el version #{version}, on #{host.name}"
  end
  return url, host[:epel_arch] || opts[:epel_arch] || 'i386', pkg
end

#get_domain_name(host) ⇒ Object

Determine the domain name of the provided host from its /etc/resolv.conf

Parameters:

  • host (Host)

    the host to act upon



268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/beaker/host_prebuilt_steps.rb', line 268

def get_domain_name(host)
  domain = nil
  search = nil
  resolv_conf = host.exec(Command.new("cat /etc/resolv.conf")).stdout
  resolv_conf.each_line { |line|
    if line =~ /^\s*domain\s+(\S+)/
      domain = $1
    elsif line =~ /^\s*search\s+(\S+)/
      search = $1
    end
  }
  return domain if domain
  return search if search
end

#get_ip(host) ⇒ Object

Deprecated.

Determine the ip address of the provided host

Parameters:

  • host (Host)

    the host to act upon



286
287
288
# File 'lib/beaker/host_prebuilt_steps.rb', line 286

def get_ip(host)
  host.get_ip
end

#hack_etc_hosts(hosts, opts) ⇒ Object

Update /etc/hosts to make it possible for each provided host to reach each other host by name. Assumes that each provided host has host set.

Parameters:

  • hosts (Host, Array<Host>)

    An array of hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



319
320
321
322
323
324
325
326
327
# File 'lib/beaker/host_prebuilt_steps.rb', line 319

def hack_etc_hosts hosts, opts
  etc_hosts = "127.0.0.1\tlocalhost localhost.localdomain\n"
  hosts.each do |host|
    etc_hosts += "#{host['ip'].to_s}\t#{host[:vmhostname] || host.name}\n"
  end
  hosts.each do |host|
    set_etc_hosts(host, etc_hosts)
  end
end

#package_proxy(host, opts) ⇒ Object

Setup files for enabling requests to pass to a proxy server This works for the APT package manager on debian, ubuntu, and cumulus and YUM package manager on el, centos, fedora and redhat.

Parameters:

  • host (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/beaker/host_prebuilt_steps.rb', line 392

def package_proxy host, opts
  logger = opts[:logger]

  block_on host do |host|
    logger.debug("enabling proxy support on #{host.name}")
    case host['platform']
      when /ubuntu/, /debian/, /cumulus/
        host.exec(Command.new("echo 'Acquire::http::Proxy \"#{opts[:package_proxy]}/\";' >> /etc/apt/apt.conf.d/10proxy"))
      when /^el-/, /centos/, /fedora/, /redhat/, /eos/
        host.exec(Command.new("echo 'proxy=#{opts[:package_proxy]}/' >> /etc/yum.conf"))
    else
      logger.debug("Attempting to enable package manager proxy support on non-supported platform: #{host.name}: #{host['platform']}")
    end
  end
end

#proxy_config(host, opts) ⇒ Object

On ubuntu, debian, or cumulus host or hosts: alter apt configuration to use the internal Puppet Labs proxy APT_CFG proxy. On solaris-11 host or hosts: alter pkg to point to the internal Puppet Labs proxy IPS_PKG_REPO.

Do nothing for other platform host or hosts.

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/beaker/host_prebuilt_steps.rb', line 211

def proxy_config( host, opts )
  logger = opts[:logger]
  block_on host do |host|
    case
    when host['platform'] =~ /ubuntu|debian|cumulus/
      host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
      copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
      apt_get_update(host)
    when host['platform'] =~ /solaris-11/
      host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
      host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % IPS_PKG_REPO))
    else
      logger.debug "#{host}: repo proxy configuration not modified"
    end
  end
rescue => e
  report_and_raise(logger, e, "proxy_config")
end

#set_env(host, opts) ⇒ Object

Add a host specific set of env vars to each provided host’s ~/.ssh/environment

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.



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

def set_env host, opts
  logger = opts[:logger]

  block_on host do |host|
    env = construct_env(host, opts)
    logger.debug("setting local environment on #{host.name}")
    case host['platform']
    when /windows/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/sshd_config"))
      host.exec(Command.new("cygrunsrv -E sshd"))
      host.exec(Command.new("cygrunsrv -S sshd"))
      env['CYGWIN'] = 'nodosfilewarning'
    when /osx/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/sshd_config"))
      host.exec(Command.new("launchctl unload /System/Library/LaunchDaemons/ssh.plist"))
      host.exec(Command.new("launchctl load /System/Library/LaunchDaemons/ssh.plist"))
    when /debian|ubuntu|cumulus/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config"))
      host.exec(Command.new("service ssh restart"))
    when /el-|centos|fedora|redhat|oracle|scientific|eos/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config"))
      host.exec(Command.new("service sshd restart"))
    when /sles/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config"))
      host.exec(Command.new("rcsshd restart"))
    when /solaris/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config"))
      host.exec(Command.new("svcadm restart svc:/network/ssh:default"))
    when /aix/
      host.exec(Command.new("echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config"))
      host.exec(Command.new("stopsrc -g ssh"))
      host.exec(Command.new("startsrc -g ssh"))
    end
    #ensure that ~/.ssh/environment exists
    host.exec(Command.new("touch #{host[:ssh_env_file]}"))
    #add the constructed env vars to this host
    host.add_env_var('RUBYLIB', '$RUBYLIB')
    host.add_env_var('PATH', '$PATH')
    env.each_pair do |var, value|
      host.add_env_var(var, value)
    end
    #close the host to re-establish the connection with the new sshd settings
    host.close
  end
end

#set_etc_hosts(host, etc_hosts) ⇒ Object

Append the provided string to the /etc/hosts file of the provided host

Parameters:

  • host (Host)

    the host to act upon

  • etc_hosts (String)

    The string to append to the /etc/hosts file



293
294
295
# File 'lib/beaker/host_prebuilt_steps.rb', line 293

def set_etc_hosts(host, etc_hosts)
  host.exec(Command.new("echo '#{etc_hosts}' > /etc/hosts"))
end

#sync_root_keys(host, opts) ⇒ Object

Install a set of authorized keys using ROOT_KEYS_SCRIPT. This is a convenience method to allow for easy login to hosts after they have been provisioned with Beaker.

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/beaker/host_prebuilt_steps.rb', line 120

def sync_root_keys host, opts
  # JJM This step runs on every system under test right now.  We're anticipating
  # issues on Windows and maybe Solaris.  We will likely need to filter this step
  # but we're deliberately taking the approach of "assume it will work, fix it
  # when reality dictates otherwise"
  logger = opts[:logger]
  block_on host do |host|
  logger.notify "Sync root authorized_keys from github on #{host.name}"
    # Allow all exit code, as this operation is unlikely to cause problems if it fails.
    if host['platform'].include? 'solaris'
      host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "| bash"), :acceptable_exit_codes => (0..255))
    elsif host['platform'].include? 'eos'
      # this is a terrible terrible thing that I'm already in the process of fixing
      # the only reason that I include this terrible implementation is that the
      # fix relies on changes in another repo, so I'm not sure how long it'll take
      # to get those in
      host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "> manage_root_authorized_keys"), :acceptable_exit_codes => (0..255))
      host.exec(Command.new("sed -i 's|mv -f $SSH_HOME/authorized_keys.tmp $SSH_HOME/authorized_keys|cp -f $SSH_HOME/authorized_keys.tmp $SSH_HOME/authorized_keys|' manage_root_authorized_keys"), :acceptable_exit_codes => (0..255))
      host.exec(Command.new("bash manage_root_authorized_keys"), :acceptable_exit_codes => (0..255))
    else
      host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "| env PATH=/usr/gnu/bin:$PATH bash"), :acceptable_exit_codes => (0..255))
    end
  end
rescue => e
  report_and_raise(logger, e, "sync_root_keys")
end

#timesync(host, opts) ⇒ Object

Run timesync on the provided hosts

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/beaker/host_prebuilt_steps.rb', line 29

def timesync host, opts
  logger = opts[:logger]
  ntp_server = opts[:ntp_server] ? opts[:ntp_server] : NTPSERVER
  block_on host do |host|
    logger.notify "Update system time sync for '#{host.name}'"
    if host['platform'].include? 'windows'
      # The exit code of 5 is for Windows 2008 systems where the w32tm /register command
      # is not actually necessary.
      host.exec(Command.new("w32tm /register"), :acceptable_exit_codes => [0,5])
      host.exec(Command.new("net start w32time"), :acceptable_exit_codes => [0,2])
      host.exec(Command.new("w32tm /config /manualpeerlist:#{ntp_server} /syncfromflags:manual /update"))
      host.exec(Command.new("w32tm /resync"))
      logger.notify "NTP date succeeded on #{host}"
    else
      case
        when host['platform'] =~ /sles-/
          ntp_command = "sntp #{ntp_server}"
        else
          ntp_command = "ntpdate -t 20 #{ntp_server}"
      end
      success=false
      try = 0
      until try >= TRIES do
        try += 1
        if host.exec(Command.new(ntp_command), :acceptable_exit_codes => (0..255)).exit_code == 0
          success=true
          break
        end
        sleep SLEEPWAIT
      end
      if success
        logger.notify "NTP date succeeded on #{host} after #{try} tries"
      else
        raise "NTP date was not successful after #{try} tries"
      end
    end
  end
rescue => e
  report_and_raise(logger, e, "timesync (--ntp)")
end

#validate_host(host, opts) ⇒ Object

Validate that hosts are prepared to be used as SUTs, if packages are missing attempt to install them.

Verifies the presence of #UNIX_PACKAGES on unix platform hosts, SLES_PACKAGES on SUSE platform hosts, DEBIAN_PACKAGES on debian platform hosts, CUMULUS_PACKAGES on cumulus platform hosts, and WINDOWS_PACKAGES on windows platform hosts.

Parameters:

  • host (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/beaker/host_prebuilt_steps.rb', line 82

def validate_host host, opts
  logger = opts[:logger]
  block_on host do |host|
    case
    when host['platform'] =~ /sles-/
      check_and_install_packages_if_needed(host, SLES_PACKAGES)
    when host['platform'] =~ /debian/
      check_and_install_packages_if_needed(host, DEBIAN_PACKAGES)
    when host['platform'] =~ /cumulus/
      check_and_install_packages_if_needed(host, CUMULUS_PACKAGES)
    when host['platform'] =~ /windows/
      check_and_install_packages_if_needed(host, WINDOWS_PACKAGES)
    when host['platform'] !~ /debian|aix|solaris|windows|sles-|osx-|cumulus/
      check_and_install_packages_if_needed(host, UNIX_PACKAGES)
    end
  end
rescue => e
  report_and_raise(logger, e, "validate")
end