beaker 4.38.1 → 4.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +12 -0
  3. data/.rubocop.yml +62 -0
  4. data/.rubocop_todo.yml +215 -0
  5. data/CHANGELOG.md +72 -33
  6. data/Gemfile +8 -1
  7. data/HISTORY.md +103 -0
  8. data/Rakefile +10 -9
  9. data/acceptance/fixtures/module/Gemfile +1 -1
  10. data/acceptance/fixtures/module/Rakefile +2 -2
  11. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -11
  12. data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -1
  13. data/acceptance/lib/helpers/test_helper.rb +3 -3
  14. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +6 -6
  15. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +6 -6
  16. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +6 -12
  17. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +4 -4
  18. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +1 -1
  19. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +7 -7
  20. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +4 -4
  21. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +8 -11
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +2 -2
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +6 -11
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +5 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +2 -2
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +1 -1
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +4 -4
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +1 -1
  30. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +1 -1
  31. data/acceptance/tests/base/dsl/structure_test.rb +4 -10
  32. data/acceptance/tests/base/host/file_test.rb +7 -7
  33. data/acceptance/tests/base/host/group_test.rb +2 -2
  34. data/acceptance/tests/base/host/host_test.rb +5 -5
  35. data/acceptance/tests/base/host/packages.rb +26 -28
  36. data/acceptance/tests/base/host/packages_unix.rb +4 -4
  37. data/acceptance/tests/base/host/user_test.rb +2 -2
  38. data/acceptance/tests/install/from_file.rb +2 -2
  39. data/beaker.gemspec +9 -9
  40. data/docs/concepts/style_guide.md +1 -1
  41. data/docs/how_to/debug_beaker_tests.md +1 -1
  42. data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
  43. data/lib/beaker/cli.rb +6 -8
  44. data/lib/beaker/command.rb +3 -3
  45. data/lib/beaker/command_factory.rb +2 -2
  46. data/lib/beaker/dsl/assertions.rb +1 -1
  47. data/lib/beaker/dsl/helpers/hocon_helpers.rb +2 -2
  48. data/lib/beaker/dsl/helpers/host_helpers.rb +11 -11
  49. data/lib/beaker/dsl/helpers/web_helpers.rb +3 -3
  50. data/lib/beaker/dsl/outcomes.rb +4 -4
  51. data/lib/beaker/dsl/roles.rb +2 -2
  52. data/lib/beaker/dsl/structure.rb +10 -10
  53. data/lib/beaker/host/aix/group.rb +3 -3
  54. data/lib/beaker/host/aix/user.rb +3 -3
  55. data/lib/beaker/host/cisco.rb +11 -11
  56. data/lib/beaker/host/eos.rb +2 -2
  57. data/lib/beaker/host/mac/exec.rb +1 -1
  58. data/lib/beaker/host/mac/group.rb +7 -7
  59. data/lib/beaker/host/mac/pkg.rb +6 -6
  60. data/lib/beaker/host/mac/user.rb +6 -6
  61. data/lib/beaker/host/pswindows/exec.rb +8 -8
  62. data/lib/beaker/host/pswindows/file.rb +1 -1
  63. data/lib/beaker/host/pswindows/group.rb +3 -3
  64. data/lib/beaker/host/pswindows/pkg.rb +6 -6
  65. data/lib/beaker/host/pswindows/user.rb +2 -2
  66. data/lib/beaker/host/unix/exec.rb +6 -6
  67. data/lib/beaker/host/unix/file.rb +3 -4
  68. data/lib/beaker/host/unix/group.rb +3 -3
  69. data/lib/beaker/host/unix/pkg.rb +17 -17
  70. data/lib/beaker/host/unix/user.rb +3 -3
  71. data/lib/beaker/host/unix.rb +10 -9
  72. data/lib/beaker/host/windows/exec.rb +3 -3
  73. data/lib/beaker/host/windows/file.rb +2 -2
  74. data/lib/beaker/host/windows/group.rb +3 -3
  75. data/lib/beaker/host/windows/pkg.rb +6 -6
  76. data/lib/beaker/host/windows/user.rb +2 -2
  77. data/lib/beaker/host/windows.rb +2 -2
  78. data/lib/beaker/host.rb +7 -7
  79. data/lib/beaker/host_prebuilt_steps.rb +38 -45
  80. data/lib/beaker/hypervisor.rb +4 -4
  81. data/lib/beaker/local_connection.rb +3 -3
  82. data/lib/beaker/logger.rb +5 -11
  83. data/lib/beaker/logger_junit.rb +2 -2
  84. data/lib/beaker/network_manager.rb +2 -2
  85. data/lib/beaker/options/command_line_parser.rb +1 -1
  86. data/lib/beaker/options/hosts_file_parser.rb +21 -4
  87. data/lib/beaker/options/options_file_parser.rb +1 -1
  88. data/lib/beaker/options/options_hash.rb +1 -3
  89. data/lib/beaker/options/parser.rb +6 -6
  90. data/lib/beaker/options/presets.rb +2 -2
  91. data/lib/beaker/options/validator.rb +2 -2
  92. data/lib/beaker/perf.rb +9 -9
  93. data/lib/beaker/platform.rb +1 -1
  94. data/lib/beaker/shared/host_manager.rb +4 -5
  95. data/lib/beaker/shared/repetition.rb +4 -4
  96. data/lib/beaker/shared/semvar.rb +2 -2
  97. data/lib/beaker/shared/timed.rb +2 -2
  98. data/lib/beaker/ssh_connection.rb +9 -9
  99. data/lib/beaker/subcommand.rb +6 -6
  100. data/lib/beaker/tasks/quick_start.rb +2 -2
  101. data/lib/beaker/tasks/rake_task.rb +3 -3
  102. data/lib/beaker/test_suite.rb +2 -2
  103. data/lib/beaker/test_suite_result.rb +8 -11
  104. data/lib/beaker/version.rb +1 -1
  105. data/spec/beaker/cli_spec.rb +46 -43
  106. data/spec/beaker/command_spec.rb +17 -7
  107. data/spec/beaker/dsl/assertions_spec.rb +2 -11
  108. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +7 -7
  109. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +2 -2
  110. data/spec/beaker/dsl/outcomes_spec.rb +1 -0
  111. data/spec/beaker/dsl/roles_spec.rb +48 -5
  112. data/spec/beaker/dsl/structure_spec.rb +22 -15
  113. data/spec/beaker/dsl/test_tagging_spec.rb +16 -16
  114. data/spec/beaker/dsl/wrappers_spec.rb +7 -7
  115. data/spec/beaker/host/cisco_spec.rb +8 -8
  116. data/spec/beaker/host/freebsd/exec_spec.rb +3 -3
  117. data/spec/beaker/host/freebsd/pkg_spec.rb +6 -3
  118. data/spec/beaker/host/mac/exec_spec.rb +3 -3
  119. data/spec/beaker/host/mac_spec.rb +6 -6
  120. data/spec/beaker/host/pswindows/exec_spec.rb +8 -5
  121. data/spec/beaker/host/pswindows/file_spec.rb +6 -3
  122. data/spec/beaker/host/pswindows_spec.rb +1 -1
  123. data/spec/beaker/host/unix/exec_spec.rb +24 -24
  124. data/spec/beaker/host/unix/file_spec.rb +18 -17
  125. data/spec/beaker/host/unix/pkg_spec.rb +26 -22
  126. data/spec/beaker/host/unix_spec.rb +8 -8
  127. data/spec/beaker/host/windows/exec_spec.rb +4 -4
  128. data/spec/beaker/host/windows/file_spec.rb +4 -4
  129. data/spec/beaker/host/windows/group_spec.rb +12 -12
  130. data/spec/beaker/host/windows/pkg_spec.rb +5 -5
  131. data/spec/beaker/host_prebuilt_steps_spec.rb +26 -20
  132. data/spec/beaker/host_spec.rb +72 -63
  133. data/spec/beaker/hypervisor/hypervisor_spec.rb +14 -14
  134. data/spec/beaker/localhost_connection_spec.rb +6 -4
  135. data/spec/beaker/logger_junit_spec.rb +16 -17
  136. data/spec/beaker/logger_spec.rb +54 -52
  137. data/spec/beaker/network_manager_spec.rb +5 -5
  138. data/spec/beaker/options/command_line_parser_spec.rb +2 -2
  139. data/spec/beaker/options/data/hosts_preserved.yml +395 -0
  140. data/spec/beaker/options/hosts_file_parser_spec.rb +9 -2
  141. data/spec/beaker/options/options_file_parser_spec.rb +1 -1
  142. data/spec/beaker/options/options_hash_spec.rb +4 -4
  143. data/spec/beaker/options/parser_spec.rb +23 -23
  144. data/spec/beaker/options/presets_spec.rb +2 -2
  145. data/spec/beaker/options/subcommand_options_parser_spec.rb +4 -3
  146. data/spec/beaker/options/validator_spec.rb +18 -18
  147. data/spec/beaker/perf_spec.rb +29 -28
  148. data/spec/beaker/platform_spec.rb +3 -2
  149. data/spec/beaker/shared/error_handler_spec.rb +1 -1
  150. data/spec/beaker/shared/fog_credentials_spec.rb +12 -12
  151. data/spec/beaker/shared/host_manager_spec.rb +7 -7
  152. data/spec/beaker/shared/repetition_spec.rb +9 -9
  153. data/spec/beaker/ssh_connection_spec.rb +14 -12
  154. data/spec/beaker/subcommand/subcommand_util_spec.rb +9 -4
  155. data/spec/beaker/subcommand_spec.rb +30 -28
  156. data/spec/beaker/test_case_spec.rb +11 -15
  157. data/spec/beaker/test_suite_spec.rb +24 -24
  158. data/spec/matchers.rb +1 -1
  159. data/spec/mocks.rb +5 -5
  160. data/spec/spec_helper.rb +0 -3
  161. metadata +59 -59
  162. data/spec/mock_fission.rb +0 -60
  163. data/spec/mock_vsphere.rb +0 -314
  164. data/spec/mock_vsphere_helper.rb +0 -183
@@ -54,11 +54,11 @@ module Beaker
54
54
  logger.notify "NTP date succeeded on #{host}"
55
55
  else
56
56
  case
57
- when host['platform'] =~ /el-[89]|fedora/
57
+ when /el-[89]|fedora/.match?(host['platform'])
58
58
  ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2"
59
- when host['platform'] =~ /opensuse-|sles-/
59
+ when /opensuse-|sles-/.match?(host['platform'])
60
60
  ntp_command = "sntp #{ntp_server}"
61
- when host['platform'] =~ /cisco_nexus/
61
+ when host['platform'].include?('cisco_nexus')
62
62
  ntp_server = host.exec(Command.new("getent hosts #{NTPSERVER} | head -n1 |cut -d \" \" -f1"), :acceptable_exit_codes => [0]).stdout
63
63
  ntp_command = "sudo -E sh -c 'export DCOS_CONTEXT=2;/isan/bin/ntpdate -u -t 20 #{ntp_server}'"
64
64
  else
@@ -146,7 +146,7 @@ module Beaker
146
146
  when /fedora/
147
147
  FEDORA_PACKAGES
148
148
  else
149
- if host['platform'] !~ /aix|solaris|osx-|f5-|netscaler|cisco_/
149
+ if !/aix|solaris|osx-|f5-|netscaler|cisco_/.match?(host['platform'])
150
150
  UNIX_PACKAGES
151
151
  else
152
152
  []
@@ -197,9 +197,9 @@ module Beaker
197
197
  block_on host do |host|
198
198
  logger.notify "Sync root authorized_keys from github on #{host.name}"
199
199
  # Allow all exit code, as this operation is unlikely to cause problems if it fails.
200
- if host['platform'] =~ /solaris|eos/
200
+ if /solaris|eos/.match?(host['platform'])
201
201
  host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :accept_all_exit_codes => true)
202
- elsif host['platform'] =~ /aix/
202
+ elsif host['platform'].include?('aix')
203
203
  host.exec(Command.new(ROOT_KEYS_SYNC_CMD_AIX % "env PATH=/usr/gnu/bin:$PATH bash"), :accept_all_exit_codes => true)
204
204
  else
205
205
  host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "env PATH=\"/usr/gnu/bin:$PATH\" bash"), :accept_all_exit_codes => true)
@@ -215,7 +215,7 @@ module Beaker
215
215
  # @param [Host, Array<Host>] hosts One or more hosts to act upon
216
216
  def apt_get_update hosts
217
217
  block_on hosts do |host|
218
- if host[:platform] =~ /ubuntu|debian|cumulus/
218
+ if /ubuntu|debian|cumulus/.match?(host[:platform])
219
219
  host.exec(Command.new("apt-get update"))
220
220
  end
221
221
  end
@@ -249,11 +249,11 @@ module Beaker
249
249
  logger = opts[:logger]
250
250
  block_on host do |host|
251
251
  case
252
- when host['platform'] =~ /ubuntu|debian|cumulus/
252
+ when /ubuntu|debian|cumulus/.match?(host['platform'])
253
253
  host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
254
254
  copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
255
255
  apt_get_update(host)
256
- when host['platform'] =~ /solaris-11/
256
+ when host['platform'].include?('solaris-11')
257
257
  host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
258
258
  host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % IPS_PKG_REPO))
259
259
  else
@@ -275,7 +275,6 @@ module Beaker
275
275
  #add_el_extras
276
276
  #only supports el-* platforms
277
277
  logger = opts[:logger]
278
- debug_opt = opts[:debug] ? 'vh' : ''
279
278
  block_on host do |host|
280
279
  case
281
280
  when el_based?(host) && ['6','7'].include?(host['platform'].version)
@@ -302,7 +301,7 @@ module Beaker
302
301
  def get_domain_name(host)
303
302
  domain = nil
304
303
  search = nil
305
- if host['platform'] =~ /windows/
304
+ if host['platform'].include?('windows')
306
305
  if host.is_cygwin?
307
306
  resolv_conf = host.exec(Command.new("cat /cygdrive/c/Windows/System32/drivers/etc/hosts")).stdout
308
307
  else
@@ -337,15 +336,15 @@ module Beaker
337
336
  # @param [Host] host the host to act upon
338
337
  # @param [String] etc_hosts The string to append to the /etc/hosts file
339
338
  def set_etc_hosts(host, etc_hosts)
340
- if host['platform'] =~ /freebsd/
339
+ if host['platform'].include?('freebsd')
341
340
  host.echo_to_file(etc_hosts, '/etc/hosts')
342
- elsif ((host['platform'] =~ /windows/) and not host.is_cygwin?)
341
+ elsif ((host['platform'].include?('windows')) and not host.is_cygwin?)
343
342
  host.exec(Command.new("echo '#{etc_hosts}' >> C:\\Windows\\System32\\drivers\\etc\\hosts"))
344
343
  else
345
344
  host.exec(Command.new("echo '#{etc_hosts}' >> /etc/hosts"))
346
345
  end
347
346
  # AIX must be configured to prefer local DNS over external
348
- if host['platform'] =~ /aix/
347
+ if host['platform'].include?('aix')
349
348
  aix_netsvc = '/etc/netsvc.conf'
350
349
  aix_local_resolv = 'hosts = local, bind'
351
350
  unless host.exec(Command.new("grep '#{aix_local_resolv}' #{aix_netsvc}"), :accept_all_exit_codes => true).exit_code == 0
@@ -362,10 +361,10 @@ module Beaker
362
361
  logger = opts[:logger]
363
362
  block_on host do |host|
364
363
  logger.debug "Give root a copy of current user's keys, on #{host.name}"
365
- if host['platform'] =~ /windows/ and host.is_cygwin?
364
+ if host['platform'].include?('windows') and host.is_cygwin?
366
365
  host.exec(Command.new('cp -r .ssh /cygdrive/c/Users/Administrator/.'))
367
366
  host.exec(Command.new('chown -R Administrator /cygdrive/c/Users/Administrator/.ssh'))
368
- elsif host['platform'] =~ /windows/ and not host.is_cygwin?
367
+ elsif host['platform'].include?('windows') and not host.is_cygwin?
369
368
  # from https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true:
370
369
  # /i : If Source is a directory or contains wildcards and Destination
371
370
  # does not exist, xcopy assumes destination specifies a directory
@@ -376,16 +375,12 @@ module Beaker
376
375
  # /y : Suppresses prompting to confirm that you want to overwrite an
377
376
  # existing destination file.
378
377
  host.exec(Command.new("if exist .ssh (xcopy .ssh C:\\Users\\Administrator\\.ssh /s /e /y /i)"))
379
- elsif host['platform'] =~ /osx/
378
+ elsif host['platform'].include?('osx')
380
379
  host.exec(Command.new('sudo cp -r .ssh /var/root/.'), {:pty => true})
381
- elsif host['platform'] =~ /freebsd/
380
+ elsif /(free|open)bsd/.match?(host['platform']) || host['platform'].include?('solaris-11')
382
381
  host.exec(Command.new('sudo cp -r .ssh /root/.'), {:pty => true})
383
- elsif host['platform'] =~ /openbsd/
384
- host.exec(Command.new('sudo cp -r .ssh /root/.'), {:pty => true})
385
- elsif host['platform'] =~ /solaris-10/
382
+ elsif host['platform'].include?('solaris-10')
386
383
  host.exec(Command.new('sudo cp -r .ssh /.'), {:pty => true})
387
- elsif host['platform'] =~ /solaris-11/
388
- host.exec(Command.new('sudo cp -r .ssh /root/.'), {:pty => true})
389
384
  else
390
385
  host.exec(Command.new('sudo su -c "cp -r .ssh /root/."'), {:pty => true})
391
386
  end
@@ -404,7 +399,7 @@ module Beaker
404
399
  # @param [Host, Array<Host>] hosts An array of hosts to act upon
405
400
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
406
401
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
407
- def hack_etc_hosts hosts, opts
402
+ def hack_etc_hosts hosts, _opts
408
403
  etc_hosts = "127.0.0.1\tlocalhost localhost.localdomain\n"
409
404
  hosts.each do |host|
410
405
  ip = host['vm_ip'] || host['ip'].to_s
@@ -423,7 +418,7 @@ module Beaker
423
418
  def disable_updates hosts, opts
424
419
  logger = opts[:logger]
425
420
  hosts.each do |host|
426
- next if host['platform'] =~ /netscaler/
421
+ next if host['platform'].include?('netscaler')
427
422
  logger.notify "Disabling updates.puppetlabs.com by modifying hosts file to resolve updates to 127.0.0.1 on #{host}"
428
423
  set_etc_hosts(host, "127.0.0.1\tupdates.puppetlabs.com\n")
429
424
  end
@@ -440,42 +435,40 @@ module Beaker
440
435
  logger = opts[:logger]
441
436
  block_on host do |host|
442
437
  logger.debug "Update sshd_config to allow root login"
443
- if host['platform'] =~ /osx/
438
+ if host['platform'].include?('osx')
444
439
  # If osx > 10.10 use '/private/etc/ssh/sshd_config', else use '/etc/sshd_config'
445
440
  ssh_config_file = '/private/etc/ssh/sshd_config'
446
- ssh_config_file = '/etc/sshd_config' if host['platform'] =~ /^osx-10\.(9|10)/i
441
+ ssh_config_file = '/etc/sshd_config' if /^osx-10\.(9|10)/i.match?(host['platform'])
447
442
 
448
443
  host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin Yes/g' #{ssh_config_file}"))
449
444
  host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' #{ssh_config_file}"))
450
- elsif host['platform'] =~ /freebsd/
445
+ elsif host['platform'].include?('freebsd')
451
446
  host.exec(Command.new("sudo sed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
452
- elsif host['platform'] =~ /openbsd/
447
+ elsif host['platform'].include?('openbsd')
453
448
  host.exec(Command.new("sudo perl -pi -e 's/^PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config"), {:pty => true} )
454
- elsif host['platform'] =~ /solaris-10/
449
+ elsif host['platform'].include?('solaris-10')
455
450
  host.exec(Command.new("sudo gsed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
456
- elsif host['platform'] =~ /solaris-11/
451
+ elsif host['platform'].include?('solaris-11')
457
452
  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} )
458
453
  host.exec(Command.new("sudo gsed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
459
- elsif host['platform'] =~ /f5/
454
+ elsif host['platform'].include?('f5') || host.is_powershell?
460
455
  #interacting with f5 should using tmsh
461
456
  logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}")
462
457
  elsif host.is_cygwin?
463
458
  host.exec(Command.new("sed -ri 's/^#?PermitRootLogin /PermitRootLogin yes/' /etc/sshd_config"), {:pty => true})
464
- elsif host.is_powershell?
465
- logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}")
466
459
  else
467
460
  host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), {:pty => true})
468
461
  end
469
462
  #restart sshd
470
- if host['platform'] =~ /debian|ubuntu|cumulus/
463
+ if /debian|ubuntu|cumulus/.match?(host['platform'])
471
464
  host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true})
472
- elsif host['platform'] =~ /arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/
465
+ elsif /arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform'])
473
466
  host.exec(Command.new("sudo -E systemctl restart sshd.service"), {:pty => true})
474
- elsif host['platform'] =~ /centos|el-|redhat|fedora|eos/
467
+ elsif /centos|el-|redhat|fedora|eos/.match?(host['platform'])
475
468
  host.exec(Command.new("sudo -E /sbin/service sshd reload"), {:pty => true})
476
- elsif host['platform'] =~ /(free|open)bsd/
469
+ elsif /(free|open)bsd/.match?(host['platform'])
477
470
  host.exec(Command.new("sudo /etc/rc.d/sshd restart"))
478
- elsif host['platform'] =~ /solaris/
471
+ elsif host['platform'].include?('solaris')
479
472
  host.exec(Command.new("sudo -E svcadm restart network/ssh"), {:pty => true} )
480
473
  else
481
474
  logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}")
@@ -490,11 +483,11 @@ module Beaker
490
483
  def disable_se_linux host, opts
491
484
  logger = opts[:logger]
492
485
  block_on host do |host|
493
- if host['platform'] =~ /centos|el-|redhat|fedora|eos/
494
- @logger.debug("Disabling se_linux on #{host.name}")
486
+ if /centos|el-|redhat|fedora|eos/.match?(host['platform'])
487
+ logger.debug("Disabling se_linux on #{host.name}")
495
488
  host.exec(Command.new("sudo su -c \"setenforce 0\""), {:pty => true})
496
489
  else
497
- @logger.warn("Attempting to disable SELinux on non-supported platform: #{host.name}: #{host['platform']}")
490
+ logger.warn("Attempting to disable SELinux on non-supported platform: #{host.name}: #{host['platform']}")
498
491
  end
499
492
  end
500
493
  end
@@ -506,7 +499,7 @@ module Beaker
506
499
  def disable_iptables host, opts
507
500
  logger = opts[:logger]
508
501
  block_on host do |host|
509
- if host['platform'] =~ /centos|el-|redhat|fedora|eos/
502
+ if /centos|el-|redhat|fedora|eos/.match?(host['platform'])
510
503
  logger.debug("Disabling iptables on #{host.name}")
511
504
  host.exec(Command.new("sudo su -c \"/etc/init.d/iptables stop\""), {:pty => true})
512
505
  else
@@ -550,7 +543,7 @@ module Beaker
550
543
  def additive_hash_merge h1, h2
551
544
  merged_hash = {}
552
545
  normalized_h2 = h2.inject({}) { |h, (k, v)| h[k.to_s.upcase] = v; h }
553
- h1.each_pair do |key, val|
546
+ h1.each_pair do |key, _val|
554
547
  normalized_key = key.to_s.upcase
555
548
  if normalized_h2.has_key?(normalized_key)
556
549
  merged_hash[key] = [h1[key], normalized_h2[normalized_key]]
@@ -594,7 +587,7 @@ module Beaker
594
587
 
595
588
  logger.debug("setting local environment on #{host.name}")
596
589
 
597
- if host['platform'] =~ /windows/ && host.is_cygwin?
590
+ if host['platform'].include?('windows') && host.is_cygwin?
598
591
  env['CYGWIN'] = 'nodosfilewarning'
599
592
  end
600
593
 
@@ -56,7 +56,7 @@ module Beaker
56
56
 
57
57
  DEFAULT_CONNECTION_PREFERENCE = [:ip, :vmhostname, :hostname]
58
58
  # SSH connection method preference. Can be overwritten by hypervisor to change the order
59
- def connection_preference(host)
59
+ def connection_preference(_host)
60
60
  DEFAULT_CONNECTION_PREFERENCE
61
61
  end
62
62
 
@@ -105,9 +105,9 @@ module Beaker
105
105
  if @options[:disable_updates]
106
106
  disable_updates(@hosts, @options)
107
107
  end
108
- rescue SignalException => ex
109
- if ex.signo == 15 #SIGTERM
110
- report_and_raise(@logger, ex, "configure")
108
+ rescue SignalException => e
109
+ if e.signo == 15 #SIGTERM
110
+ report_and_raise(@logger, e, "configure")
111
111
  end
112
112
  raise
113
113
  end
@@ -19,7 +19,7 @@ module Beaker
19
19
  connection
20
20
  end
21
21
 
22
- def connect options = {}
22
+ def connect _options = {}
23
23
  @logger.debug "Local connection, no connection to start"
24
24
  end
25
25
 
@@ -35,7 +35,7 @@ module Beaker
35
35
  ENV.replace(backup)
36
36
  end
37
37
 
38
- def execute command, options = {}, stdout_callback = nil, stderr_callback = stdout_callback
38
+ def execute command, _options = {}, stdout_callback = nil, _stderr_callback = stdout_callback
39
39
  result = Result.new(@hostname, command)
40
40
  envs = {}
41
41
  if File.readable?(@ssh_env_file)
@@ -46,7 +46,7 @@ module Beaker
46
46
  end
47
47
 
48
48
  begin
49
- clean_env = ENV.reject{ |k| k =~ /^BUNDLE|^RUBY|^GEM/ }
49
+ clean_env = ENV.reject{ |k| /^BUNDLE|^RUBY|^GEM/.match?(k) }
50
50
 
51
51
  with_env(clean_env) do
52
52
  std_out, std_err, status = Open3.capture3(envs, command)
data/lib/beaker/logger.rb CHANGED
@@ -65,8 +65,6 @@ module Beaker
65
65
  @log_level = :trace
66
66
  when /debug/i, :debug
67
67
  @log_level = :debug
68
- when /verbose/i, :verbose
69
- @log_level = :verbose
70
68
  when /info/i, :info
71
69
  @log_level = :info
72
70
  when /notify/i, :notify
@@ -132,9 +130,7 @@ module Beaker
132
130
  # @param [Array<IO, String>] dest Array of strings (each used as a file path) and IO steams that messages will be printed to
133
131
  def add_destination(dest)
134
132
  case dest
135
- when IO
136
- @destinations << dest
137
- when StringIO
133
+ when IO, StringIO
138
134
  @destinations << dest
139
135
  when String
140
136
  @destinations << File.open(dest, 'w')
@@ -147,9 +143,7 @@ module Beaker
147
143
  # @param [String, IO] dest String representing a file path or IO stream
148
144
  def remove_destination(dest)
149
145
  case dest
150
- when IO
151
- @destinations.delete(dest)
152
- when StringIO
146
+ when IO, StringIO
153
147
  @destinations.delete(dest)
154
148
  when String
155
149
  @destinations.delete_if {|d| d.respond_to?(:path) and d.path == dest}
@@ -220,7 +214,7 @@ module Beaker
220
214
  prefix_log_line s
221
215
  end
222
216
  else
223
- line.gsub!(/\r/, '')
217
+ line.delete!("\r")
224
218
  has_ending_newline = line.end_with?("\n")
225
219
  actual_lines = line.split("\n")
226
220
  actual_lines.map! do |actual_line|
@@ -233,7 +227,7 @@ module Beaker
233
227
  end
234
228
 
235
229
  # Indent the step level for the duration of block.
236
- def with_indent(&block)
230
+ def with_indent()
237
231
  old_line_prefix = self.line_prefix.dup
238
232
  self.line_prefix << ' '
239
233
  yield
@@ -444,7 +438,7 @@ module Beaker
444
438
  end
445
439
 
446
440
  # And remove lines that contain our program name in them
447
- completely_purged = mostly_purged.reject {|line| line.include? $0 }
441
+ mostly_purged.reject {|line| line.include? $0 }
448
442
  end
449
443
 
450
444
  # Utility method that takes a path as input, checks each component
@@ -21,7 +21,7 @@ module Beaker
21
21
  def self.write_xml(xml_file, stylesheet, &block)
22
22
  doc, suites = self.get_xml_contents(xml_file, name, stylesheet)
23
23
 
24
- if block_given?
24
+ if block
25
25
  case block.arity
26
26
  when 2
27
27
  yield doc, suites
@@ -86,7 +86,7 @@ module Beaker
86
86
  suites = REXML::XPath.first(doc, "testsuites")
87
87
  #remove old data
88
88
  suites.elements.each("testsuite") do |e|
89
- if e.name =~ /#{name}/
89
+ if /#{name}/.match?(e.name)
90
90
  suites.delete_element e
91
91
  end
92
92
  end
@@ -17,7 +17,7 @@ module Beaker
17
17
  def provision? options, host
18
18
  command_line_says = options[:provision]
19
19
  host_says = host['hypervisor'] && (host.has_key?('provision') ? host['provision'] : true)
20
- (command_line_says && host_says) or (host['hypervisor'] =~/(vagrant)/)
20
+ (command_line_says && host_says) or host['hypervisor'].include?('vagrant')
21
21
  end
22
22
 
23
23
  attr_accessor :hosts, :hypervisors
@@ -53,7 +53,7 @@ module Beaker
53
53
  end
54
54
  @hypervisors = {}
55
55
  #sort hosts by their hypervisor, use hypervisor 'none' if no hypervisor is specified
56
- hostless_options = Beaker::Options::OptionsHash.new.merge(@options.select{ |k,v| k.to_s !~ /HOSTS/})
56
+ hostless_options = Beaker::Options::OptionsHash.new.merge(@options.select{ |k,_v| !k.to_s.include?('HOSTS')})
57
57
  @options['HOSTS'].each_key do |name|
58
58
  host_hash = @options['HOSTS'][name]
59
59
  hypervisor = host_hash['hypervisor']
@@ -191,7 +191,7 @@ module Beaker
191
191
  'slow (attempt to continue run post test failure)',
192
192
  'stop (DEPRECATED, please use fast)',
193
193
  '(default: slow)' do |mode|
194
- @cmd_options[:fail_mode] = mode =~ /stop/ ? 'fast' : mode
194
+ @cmd_options[:fail_mode] = mode.include?('stop') ? 'fast' : mode
195
195
  end
196
196
 
197
197
  opts.on '--test-results-file /FILE/TO/SAVE/TO.rb',
@@ -2,7 +2,24 @@ module Beaker
2
2
  module Options
3
3
  #A set of functions to parse hosts files
4
4
  module HostsFileParser
5
- PERMITTED_YAML_CLASSES = [Beaker::Options::OptionsHash, Beaker::Platform, Symbol, Time]
5
+ PERMITTED_YAML_CLASSES = [
6
+ 'Beaker',
7
+ 'Beaker::Logger',
8
+ 'Beaker::Options::OptionsHash',
9
+ 'Beaker::Platform',
10
+ 'Beaker::Result',
11
+ 'File',
12
+ 'IO',
13
+ 'Logger',
14
+ 'Logger::Formatter',
15
+ 'Logger::LogDevice',
16
+ 'Monitor',
17
+ 'Net::SSH::Prompt',
18
+ 'StringifyHash',
19
+ 'StringIO',
20
+ 'Symbol',
21
+ 'Time',
22
+ ]
6
23
 
7
24
  # Read the contents of the hosts.cfg into an OptionsHash, merge the 'CONFIG' section into the OptionsHash, return OptionsHash
8
25
  # @param [String] hosts_file_path The path to the hosts file
@@ -75,7 +92,7 @@ module Beaker
75
92
  # @param [String] error_message Message to print if {::Psych::SyntaxError}
76
93
  # is raised during block execution
77
94
  # @return [OptionsHash] Updated host_options with host info merged
78
- def self.merge_hosts_yaml( host_options, error_message, &block )
95
+ def self.merge_hosts_yaml( host_options, error_message )
79
96
  begin
80
97
  loaded_host_options = yield
81
98
  rescue Psych::SyntaxError => e
@@ -98,9 +115,9 @@ module Beaker
98
115
  ERB.new(template, nil, '-')
99
116
  end
100
117
  if RUBY_VERSION >= '2.6'
101
- YAML.safe_load(erb_obj.result(b), permitted_classes: PERMITTED_YAML_CLASSES)
118
+ YAML.safe_load(erb_obj.result(b), permitted_classes: PERMITTED_YAML_CLASSES, aliases: true)
102
119
  else
103
- YAML.load(erb_obj.result(b))
120
+ YAML.load(erb_obj.result(b)) # rubocop:disable Security/YAMLLoad
104
121
  end
105
122
  end
106
123
  end
@@ -28,7 +28,7 @@ module Beaker
28
28
  result = Beaker::Options::OptionsHash.new
29
29
  if options_file_path
30
30
  options_file_path = File.expand_path(options_file_path)
31
- unless File.exists?(options_file_path)
31
+ unless File.exist?(options_file_path)
32
32
  raise ArgumentError, "Specified options file '#{options_file_path}' does not exist!"
33
33
  end
34
34
  # This eval will allow the specified options file to have access to our
@@ -15,7 +15,7 @@ module Beaker
15
15
  #
16
16
  # @return [Boolean]
17
17
  def is_pe?
18
- self[:type] ? self[:type] =~ /pe/ : true
18
+ self[:type] ? self[:type].include?('pe') : true
19
19
  end
20
20
 
21
21
  # Determine the puppet type of the ObjectHash
@@ -31,8 +31,6 @@ module Beaker
31
31
  case self[:type]
32
32
  when /pe/
33
33
  :pe
34
- when /foss/
35
- :foss
36
34
  else
37
35
  :foss
38
36
  end
@@ -43,7 +43,7 @@ module Beaker
43
43
  arry = []
44
44
  if arg.is_a?(Array)
45
45
  arry += arg
46
- elsif arg =~ /,/
46
+ elsif arg.include?(',')
47
47
  arry += arg.split(',')
48
48
  else
49
49
  arry << arg
@@ -281,7 +281,7 @@ module Beaker
281
281
  # @raise [ArgumentError] if a hosts file is generated, but it can't
282
282
  # be read by the HostsFileParser
283
283
  def parse_hosts_options
284
- if @options[:hosts_file].nil? || File.exists?(@options[:hosts_file])
284
+ if @options[:hosts_file].nil? || File.exist?(@options[:hosts_file])
285
285
  #read the hosts file that contains the node configuration and hypervisor info
286
286
  return Beaker::Options::HostsFileParser.parse_hosts_file(@options[:hosts_file])
287
287
  end
@@ -298,11 +298,11 @@ module Beaker
298
298
  bhg_cli = BeakerHostGenerator::CLI.new(host_generator_options)
299
299
  bhg_cli.execute
300
300
  rescue BeakerHostGenerator::Exceptions::Error,
301
- BeakerHostGenerator::Exceptions::InvalidNodeSpecError => error
301
+ BeakerHostGenerator::Exceptions::InvalidNodeSpecError => e
302
302
  error_message = "\nbeaker-hostgenerator was not able to use this value as input."
303
303
  error_message << "\nExiting with an Error.\n\n"
304
304
  $stderr.puts error_message
305
- raise error
305
+ raise e
306
306
  end
307
307
 
308
308
  @options[:hosts_file_generated] = true
@@ -375,7 +375,7 @@ module Beaker
375
375
  #check that windows/el-4 boxes are only agents (solaris can be a master in foss cases)
376
376
  @options[:HOSTS].each_key do |name|
377
377
  host = @options[:HOSTS][name]
378
- if host[:platform] =~ /windows|el-4/
378
+ if /windows|el-4/.match?(host[:platform])
379
379
  test_host_roles(name, host)
380
380
  end
381
381
 
@@ -461,7 +461,7 @@ module Beaker
461
461
  exclude_roles = %w(master database dashboard)
462
462
  host_roles = host_hash[:roles]
463
463
  unless (host_roles & exclude_roles).empty?
464
- @validator.parser_error "#{host_hash[:platform].to_s} box '#{host_name}' may not have roles: #{exclude_roles.join(', ')}."
464
+ @validator.parser_error "#{host_hash[:platform]} box '#{host_name}' may not have roles: #{exclude_roles.join(', ')}."
465
465
  end
466
466
  end
467
467
 
@@ -45,7 +45,7 @@ module Beaker
45
45
  def select_env_by_regex regex
46
46
  envs = Beaker::Options::OptionsHash.new
47
47
  ENV.each_pair do | k, v |
48
- if k.to_s =~ /#{regex}/
48
+ if /#{regex}/.match?(k.to_s)
49
49
  envs[k] = v
50
50
  end
51
51
  end
@@ -105,7 +105,7 @@ module Beaker
105
105
  found = found.merge(format_found_env_vars( collect_env_vars( ENVIRONMENT_SPEC )))
106
106
  found[:answers] = select_env_by_regex('\\Aq_')
107
107
 
108
- found.delete_if {|key, value| value.nil? or value.empty? }
108
+ found.delete_if {|_key, value| value.nil? or value.empty? }
109
109
  found
110
110
  end
111
111
 
@@ -52,7 +52,7 @@ module Beaker
52
52
  # @return [nil] Does not return anything
53
53
  def validate_fail_mode(fail_mode)
54
54
  #check for valid fail mode
55
- if fail_mode !~ VALID_FAIL_MODES
55
+ unless fail_mode.is_a?(String) && VALID_FAIL_MODES.match?(fail_mode)
56
56
  validator_error "--fail-mode must be one of fast or slow, not '#{fail_mode}'"
57
57
  end
58
58
  end
@@ -63,7 +63,7 @@ module Beaker
63
63
  # @return [nil] Does not return anything
64
64
  def validate_preserve_hosts(hosts_setting)
65
65
  #check for valid preserve_hosts option
66
- if hosts_setting !~ VALID_PRESERVE_HOSTS
66
+ unless hosts_setting.is_a?(String) && VALID_PRESERVE_HOSTS.match?(hosts_setting)
67
67
  validator_error("--preserve_hosts must be one of always, onfail, onpass or never, not '#{hosts_setting}'")
68
68
  end
69
69
  end
data/lib/beaker/perf.rb CHANGED
@@ -29,7 +29,7 @@ module Beaker
29
29
  def setup_perf_on_host(host)
30
30
  @logger.perf_output("Setup perf on host: " + host)
31
31
  # Install sysstat if required
32
- if host['platform'] =~ PERF_SUPPORTED_PLATFORMS
32
+ if PERF_SUPPORTED_PLATFORMS.match?(host['platform'])
33
33
  PERF_PACKAGES.each do |pkg|
34
34
  if not host.check_for_package pkg
35
35
  host.install_package pkg
@@ -39,22 +39,22 @@ module Beaker
39
39
  @logger.perf_output("Perf (sysstat) not supported on host: " + host)
40
40
  end
41
41
 
42
- if host['platform'] =~ /debian|ubuntu|cumulus/
42
+ if /debian|ubuntu|cumulus/.match?(host['platform'])
43
43
  @logger.perf_output("Modify /etc/default/sysstat on Debian and Ubuntu platforms")
44
44
  host.exec(Command.new('sed -i s/ENABLED=\"false\"/ENABLED=\"true\"/ /etc/default/sysstat'))
45
- elsif host['platform'] =~ /opensuse|sles/
45
+ elsif /opensuse|sles/.match?(host['platform'])
46
46
  @logger.perf_output("Creating symlink from /etc/sysstat/sysstat.cron to /etc/cron.d")
47
47
  host.exec(Command.new('ln -s /etc/sysstat/sysstat.cron /etc/cron.d'),:acceptable_exit_codes => [0,1])
48
48
  end
49
- if @options[:collect_perf_data] =~ /aggressive/
49
+ if @options[:collect_perf_data]&.include?('aggressive')
50
50
  @logger.perf_output("Enabling aggressive sysstat polling")
51
- if host['platform'] =~ /debian|ubuntu/
51
+ if /debian|ubuntu/.match?(host['platform'])
52
52
  host.exec(Command.new('sed -i s/5-55\\\/10/*/ /etc/cron.d/sysstat'))
53
- elsif host['platform'] =~ /centos|el|fedora|oracle|redhat|scientific/
53
+ elsif /centos|el|fedora|oracle|redhat|scientific/.match?(host['platform'])
54
54
  host.exec(Command.new('sed -i s/*\\\/10/*/ /etc/cron.d/sysstat'))
55
55
  end
56
56
  end
57
- if host['platform'] =~ PERF_START_PLATFORMS # SLES doesn't need this step
57
+ if PERF_START_PLATFORMS.match?(host['platform']) # SLES doesn't need this step
58
58
  host.exec(Command.new('service sysstat start'))
59
59
  end
60
60
  end
@@ -73,8 +73,8 @@ module Beaker
73
73
  # @return [void] The report is sent to the logging output
74
74
  def get_perf_data(host, perf_start, perf_end)
75
75
  @logger.perf_output("Getting perf data for host: " + host)
76
- if host['platform'] =~ PERF_SUPPORTED_PLATFORMS # All flavours of Linux
77
- if not @options[:collect_perf_data] =~ /aggressive/
76
+ if PERF_SUPPORTED_PLATFORMS.match?(host['platform']) # All flavours of Linux
77
+ if not @options[:collect_perf_data]&.include?('aggressive')
78
78
  host.exec(Command.new("sar -A -s #{perf_start.strftime("%H:%M:%S")} -e #{perf_end.strftime("%H:%M:%S")}"),:acceptable_exit_codes => [0,1,2])
79
79
  end
80
80
  if (defined? @options[:graphite_server] and not @options[:graphite_server].nil?) and
@@ -82,7 +82,7 @@ module Beaker
82
82
  # * netscaler
83
83
  # * archlinux
84
84
  def initialize(name)
85
- if name !~ PLATFORMS
85
+ if !PLATFORMS.match?(name)
86
86
  raise ArgumentError, "Unsupported platform name #{name}"
87
87
  end
88
88