Module: Beaker::HostPrebuiltSteps
Overview
Provides convienience methods for commonly run actions on hosts
Constant Summary collapse
- NTPSERVER =
'pool.ntp.org'
- SLEEPWAIT =
5
- TRIES =
5
- RHEL8_PACKAGES =
['curl', 'chrony']
- RHEL9_PACKAGES =
['chrony']
- FEDORA_PACKAGES =
['curl', 'chrony']
- UNIX_PACKAGES =
['curl', 'ntpdate']
- FREEBSD_PACKAGES =
['curl', 'perl5|perl']
- OPENBSD_PACKAGES =
['curl']
- ARCHLINUX_PACKAGES =
['curl', 'ntp', 'net-tools', 'openssh']
- WINDOWS_PACKAGES =
['curl']
- PSWINDOWS_PACKAGES =
[]
- SLES10_PACKAGES =
['curl']
- SLES_PACKAGES =
['curl', 'ntp']
- DEBIAN_PACKAGES =
['curl', 'ntpdate', 'lsb-release', 'apt-transport-https']
- CUMULUS_PACKAGES =
['curl', 'ntpdate']
- SOLARIS10_PACKAGES =
['CSWcurl', 'CSWntp', 'wget']
- SOLARIS11_PACKAGES =
['curl', 'ntp']
- 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"
- ROOT_KEYS_SYNC_CMD_AIX =
"curl --tlsv1 -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
-
#add_el_extras(host, opts) ⇒ Object
Install EPEL on host or hosts with platform = /el-(6|7)/.
-
#additive_hash_merge(h1, h2) ⇒ Hash
Merge the two provided hashes so that an array of values is created from collisions.
-
#apt_get_update(hosts) ⇒ Object
Run 'apt-get update' on the provided host or hosts.
-
#check_and_install_packages_if_needed(host, package_list) ⇒ Object
Installs the given packages if they aren't already on a host.
-
#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.
-
#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.
-
#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.
-
#disable_iptables(host, opts) ⇒ Object
Disable iptables on centos, does nothing on other platforms.
-
#disable_se_linux(host, opts) ⇒ Object
Disable SELinux on centos, does nothing on other platforms.
-
#disable_updates(hosts, opts) ⇒ Object
Update /etc/hosts to make updates.puppetlabs.com (aka the dujour server) resolve to 127.0.01, so that we don't pollute the server with test data.
-
#enable_root_login(host, opts) ⇒ Object
Update sshd_config on debian, ubuntu, centos, el, redhat, cumulus, and fedora boxes to allow for root login.
-
#get_domain_name(host) ⇒ Object
Determine the domain name of the provided host from its /etc/resolv.conf.
- #get_ip(host) ⇒ Object deprecated Deprecated.
-
#hack_etc_hosts(hosts, _opts) ⇒ Object
Update /etc/hosts to make it possible for each provided host to reach each other host by name.
-
#host_packages(host) ⇒ Array<String>
Return a list of packages that should be present.
-
#install_one_of_packages(host, packages) ⇒ Object
Installs one of alternative packages (first available).
-
#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.
-
#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.
-
#set_env(host, opts) ⇒ Object
Add a host specific set of env vars to each provided host's ~/.ssh/environment.
-
#set_etc_hosts(host, etc_hosts) ⇒ Object
Append the provided string to the /etc/hosts file of the provided host.
-
#sync_root_keys(host, opts) ⇒ Object
Install a set of authorized keys using ROOT_KEYS_SCRIPT.
-
#timesync(host, opts) ⇒ Object
Run timesync on the provided hosts.
-
#validate_host(host, opts) ⇒ Object
Validate that hosts are prepared to be used as SUTs, if packages are missing attempt to install them.
Methods included from DSL::Patterns
Instance Method Details
#add_el_extras(host, opts) ⇒ Object
Install EPEL on host or hosts with platform = /el-(6|7)/. Do nothing on host or hosts of other platforms.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 274 def add_el_extras( host, opts ) #add_el_extras #only supports el-* platforms logger = opts[:logger] block_on host do |host| case when el_based?(host) && ['6','7'].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_base = opts[:epel_url] host.install_package_with_rpm("#{url_base}/epel-release-latest-#{host['platform'].version}.noarch.rpm", '--replacepkgs', { :package_proxy => opts[:package_proxy] }) #update /etc/yum.repos.d/epel.repo for new baseurl host.exec(Command.new("sed -i -e 's;#baseurl.*$;baseurl=#{Regexp.escape("#{url_base}/#{host['platform'].version}")}/\$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
543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 543 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.
216 217 218 219 220 221 222 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 216 def apt_get_update hosts block_on hosts do |host| if /ubuntu|debian|cumulus/.match?(host[:platform]) 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
161 162 163 164 165 166 167 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 161 def check_and_install_packages_if_needed host, package_list package_list.each do |string| alternatives = string.split('|') next if alternatives.any? { |pkg| host.check_for_package pkg } install_one_of_packages host, alternatives 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
560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 560 def construct_env host, opts env = additive_hash_merge(host[:host_env], opts[:host_env]) env.each_key do |key| separator = host['pathseparator'] if key == 'PATH' && (not host.is_powershell?) separator = ':' end env[key] = env[key].join(separator) 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.
228 229 230 231 232 233 234 235 236 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 228 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
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 360 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'].include?('windows') and host.is_cygwin? host.exec(Command.new('cp -r .ssh /cygdrive/c/Users/Administrator/.')) host.exec(Command.new('chown -R Administrator /cygdrive/c/Users/Administrator/.ssh')) elsif host['platform'].include?('windows') and not host.is_cygwin? # from https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true: # /i : If Source is a directory or contains wildcards and Destination # does not exist, xcopy assumes destination specifies a directory # name and creates a new directory. Then, xcopy copies all specified # files into the new directory. By default, xcopy prompts you to # specify whether Destination is a file or a directory. # # /y : Suppresses prompting to confirm that you want to overwrite an # existing destination file. host.exec(Command.new("if exist .ssh (xcopy .ssh C:\\Users\\Administrator\\.ssh /s /e /y /i)")) elsif host['platform'].include?('osx') host.exec(Command.new('sudo cp -r .ssh /var/root/.'), {:pty => true}) elsif /(free|open)bsd/.match?(host['platform']) || host['platform'].include?('solaris-11') host.exec(Command.new('sudo cp -r .ssh /root/.'), {:pty => true}) elsif host['platform'].include?('solaris-10') host.exec(Command.new('sudo cp -r .ssh /.'), {:pty => true}) else host.exec(Command.new('sudo su -c "cp -r .ssh /root/."'), {:pty => true}) end if host.selinux_enabled? host.exec(Command.new('sudo fixfiles restore /root')) end end end |
#disable_iptables(host, opts) ⇒ Object
Disable iptables on centos, does nothing on other platforms
499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 499 def disable_iptables host, opts logger = opts[:logger] block_on host do |host| if /centos|el-|redhat|fedora|eos/.match?(host['platform']) 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
483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 483 def disable_se_linux host, opts logger = opts[:logger] block_on host do |host| if /centos|el-|redhat|fedora|eos/.match?(host['platform']) 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 |
#disable_updates(hosts, opts) ⇒ Object
Update /etc/hosts to make updates.puppetlabs.com (aka the dujour server) resolve to 127.0.01, so that we don't pollute the server with test data. See SERVER-1000, BKR-182, BKR-237, DJ-10 for additional details.
418 419 420 421 422 423 424 425 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 418 def disable_updates hosts, opts logger = opts[:logger] hosts.each do |host| next if host['platform'].include?('netscaler') logger.notify "Disabling updates.puppetlabs.com by modifying hosts file to resolve updates to 127.0.0.1 on #{host}" set_etc_hosts(host, "127.0.0.1\tupdates.puppetlabs.com\n") end 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.
434 435 436 437 438 439 440 441 442 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 470 471 472 473 474 475 476 477 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 434 def enable_root_login host, opts logger = opts[:logger] block_on host do |host| logger.debug "Update sshd_config to allow root login" if host['platform'].include?('osx') # If osx > 10.10 use '/private/etc/ssh/sshd_config', else use '/etc/sshd_config' ssh_config_file = '/private/etc/ssh/sshd_config' ssh_config_file = '/etc/sshd_config' if /^osx-10\.(9|10)/i.match?(host['platform']) host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin Yes/g' #{ssh_config_file}")) host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' #{ssh_config_file}")) elsif host['platform'].include?('freebsd') host.exec(Command.new("sudo sed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} ) elsif host['platform'].include?('openbsd') host.exec(Command.new("sudo perl -pi -e 's/^PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config"), {:pty => true} ) elsif host['platform'].include?('solaris-10') host.exec(Command.new("sudo gsed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} ) elsif host['platform'].include?('solaris-11') host.exec(Command.new("if grep \"root::::type=role\" /etc/user_attr; then sudo rolemod -K type=normal root; else echo \"root user already type=normal\"; fi"), {:pty => true} ) host.exec(Command.new("sudo gsed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} ) elsif host['platform'].include?('f5') || host.is_powershell? #interacting with f5 should using tmsh logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}") elsif host.is_cygwin? host.exec(Command.new("sed -ri 's/^#?PermitRootLogin /PermitRootLogin yes/' /etc/sshd_config"), {:pty => true}) else host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), {:pty => true}) end #restart sshd if /debian|ubuntu|cumulus/.match?(host['platform']) host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true}) elsif /arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform']) host.exec(Command.new("sudo -E systemctl restart sshd.service"), {:pty => true}) elsif /centos|el-|redhat|fedora|eos/.match?(host['platform']) host.exec(Command.new("sudo -E /sbin/service sshd reload"), {:pty => true}) elsif /(free|open)bsd/.match?(host['platform']) host.exec(Command.new("sudo /etc/rc.d/sshd restart")) elsif host['platform'].include?('solaris') host.exec(Command.new("sudo -E svcadm restart network/ssh"), {:pty => true} ) else logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}") end end end |
#get_domain_name(host) ⇒ Object
Determine the domain name of the provided host from its /etc/resolv.conf
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 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 301 def get_domain_name(host) domain = nil search = nil if host['platform'].include?('windows') if host.is_cygwin? resolv_conf = host.exec(Command.new("cat /cygdrive/c/Windows/System32/drivers/etc/hosts")).stdout else resolv_conf = host.exec(Command.new('type C:\Windows\System32\drivers\etc\hosts')).stdout end else resolv_conf = host.exec(Command.new("cat /etc/resolv.conf")).stdout end resolv_conf.each_line { |line| if line =~ /^\s*domain\s+(\S+)/ domain = $1 elsif line =~ /^\s*search\s+(\S+)/ search = $1 end } return_value ||= domain return_value ||= search if return_value return_value.gsub(/\.$/, '') end end |
#get_ip(host) ⇒ Object
Determine the ip address of the provided host
331 332 333 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 331 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; in the instance where a provider sets host to an address which facilitates access to the host externally, but the actual host addresses differ from this, we check first for the presence of a host key first, and use that if present.
402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 402 def hack_etc_hosts hosts, _opts etc_hosts = "127.0.0.1\tlocalhost localhost.localdomain\n" hosts.each do |host| ip = host['vm_ip'] || host['ip'].to_s hostname = host[:vmhostname] || host.name domain = get_domain_name(host) etc_hosts += "#{ip}\t#{hostname}.#{domain} #{hostname}\n" end hosts.each do |host| set_etc_hosts(host, etc_hosts) end end |
#host_packages(host) ⇒ Array<String>
Return a list of packages that should be present.
115 116 117 118 119 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 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 115 def host_packages(host) case host['platform'] when /el-8/ RHEL8_PACKAGES when /el-9/ RHEL9_PACKAGES when /sles-10/ SLES10_PACKAGES when /opensuse|sles-/ SLES_PACKAGES when /debian/ DEBIAN_PACKAGES when /cumulus/ CUMULUS_PACKAGES when /windows/ if host.is_cygwin? raise RuntimeError, "cygwin is not installed on #{host}" if !host.cygwin_installed? WINDOWS_PACKAGES else PSWINDOWS_PACKAGES end when /freebsd/ FREEBSD_PACKAGES when /openbsd/ OPENBSD_PACKAGES when /solaris-10/ SOLARIS10_PACKAGES when /solaris-1[1-9]/ SOLARIS11_PACKAGES when /archlinux/ ARCHLINUX_PACKAGES when /fedora/ FEDORA_PACKAGES else if !/aix|solaris|osx-|f5-|netscaler|cisco_/.match?(host['platform']) UNIX_PACKAGES else [] end end end |
#install_one_of_packages(host, packages) ⇒ Object
Installs one of alternative packages (first available)
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 173 def install_one_of_packages host, packages error = nil packages.each do |pkg| begin return host.install_package pkg rescue Beaker::Host::CommandFailure => e error = e end end raise error 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.
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 517 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.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 248 def proxy_config( host, opts ) logger = opts[:logger] block_on host do |host| case when /ubuntu|debian|cumulus/.match?(host['platform']) 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'].include?('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
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 607 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 576 def set_env host, opts logger = opts[:logger] block_on host do |host| skip_msg = host.skip_set_env? unless skip_msg.nil? logger.debug( skip_msg ) next end env = construct_env(host, opts) logger.debug("setting local environment on #{host.name}") if host['platform'].include?('windows') && host.is_cygwin? env['CYGWIN'] = 'nodosfilewarning' end host.ssh_permit_user_environment host.ssh_set_user_environment(env) #close the host to re-establish the connection with the new sshd settings host.close # print out the working env if host.is_powershell? host.exec(Command.new("SET")) else host.exec(Command.new("cat #{host[:ssh_env_file]}")) end end end |
#set_etc_hosts(host, etc_hosts) ⇒ Object
Append the provided string to the /etc/hosts file of the provided host
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 338 def set_etc_hosts(host, etc_hosts) if host['platform'].include?('freebsd') host.echo_to_file(etc_hosts, '/etc/hosts') elsif ((host['platform'].include?('windows')) and not host.is_cygwin?) host.exec(Command.new("echo '#{etc_hosts}' >> C:\\Windows\\System32\\drivers\\etc\\hosts")) else host.exec(Command.new("echo '#{etc_hosts}' >> /etc/hosts")) end # AIX must be configured to prefer local DNS over external if host['platform'].include?('aix') aix_netsvc = '/etc/netsvc.conf' aix_local_resolv = 'hosts = local, bind' unless host.exec(Command.new("grep '#{aix_local_resolv}' #{aix_netsvc}"), :accept_all_exit_codes => true).exit_code == 0 host.exec(Command.new("echo '#{aix_local_resolv}' >> #{aix_netsvc}")) end end 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.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 191 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 /solaris|eos/.match?(host['platform']) host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :accept_all_exit_codes => true) elsif host['platform'].include?('aix') host.exec(Command.new(ROOT_KEYS_SYNC_CMD_AIX % "env PATH=/usr/gnu/bin:$PATH bash"), :accept_all_exit_codes => true) else host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "env PATH=\"/usr/gnu/bin:$PATH\" bash"), :accept_all_exit_codes => true) end end rescue => e report_and_raise(logger, e, "sync_root_keys") end |
#timesync(host, opts) ⇒ Object
Run timesync on the provided hosts
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 42 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 /el-[89]|fedora/.match?(host['platform']) ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2" when /opensuse-|sles-/.match?(host['platform']) ntp_command = "sntp #{ntp_server}" when host['platform'].include?('cisco_nexus') ntp_server = host.exec(Command.new("getent hosts #{NTPSERVER} | head -n1 |cut -d \" \" -f1"), :acceptable_exit_codes => [0]).stdout ntp_command = "sudo -E sh -c 'export DCOS_CONTEXT=2;/isan/bin/ntpdate -u -t 20 #{ntp_server}'" else ntp_command = "ntpdate -u -t 20 #{ntp_server}" end success=false try = 0 until try >= TRIES do try += 1 if host.exec(Command.new(ntp_command), :accept_all_exit_codes => true).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 nil 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, WINDOWS_PACKAGES on cygwin-installed windows platform hosts, and PSWINDOWS_PACKAGES on non-cygwin windows platform hosts.
102 103 104 105 106 107 108 109 |
# File 'lib/beaker/host_prebuilt_steps.rb', line 102 def validate_host host, opts logger = opts[:logger] block_on host do |host| check_and_install_packages_if_needed(host, host_packages(host)) end rescue => e report_and_raise(logger, e, "validate") end |