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
@@ -6,19 +6,19 @@ module PSWindows::Pkg
6
6
  result.exit_code == 0
7
7
  end
8
8
 
9
- def check_for_package(name)
9
+ def check_for_package(_name)
10
10
  #HACK NOOP
11
11
  #raise "Cannot check for package #{name} on #{self}"
12
12
  0
13
13
  end
14
14
 
15
- def install_package(name, cmdline_args = '')
15
+ def install_package(_name, _cmdline_args = '')
16
16
  #HACK NOOP
17
17
  #raise "Package #{name} cannot be installed on #{self}"
18
18
  0
19
19
  end
20
20
 
21
- def uninstall_package(name, cmdline_args = '')
21
+ def uninstall_package(_name, _cmdline_args = '')
22
22
  #HACK NOOP
23
23
  #raise "Package #{name} cannot be uninstalled on #{self}"
24
24
  0
@@ -27,7 +27,7 @@ module PSWindows::Pkg
27
27
  #Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
28
28
  #@return [Boolean] true if x86_64, false otherwise
29
29
  def determine_if_x86_64
30
- (identify_windows_architecture =~ /64/) == 0
30
+ identify_windows_architecture.include?('64')
31
31
  end
32
32
 
33
33
  private
@@ -37,7 +37,7 @@ module PSWindows::Pkg
37
37
  arch = nil
38
38
  execute("wmic os get osarchitecture", :accept_all_exit_codes => true) do |result|
39
39
  arch = if result.exit_code == 0
40
- result.stdout =~ /64/ ? '64' : '32'
40
+ result.stdout.include?('64') ? '64' : '32'
41
41
  else
42
42
  identify_windows_architecture_from_os_name_for_win2003
43
43
  end
@@ -49,7 +49,7 @@ module PSWindows::Pkg
49
49
  def identify_windows_architecture_from_os_name_for_win2003
50
50
  arch = nil
51
51
  execute("wmic os get name", :accept_all_exit_codes => true) do |result|
52
- arch = result.stdout =~ /64/ ? '64' : '32'
52
+ arch = result.stdout.include?('64') ? '64' : '32'
53
53
  end
54
54
  arch
55
55
  end
@@ -1,7 +1,7 @@
1
1
  module PSWindows::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list()
5
5
  execute('cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value') do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module PSWindows::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("net user \"#{name}\"") do |result|
19
19
  fail_test "failed to get user #{name}" if result.exit_code != 0
20
20
 
@@ -188,7 +188,7 @@ module Unix::Exec
188
188
  # This is for sles based hosts.
189
189
  # @param [String] env_file The ssh environment file to read from
190
190
  def mirror_env_to_profile_d env_file
191
- if self[:platform] =~ /opensuse|sles-/
191
+ if /opensuse|sles-/.match?(self[:platform])
192
192
  @logger.debug("mirroring environment to /etc/profile.d on opensuse/sles platform host")
193
193
  cur_env = exec(Beaker::Command.new("cat #{env_file}")).stdout
194
194
  shell_env = ''
@@ -306,7 +306,7 @@ module Unix::Exec
306
306
  directory = tmpdir()
307
307
  exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit"))
308
308
  exec(Beaker::Command.new("mv #{directory}/sshd_config.permit /etc/ssh/sshd_config"))
309
- exec(Beaker::Command.new("echo '' >/etc/environment")) if self['platform'] =~ /ubuntu-2(0|2).04/
309
+ exec(Beaker::Command.new("echo '' >/etc/environment")) if /ubuntu-2(0|2).04/.match?(self['platform'])
310
310
  when /(free|open)bsd/
311
311
  exec(Beaker::Command.new("sudo perl -pi -e 's/^#?PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config"), {:pty => true} )
312
312
  else
@@ -363,7 +363,7 @@ module Unix::Exec
363
363
  # @param [Hash] opts optional parameters
364
364
  #
365
365
  # @return [String] Command string as needed for this host
366
- def prepend_commands(command = '', user_pc = '', opts = {})
366
+ def prepend_commands(_command = '', user_pc = '', _opts = {})
367
367
  user_pc
368
368
  end
369
369
 
@@ -374,7 +374,7 @@ module Unix::Exec
374
374
  # @param [Hash] opts optional parameters
375
375
  #
376
376
  # @return [String] Command string as needed for this host
377
- def append_commands(command = '', user_ac = '', opts = {})
377
+ def append_commands(_command = '', user_ac = '', _opts = {})
378
378
  user_ac
379
379
  end
380
380
 
@@ -400,7 +400,7 @@ module Unix::Exec
400
400
  arch = $3
401
401
  arch = 'amd64' if ['x64', 'x86_64'].include?(arch)
402
402
  add_env_var('PKG_PATH', "http://ftp.openbsd.org/pub/OpenBSD/#{version}/packages/#{arch}/")
403
- elsif self['platform'] =~ /solaris-10/
403
+ elsif self['platform'].include?('solaris-10')
404
404
  add_env_var('PATH', '/opt/csw/bin')
405
405
  end
406
406
 
@@ -418,7 +418,7 @@ module Unix::Exec
418
418
  end
419
419
 
420
420
  def enable_remote_rsyslog(server = 'rsyslog.ops.puppetlabs.net', port = 514)
421
- if self['platform'] !~ /ubuntu/
421
+ if !self['platform'].include?('ubuntu')
422
422
  @logger.warn "Enabling rsyslog is only implemented for ubuntu hosts"
423
423
  return
424
424
  end
@@ -116,7 +116,7 @@ module Unix::File
116
116
  when /fedora|el|redhat|centos|cisco_nexus|cisco_ios_xr|opensuse|sles/
117
117
  variant = 'el' if ['centos', 'redhat'].include?(variant)
118
118
 
119
- variant = 'redhatfips' if self['packaging_platform'] =~ /redhatfips/
119
+ variant = 'redhatfips' if self['packaging_platform']&.include?('redhatfips')
120
120
 
121
121
  if variant == 'cisco_nexus'
122
122
  variant = 'cisco-wrlinux'
@@ -170,8 +170,7 @@ module Unix::File
170
170
  #
171
171
  # @return [String] the text of the noask file
172
172
  def noask_file_text
173
- variant, version, arch, codename = self['platform'].to_array
174
- if variant == 'solaris' && version == '10'
173
+ if self['platform'].variant == 'solaris' && self['platform'].version == '10'
175
174
  noask = <<NOASK
176
175
  # Write the noask file to a temporary directory
177
176
  # please see man -s 4 admin for details about this file:
@@ -217,7 +216,7 @@ NOASK
217
216
  # @param [String] scp_file_target File path to target SCP location on host
218
217
  #
219
218
  # @return nil
220
- def scp_post_operations(scp_file_actual, scp_file_target)
219
+ def scp_post_operations(_scp_file_actual, _scp_file_target)
221
220
  nil
222
221
  end
223
222
  end
@@ -1,7 +1,7 @@
1
1
  module Unix::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list(&block)
4
+ def group_list()
5
5
  execute("getent group") do |result|
6
6
  groups = []
7
7
  result.stdout.each_line do |line|
@@ -14,9 +14,9 @@ module Unix::Group
14
14
  end
15
15
  end
16
16
 
17
- def group_get(name, &block)
17
+ def group_get(name)
18
18
  execute("getent group #{name}") do |result|
19
- fail_test "failed to get group #{name}" unless result.stdout =~ /^#{name}:.*:[0-9]+:/
19
+ fail_test "failed to get group #{name}" unless /^#{name}:.*:[0-9]+:/.match?(result.stdout)
20
20
 
21
21
  yield result if block_given?
22
22
  result
@@ -27,7 +27,7 @@ module Unix::Pkg
27
27
  case self['platform']
28
28
  when /sles-10/
29
29
  result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
30
- result.stdout =~ /No packages found/ ? (return false) : (return result.exit_code == 0)
30
+ result.stdout.include?('No packages found') ? (return false) : (return result.exit_code == 0)
31
31
  when /opensuse|sles-/
32
32
  if !self[:sles_rpmkeys_nightly_pl_imported]
33
33
  # The `:sles_rpmkeys_nightly_pl_imported` key is only read here at this
@@ -64,7 +64,7 @@ module Unix::Pkg
64
64
  # If apt has not been updated since the last repo deployment it is
65
65
  # updated. Otherwise this is a noop
66
66
  def update_apt_if_needed
67
- if self['platform'] =~ /debian|ubuntu|cumulus|huaweios/
67
+ if /debian|ubuntu|cumulus|huaweios/.match?(self['platform'])
68
68
  if @apt_needs_update
69
69
  execute("apt-get update")
70
70
  @apt_needs_update = false
@@ -76,7 +76,7 @@ module Unix::Pkg
76
76
  # Except for the kernel. An upgrade will purge the modules for the currently running kernel
77
77
  # Before upgrading packages, we need to ensure we've the latest keyring
78
78
  def update_pacman_if_needed
79
- if self['platform'] =~ /archlinux/
79
+ if self['platform'].include?('archlinux')
80
80
  if @pacman_needs_update
81
81
  execute("pacman --sync --noconfirm --noprogressbar --refresh archlinux-keyring")
82
82
  execute("pacman --sync --noconfirm --noprogressbar --refresh --sysupgrade --ignore linux --ignore linux-docs --ignore linux-headers")
@@ -144,7 +144,7 @@ module Unix::Pkg
144
144
  raise ArgumentException
145
145
  end
146
146
  # If the package advises symlinks to be created, do it
147
- command.stdout.split(/\n/).select { |x| x =~ /^\s+ln\s/ }.each do |ln|
147
+ command.stdout.split("\n").select { |x| /^\s+ln\s/.match?(x) }.each do |ln|
148
148
  execute(ln, opts)
149
149
  end
150
150
  end
@@ -171,7 +171,7 @@ module Unix::Pkg
171
171
  # @api public
172
172
  def install_package_with_rpm(name, cmdline_args = '', opts = {})
173
173
  proxy = ''
174
- if name =~ /^http/ and opts[:package_proxy]
174
+ if name&.start_with?('http') and opts[:package_proxy]
175
175
  proxy = extract_rpm_proxy_options(opts[:package_proxy])
176
176
  end
177
177
  execute("rpm #{cmdline_args} -Uvh #{name} #{proxy}")
@@ -292,7 +292,7 @@ module Unix::Pkg
292
292
  # @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
293
293
  # @visibility private
294
294
  def deploy_package_repo(path, name, version)
295
- if not File.exists? path
295
+ if not File.exist? path
296
296
  @logger.warn "Was asked to deploy package repository from #{path}, but it doesn't exist!"
297
297
  return
298
298
  end
@@ -315,7 +315,7 @@ module Unix::Pkg
315
315
  #Examine the host system to determine the architecture
316
316
  #@return [Boolean] true if x86_64, false otherwise
317
317
  def determine_if_x86_64
318
- if self[:platform] =~ /solaris/
318
+ if self[:platform].include?('solaris')
319
319
  result = exec(Beaker::Command.new("uname -a | grep x86_64"), :accept_all_exit_codes => true)
320
320
  result.exit_code == 0
321
321
  else
@@ -361,7 +361,7 @@ module Unix::Pkg
361
361
  raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
362
362
  raise ArgumentError, error_message % "opts[:download_url]" unless opts[:download_url]
363
363
 
364
- variant, version, arch, codename = self['platform'].to_array
364
+ variant, version, arch, _codename = self['platform'].to_array
365
365
 
366
366
  version = version.split('.')[0] # packages are only published for major versions
367
367
 
@@ -425,14 +425,14 @@ module Unix::Pkg
425
425
  raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
426
426
  raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
427
427
 
428
- variant, version, arch, codename = self['platform'].to_array
428
+ variant, version, arch, _codename = self['platform'].to_array
429
429
 
430
430
  case variant
431
431
  when /^(solaris)$/
432
432
  release_path_end, release_file = solaris_puppet_agent_dev_package_info(
433
433
  puppet_collection, puppet_agent_version, opts )
434
434
  when /^(opensuse|sles|aix|el|centos|oracle|redhat|scientific)$/
435
- variant = 'el' if variant.match(/(?:el|centos|oracle|redhat|scientific)/)
435
+ variant = 'el' if variant.match?(/(?:el|centos|oracle|redhat|scientific)/)
436
436
  variant = 'sles' if variant == 'opensuse'
437
437
 
438
438
  if variant == 'aix'
@@ -463,7 +463,7 @@ module Unix::Pkg
463
463
  # {Windows::Pkg#pe_puppet_agent_promoted_package_info} to see usage.
464
464
  # 2. release_file Path to the file on release build servers
465
465
  # 3. download_file Filename for the package itself
466
- def pe_puppet_agent_promoted_package_info( puppet_collection = nil, opts = {} )
466
+ def pe_puppet_agent_promoted_package_info( puppet_collection = nil, _opts = {} )
467
467
  error_message = "Must provide %s argument to get puppet agent dev package information"
468
468
  raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
469
469
 
@@ -477,7 +477,7 @@ module Unix::Pkg
477
477
  if arch == 'x86_64'
478
478
  arch = 'amd64'
479
479
  end
480
- version = version[0,2] + '.' + version[2,2] if (variant =~ /ubuntu/ && !version.include?("."))
480
+ version = version[0,2] + '.' + version[2,2] if (variant.include?('ubuntu') && !version.include?("."))
481
481
  release_file = "/repos/apt/#{codename}/pool/#{puppet_collection}/p/puppet-agent/puppet-agent*#{arch}.deb"
482
482
  download_file = "puppet-agent-#{variant}-#{version}-#{arch}.tar.gz"
483
483
  when /^solaris$/
@@ -502,10 +502,10 @@ module Unix::Pkg
502
502
  #
503
503
  # @return nil
504
504
  def pe_puppet_agent_promoted_package_install(
505
- onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, opts
505
+ onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, _opts
506
506
  )
507
507
  uncompress_local_tarball( onhost_copied_download, onhost_copy_base, download_file )
508
- if self['platform'] =~ /^solaris/
508
+ if /^solaris/.match?(self['platform'])
509
509
  # above uncompresses the install from .tar.gz -> .p5p into the
510
510
  # onhost_copied_file directory w/a weird name. We have to read that file
511
511
  # name from the filesystem, so that we can provide it to install_local...
@@ -525,7 +525,7 @@ module Unix::Pkg
525
525
  #
526
526
  # @return nil
527
527
  def install_local_package(onhost_package_file, onhost_copy_dir = nil)
528
- variant, version, arch, codename = self['platform'].to_array
528
+ variant, version, _arch, _codename = self['platform'].to_array
529
529
  case variant
530
530
  when /^(fedora|el|redhat|centos)$/
531
531
  command_name = 'yum'
@@ -555,7 +555,7 @@ module Unix::Pkg
555
555
  #
556
556
  # @return nil
557
557
  def uncompress_local_tarball(onhost_tar_file, onhost_base_dir, download_file)
558
- variant, version, arch, codename = self['platform'].to_array
558
+ variant, version, _arch, _codename = self['platform'].to_array
559
559
  case variant
560
560
  when /^(fedora|el|centos|redhat|opensuse|sles|debian|ubuntu|cumulus)$/
561
561
  execute("tar -zxvf #{onhost_tar_file} -C #{onhost_base_dir}")
@@ -587,7 +587,7 @@ module Unix::Pkg
587
587
  #
588
588
  # @return [Beaker::Result] Result of installation command execution
589
589
  def solaris_install_local_package(package_path, noask_directory = nil)
590
- variant, version, arch, codename = self['platform'].to_array
590
+ variant, version, _arch, _codename = self['platform'].to_array
591
591
 
592
592
  version = version.split('.')[0] # packages are only published for major versions
593
593
 
@@ -1,7 +1,7 @@
1
1
  module Unix::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list()
5
5
  execute("getent passwd") do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
@@ -14,9 +14,9 @@ module Unix::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("getent passwd #{name}") do |result|
19
- fail_test "failed to get user #{name}" unless result.stdout =~ /^#{name}:/
19
+ fail_test "failed to get user #{name}" unless /^#{name}:/.match?(result.stdout)
20
20
 
21
21
  yield result if block_given?
22
22
  result
@@ -35,12 +35,14 @@ module Unix
35
35
  end
36
36
 
37
37
  def external_copy_base
38
- return @external_copy_base if @external_copy_base
39
- @external_copy_base = '/root'
40
- variant, version, arch, codename = self['platform'].to_array
41
- # Solaris 10 uses / as the root user directory. Solaris 11 uses /root (like most).
42
- @external_copy_base = '/' if variant == 'solaris' && version == '10'
43
- @external_copy_base
38
+ @external_copy_base ||= begin
39
+ if self['platform'].variant == 'solaris' && self['platform'].version == '10'
40
+ # Solaris 10 uses / as the root user directory. Solaris 11 uses /root (like most).
41
+ '/'
42
+ else
43
+ '/root'
44
+ end
45
+ end
44
46
  end
45
47
 
46
48
  # Tells you whether a host platform supports beaker's
@@ -49,10 +51,9 @@ module Unix
49
51
  # @return [String,nil] Reason message if set_env should be skipped,
50
52
  # nil if it should run.
51
53
  def skip_set_env?
52
- variant, version, arch, codename = self['platform'].to_array
53
- case variant
54
+ case self['platform'].variant
54
55
  when /^(f5|netscaler)$/
55
- "no puppet-agent package for network device platform '#{variant}'"
56
+ "no puppet-agent package for network device platform '#{self['platform'].variant}'"
56
57
  else
57
58
  nil
58
59
  end
@@ -94,7 +94,7 @@ module Windows::Exec
94
94
  # @option opts [Boolean] :cmd_exe whether cmd.exe should be used
95
95
  #
96
96
  # @return [String] Command string as needed for this host
97
- def prepend_commands(command = '', user_pc = nil, opts = {})
97
+ def prepend_commands(_command = '', user_pc = nil, opts = {})
98
98
  cygwin_prefix = (self.is_cygwin? and opts[:cmd_exe]) ? 'cmd.exe /c' : ''
99
99
  spacing = (user_pc && !cygwin_prefix.empty?) ? ' ' : ''
100
100
  "#{cygwin_prefix}#{spacing}#{user_pc}"
@@ -107,7 +107,7 @@ module Windows::Exec
107
107
  # @param [Hash] opts optional parameters
108
108
  #
109
109
  # @return [String] Command string as needed for this host
110
- def append_commands(command = '', user_ac = '', opts = {})
110
+ def append_commands(_command = '', user_ac = '', _opts = {})
111
111
  user_ac
112
112
  end
113
113
 
@@ -150,7 +150,7 @@ module Windows::Exec
150
150
  # @return [Boolean]
151
151
  def cygwin_installed?
152
152
  output = exec(Beaker::Command.new('cygcheck --check-setup cygwin'), :accept_all_exit_codes => true).stdout
153
- return true if output.match(/cygwin/) && output.match(/OK/)
153
+ return true if output.include?('cygwin') && output.include?('OK')
154
154
  false
155
155
  end
156
156
 
@@ -12,7 +12,7 @@ module Windows::File
12
12
  def system_temp_path
13
13
  # under CYGWIN %TEMP% may not be set
14
14
  tmp_path = execute('ECHO %SYSTEMROOT%', :cmdexe => true)
15
- tmp_path.gsub(/\n/, '') + '\\TEMP'
15
+ tmp_path.delete("\n") + '\\TEMP'
16
16
  end
17
17
 
18
18
  # (see {Beaker::Host::Unix::File#chown})
@@ -63,7 +63,7 @@ module Windows::File
63
63
  when :openssh
64
64
  path
65
65
  when :win32_openssh
66
- path.gsub('\\', '/')
66
+ path.tr('\\', '/')
67
67
  else
68
68
  raise ArgumentError, "windows/file.rb:scp_path: ssh server not recognized: '#{determine_ssh_server}'"
69
69
  end
@@ -1,7 +1,7 @@
1
1
  module Windows::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list(&block)
4
+ def group_list()
5
5
  execute('cmd /c echo "" | wmic group where localaccount="true" get name /format:value') do |result|
6
6
  groups = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module Windows::Group
14
14
  end
15
15
  end
16
16
 
17
- def group_get(name, &block)
17
+ def group_get(name)
18
18
  execute("net localgroup \"#{name}\"") do |result|
19
19
  fail_test "failed to get group #{name}" if result.exit_code != 0
20
20
 
@@ -23,7 +23,7 @@ module Windows::Group
23
23
  end
24
24
  end
25
25
 
26
- def group_gid(name)
26
+ def group_gid(_name)
27
27
  raise NotImplementedError, "Can't retrieve group gid on a Windows host"
28
28
  end
29
29
 
@@ -25,14 +25,14 @@ module Windows::Pkg
25
25
  execute("#{cygwin} -q -n -N -d -R #{rootdir} -s http://cygwin.osuosl.org -P #{name} #{cmdline_args}")
26
26
  end
27
27
 
28
- def uninstall_package(name, cmdline_args = '')
28
+ def uninstall_package(name, _cmdline_args = '')
29
29
  raise "Package #{name} cannot be uninstalled on #{self}"
30
30
  end
31
31
 
32
32
  #Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
33
33
  #@return [Boolean] true if x86_64, false otherwise
34
34
  def determine_if_x86_64
35
- (identify_windows_architecture =~ /64/) == 0
35
+ identify_windows_architecture.include?('64')
36
36
  end
37
37
 
38
38
  # Gets the path & file name for the puppet agent dev package on Windows
@@ -45,7 +45,7 @@ module Windows::Pkg
45
45
  # time. Note that it will not fail if not provided, however
46
46
  #
47
47
  # @return [String, String] Path to the directory and filename of the package, respectively
48
- def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
48
+ def puppet_agent_dev_package_info( _puppet_collection = nil, puppet_agent_version = nil, opts = {} )
49
49
  release_path_end = 'windows'
50
50
  is_config_32 = self['ruby_arch'] == 'x86' || self['install_32'] || opts['install_32']
51
51
  should_install_64bit = self.is_x86_64? && !is_config_32
@@ -55,7 +55,7 @@ module Windows::Pkg
55
55
  arch_suffix = should_install_64bit ? '64' : '86'
56
56
  # If a version was specified, use it; otherwise fall back to a default name.
57
57
  # Avoid when puppet_agent_version is set to a SHA, which isn't used in package names.
58
- if puppet_agent_version =~ /^\d+\.\d+\.\d+/
58
+ if /^\d+\.\d+\.\d+/.match?(puppet_agent_version)
59
59
  release_file = "puppet-agent-#{puppet_agent_version}-x#{arch_suffix}.msi"
60
60
  else
61
61
  release_file = "puppet-agent-x#{arch_suffix}.msi"
@@ -72,7 +72,7 @@ module Windows::Pkg
72
72
  # 1. release_path_end Suffix for the release_path
73
73
  # 2. release_file Path to the file on release build servers
74
74
  # 3. download_file Filename for the package itself
75
- def pe_puppet_agent_promoted_package_info( puppet_collection = nil, opts = {} )
75
+ def pe_puppet_agent_promoted_package_info( _puppet_collection = nil, _opts = {} )
76
76
  is_config_32 = self['ruby_arch'] == 'x86' || self['install_32'] || self['install_32']
77
77
  should_install_64bit = self.is_x86_64? && !is_config_32
78
78
  # only install 64bit builds if
@@ -89,7 +89,7 @@ module Windows::Pkg
89
89
 
90
90
  # @api private
91
91
  def identify_windows_architecture
92
- platform.arch =~ /64/ ? '64' : '32'
92
+ platform.arch.include?('64') ? '64' : '32'
93
93
  end
94
94
 
95
95
  end
@@ -1,7 +1,7 @@
1
1
  module Windows::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list()
5
5
  execute('cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value') do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module Windows::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("net user \"#{name}\"") do |result|
19
19
  fail_test "failed to get user #{name}" if result.exit_code != 0
20
20
 
@@ -38,11 +38,11 @@ module Windows
38
38
  return @ssh_server if @ssh_server
39
39
  @ssh_server = :openssh
40
40
  status = execute('cmd.exe /c sc query BvSshServer', :accept_all_exit_codes => true)
41
- if status =~ /4 RUNNING/
41
+ if status&.include?('4 RUNNING')
42
42
  @ssh_server = :bitvise
43
43
  else
44
44
  status = execute('cmd.exe /c sc qc sshd', :accept_all_exit_codes => true)
45
- if status =~ /C:\\Windows\\System32\\OpenSSH\\sshd\.exe/
45
+ if status&.include?('C:\\Windows\\System32\\OpenSSH\\sshd.exe')
46
46
  @ssh_server = :win32_openssh
47
47
  end
48
48
  end
data/lib/beaker/host.rb CHANGED
@@ -37,7 +37,7 @@ module Beaker
37
37
  end
38
38
 
39
39
  def [](k)
40
- cmd = PuppetCommand.new(@command, "--configprint #{k.to_s}")
40
+ cmd = PuppetCommand.new(@command, "--configprint #{k}")
41
41
  @host.exec(cmd).stdout.strip
42
42
  end
43
43
  end
@@ -86,7 +86,7 @@ module Beaker
86
86
  # TODO: might want to consider caching here; not doing it for now because
87
87
  # I haven't thought through all of the possible scenarios that could
88
88
  # cause the value to change after it had been cached.
89
- result = puppet_configprint['node_name_value'].strip
89
+ puppet_configprint['node_name_value'].strip
90
90
  end
91
91
 
92
92
  def port_open? port
@@ -177,7 +177,7 @@ module Beaker
177
177
  end
178
178
 
179
179
  def is_pe?
180
- self['type'] && self['type'].to_s =~ /pe/
180
+ self['type'] && self['type'].to_s.include?('pe')
181
181
  end
182
182
 
183
183
  def is_cygwin?
@@ -450,7 +450,7 @@ module Beaker
450
450
  end
451
451
  if File.file?(source) or (File.directory?(source) and not has_ignore)
452
452
  source_file = source
453
- if has_ignore and (source =~ ignore_re)
453
+ if has_ignore and ignore_re&.match?(source)
454
454
  @logger.trace "After rejecting ignored files/dirs, there is no file to copy"
455
455
  source_file = nil
456
456
  result.stdout = "No files to copy"
@@ -462,7 +462,7 @@ module Beaker
462
462
  end
463
463
  else # a directory with ignores
464
464
  dir_source = Dir.glob("#{source}/**/*").reject do |f|
465
- f.gsub(/\A#{Regexp.escape(source)}/, '') =~ ignore_re #only match against subdirs, not full path
465
+ ignore_re&.match?(f.gsub(/\A#{Regexp.escape(source)}/, '')) #only match against subdirs, not full path
466
466
  end
467
467
  @logger.trace "After rejecting ignored files/dirs, going to scp [#{dir_source.join(", ")}]"
468
468
 
@@ -551,9 +551,9 @@ module Beaker
551
551
  #
552
552
  # We still want any user-set SSH config to win though
553
553
  filesystem_ssh_config = nil
554
- if ssh_opts[:config] && File.exists?(ssh_opts[:config])
554
+ if ssh_opts[:config] && File.exist?(ssh_opts[:config])
555
555
  filesystem_ssh_config = ssh_opts[:config]
556
- elsif self[:vagrant_ssh_config] && File.exists?(self[:vagrant_ssh_config])
556
+ elsif self[:vagrant_ssh_config] && File.exist?(self[:vagrant_ssh_config])
557
557
  filesystem_ssh_config = self[:vagrant_ssh_config]
558
558
  end
559
559