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
@@ -83,7 +83,7 @@ module Beaker
83
83
  @result = host.exec(command_object, opts)
84
84
 
85
85
  # Also, let additional checking be performed by the caller.
86
- if block_given?
86
+ if block
87
87
  case block.arity
88
88
  #block with arity of 0, just hand back yourself
89
89
  when 0
@@ -193,7 +193,7 @@ module Beaker
193
193
  # @return [Result] Returns the result of the SCP operation
194
194
  def scp_to host, from_path, to_path, opts = {}
195
195
  block_on host do | host |
196
- if host['platform'] =~ /windows/ && to_path.match('`cygpath')
196
+ if host['platform'].include?('windows') && to_path.match('`cygpath')
197
197
  result = on host, "echo #{to_path}"
198
198
  to_path = result.raw_output.chomp
199
199
  end
@@ -215,7 +215,7 @@ module Beaker
215
215
  # @return [Result] Returns the result of the rsync operation
216
216
  def rsync_to host, from_path, to_path, opts = {}
217
217
  block_on host do | host |
218
- if host['platform'] =~ /windows/ && to_path.match('`cygpath')
218
+ if host['platform'].include?('windows') && to_path.match('`cygpath')
219
219
  result = host.echo "#{to_path}"
220
220
  to_path = result.raw_output.chomp
221
221
  end
@@ -268,7 +268,7 @@ module Beaker
268
268
  FileUtils.mkdir_p(targetdir)
269
269
  scp_from(host, from_path, targetdir, opts)
270
270
  # scp_from does succeed on a non-existant file, checking if the file/folder actually exists
271
- if not File.exists?(filename)
271
+ if not File.exist?(filename)
272
272
  raise IOError, "No such file or directory - #{filename}"
273
273
  end
274
274
  create_tarball(archive_root, archive_name)
@@ -348,7 +348,7 @@ module Beaker
348
348
  block_on hosts, opts do |host|
349
349
  script_path = "beaker_powershell_script_#{Time.now.to_i}.ps1"
350
350
  create_remote_file(host, script_path, powershell_script, opts)
351
- native_path = script_path.gsub(/\//, "\\")
351
+ native_path = script_path.tr('/', "\\")
352
352
  on host, powershell("", {"File" => native_path }), opts
353
353
  end
354
354
 
@@ -491,7 +491,7 @@ module Beaker
491
491
  #
492
492
  # @return [Boolean] Whether the file exists on the host (using `test -f`)
493
493
  def file_exists_on(host, file_path)
494
- if host['platform'] =~ /windows/
494
+ if host[:platform].include?('windows')
495
495
  command = %(Test-Path #{file_path})
496
496
 
497
497
  if file_path.include?(':')
@@ -516,7 +516,7 @@ module Beaker
516
516
  #
517
517
  # @return [Boolean] Whether the directory exists on the host (using `test -d`)
518
518
  def directory_exists_on(host, dir_path)
519
- if host['platform'] =~ /windows/
519
+ if host[:platform].include?('windows')
520
520
  dir_path = "#{dir_path}\\" unless (dir_path[-1].chr == '\\')
521
521
 
522
522
  command = Command.new(%{IF exist "#{dir_path}" ( exit 0 ) ELSE ( exit 1 )}, [], { :cmdexe => true })
@@ -535,7 +535,7 @@ module Beaker
535
535
  # @return [Boolean] Whether the symlink exists on the host (using `test -L`)
536
536
  def link_exists_on(host, link_path)
537
537
  # Links are weird on windows, fall back to seeing if the file exists
538
- return file_exists_on(host, link_path) if host['platform'] =~ /windows/
538
+ return file_exists_on(host, link_path) if host[:platform].include?('windows')
539
539
 
540
540
  return on(host, Command.new(%(test -L "#{link_path}"), accept_all_exit_codes: true)).exit_code.zero?
541
541
  end
@@ -551,8 +551,8 @@ module Beaker
551
551
 
552
552
  split_path = win_ads_path(file_path)
553
553
  if file_exists_on(host, split_path[:path])
554
- if host['platform'] =~ /windows/
555
- file_path.gsub!('/', '\\')
554
+ if host[:platform].include?('windows')
555
+ file_path.tr!('/', '\\')
556
556
 
557
557
  command = %{Get-Content -Raw -Path #{file_path}}
558
558
  command += %{ -Stream #{split_path[:ads]}} if split_path[:ads]
@@ -580,7 +580,7 @@ module Beaker
580
580
  on host, "curl --tlsv1 %s" % cmd, opts, &block
581
581
  end
582
582
 
583
- def curl_with_retries(desc, host, url, desired_exit_codes, max_retries = 60, retry_interval = 1)
583
+ def curl_with_retries(_desc, host, url, desired_exit_codes, max_retries = 60, retry_interval = 1)
584
584
  opts = {
585
585
  :desired_exit_codes => desired_exit_codes,
586
586
  :max_retries => max_retries,
@@ -57,7 +57,7 @@ module Beaker
57
57
  base_url.chomp!('/')
58
58
  src = "#{base_url}/#{file_name}"
59
59
  dst = File.join(dst_dir, file_name)
60
- if options[:cache_files_locally] && File.exists?(dst)
60
+ if options[:cache_files_locally] && File.exist?(dst)
61
61
  logger.notify "Already fetched #{dst}"
62
62
  else
63
63
  logger.notify "Fetching: #{src}"
@@ -69,7 +69,7 @@ module Beaker
69
69
  end
70
70
  end
71
71
  rescue OpenURI::HTTPError => e
72
- if e.message =~ /404.*/
72
+ if /404.*/.match?(e.message)
73
73
  raise "Failed to fetch_remote_file '#{src}' (#{e.message})"
74
74
  else
75
75
  raise e
@@ -92,7 +92,7 @@ module Beaker
92
92
  # @!visibility private
93
93
  def fetch_http_dir(url, dst_dir)
94
94
  logger.notify "fetch_http_dir (url: #{url}, dst_dir #{dst_dir})"
95
- if url[-1, 1] !~ /\//
95
+ if !url.end_with?('/')
96
96
  url += '/'
97
97
  end
98
98
  url = URI.parse(url)
@@ -19,18 +19,18 @@ module Beaker
19
19
  # Raise this class if it is determined that a test case should not
20
20
  # be executed because the feature in question is still a
21
21
  # "Work in Progress"
22
- class PendingTest < Exception; end
22
+ class PendingTest < RuntimeError; end
23
23
 
24
24
  # Raise this class if execution should be stopped because the test
25
25
  # is not applicable within a given environment.
26
- class SkipTest < Exception; end
26
+ class SkipTest < RuntimeError; end
27
27
 
28
28
  # Raise this class if some criteria has been met that proves a failure.
29
- class FailTest < Exception; end
29
+ class FailTest < RuntimeError; end
30
30
 
31
31
  # Raise this class if execution should stop because enough criteria has
32
32
  # shown itself to pass the test.
33
- class PassTest < Exception; end
33
+ class PassTest < RuntimeError; end
34
34
 
35
35
 
36
36
  # Raises FailTest Exception and logs an error message
@@ -139,7 +139,7 @@ module Beaker
139
139
  return !version_is_less(version, '4.0') if version && !version.empty?
140
140
  end
141
141
  return true if host[:roles] && host[:roles].include?('aio')
142
- return true if host[:type] && !!(host[:type] =~ /(\A|-)aio(\Z|-)/ )
142
+ return true if host[:type] && /(\A|-)aio(\Z|-)/.match(host[:type])
143
143
  false
144
144
  end
145
145
 
@@ -175,7 +175,7 @@ module Beaker
175
175
  end
176
176
  else
177
177
  if not respond_to? role
178
- if role !~ /\A[[:alpha:]]+[a-zA-Z0-9_]*[!?=]?\Z/
178
+ if !/\A[[:alpha:]]+[a-zA-Z0-9_]*[!?=]?\Z/.match?(role)
179
179
  raise ArgumentError, "Role name format error for '#{role}'. Allowed characters are: \na-Z\n0-9 (as long as not at the beginning of name)\n'_'\n'?', '!' and '=' (only as individual last character at end of name)"
180
180
  end
181
181
  self.class.send :define_method, role.to_s do
@@ -37,7 +37,7 @@ module Beaker
37
37
  def step step_name, &block
38
38
  logger.notify "\n* #{step_name}\n"
39
39
  set_current_step_name(step_name)
40
- if block_given?
40
+ if block
41
41
  begin
42
42
  logger.with_indent do
43
43
  yield
@@ -58,7 +58,7 @@ module Beaker
58
58
  else
59
59
  logger.info("Exception raised during step execution and debug-errors option is set, entering pry. Exception was: #{e.inspect}")
60
60
  logger.info("HINT: Use the pry 'backtrace' and 'up' commands to navigate to the test code")
61
- binding.pry
61
+ binding.pry # rubocop:disable Lint/Debugger
62
62
  end
63
63
  end
64
64
  raise e
@@ -128,7 +128,7 @@ module Beaker
128
128
  # @param [String] my_name The name of the test to be logged.
129
129
  # @param [Proc] block The actions to be performed during this test.
130
130
  #
131
- def test_name my_name, &block
131
+ def test_name my_name
132
132
  logger.notify "\n#{my_name}\n"
133
133
  set_current_test_name(my_name)
134
134
  if block_given?
@@ -190,17 +190,17 @@ module Beaker
190
190
  # a {Beaker::Assertions} (i.e., if the assert
191
191
  # passes)
192
192
  # @author Chris Cowell-Shah (<tt>ccs@puppetlabs.com</tt>)
193
- def expect_failure(explanation, &block)
193
+ def expect_failure(explanation)
194
194
  begin
195
195
  yield if block_given? # code block should contain an assert that you expect to fail
196
- rescue Beaker::DSL::Assertions, Minitest::Assertion => failed_assertion
196
+ rescue Beaker::DSL::Assertions, Minitest::Assertion => e
197
197
  # Yay! The assert in the code block failed, as expected.
198
198
  # Swallow the failure so the test passes.
199
199
  logger.notify 'An assertion was expected to fail, and did. ' +
200
200
  'This is probably due to a known product bug, ' +
201
201
  'and is probably not a problem. ' +
202
202
  "Additional info: '#{explanation}' " +
203
- "Failed assertion: '#{failed_assertion}'"
203
+ "Failed assertion: '#{e}'"
204
204
  return
205
205
  end
206
206
  # Uh-oh! The assert in the code block unexpectedly passed.
@@ -304,7 +304,7 @@ module Beaker
304
304
  # TestCase#hosts is reset after block has executed.
305
305
  #
306
306
  # @see #confine
307
- def confine_block(type, criteria, host_array = nil, &block)
307
+ def confine_block(type, criteria, host_array = nil)
308
308
  host_array = Array( host_array || hosts )
309
309
  original_hosts = self.hosts.dup
310
310
  confine(type, criteria, host_array)
@@ -314,7 +314,7 @@ module Beaker
314
314
  rescue Beaker::DSL::Outcomes::SkipTest => e
315
315
  # I don't like this much, but adding options to confine is a breaking change
316
316
  # to the DSL that would involve a major version bump
317
- if e.message !~ /No suitable hosts found/
317
+ if !e.message.include?('No suitable hosts found')
318
318
  # a skip generated from the provided block, pass it up the chain
319
319
  raise e
320
320
  end
@@ -340,7 +340,7 @@ module Beaker
340
340
  # should return true if the host matches this additional criteria.
341
341
  #
342
342
  # @return [Array<Host>] Returns an array of hosts that meet the provided criteria
343
- def select_hosts(criteria, host_array = nil, &block)
343
+ def select_hosts(criteria, host_array = nil)
344
344
  hosts_to_select_from = host_array || hosts
345
345
  criteria.each_pair do |property, value|
346
346
  hosts_to_select_from = hosts_to_select_from.select do |host|
@@ -364,7 +364,7 @@ module Beaker
364
364
  when String
365
365
  true_false = host[property.to_s].include? value
366
366
  when Regexp
367
- true_false = host[property.to_s] =~ value
367
+ true_false = value.match?(host[property.to_s])
368
368
  end
369
369
  true_false
370
370
  end
@@ -1,7 +1,7 @@
1
1
  module Aix::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list(&block)
4
+ def group_list()
5
5
  execute("lsgroup -a ALL") do |result|
6
6
  yield result if block_given?
7
7
 
@@ -9,9 +9,9 @@ module Aix::Group
9
9
  end
10
10
  end
11
11
 
12
- def group_get(name, &block)
12
+ def group_get(name)
13
13
  execute("lsgroup #{name}") do |result|
14
- fail_test "failed to get group #{name}" unless result.stdout =~ /^#{name} id/
14
+ fail_test "failed to get group #{name}" unless /^#{name} id/.match?(result.stdout)
15
15
 
16
16
  yield result if block_given?
17
17
  result
@@ -1,7 +1,7 @@
1
1
  module Aix::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list()
5
5
  execute("lsuser ALL") do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
@@ -14,9 +14,9 @@ module Aix::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("lsuser #{name}") do |result|
19
- fail_test "failed to get user #{name}" unless result.stdout =~ /^#{name} id/
19
+ fail_test "failed to get user #{name}" unless /^#{name} id/.match?(result.stdout)
20
20
 
21
21
  yield result if block_given?
22
22
  result
@@ -34,7 +34,7 @@ module Cisco
34
34
  #
35
35
  # @return nil
36
36
  def scp_post_operations(scp_file_actual, scp_file_target)
37
- if self[:platform] =~ /cisco_nexus/
37
+ if self[:platform].include?('cisco_nexus')
38
38
  execute( "mv #{scp_file_actual} #{scp_file_target}" )
39
39
  end
40
40
  nil
@@ -47,10 +47,10 @@ module Cisco
47
47
  # @return [String] path, changed if needed due to host
48
48
  # constraints
49
49
  def scp_path(path)
50
- if self[:platform] =~ /cisco_nexus/
50
+ if self[:platform].include?('cisco_nexus')
51
51
  @home_dir ||= execute( 'pwd' )
52
52
  answer = "#{@home_dir}/#{File.basename( path )}"
53
- answer << '/' if path =~ /\/$/
53
+ answer << '/' if /\/$/.match?(path)
54
54
  return answer
55
55
  end
56
56
  path
@@ -81,9 +81,9 @@ module Cisco
81
81
  # @param [Hash] opts optional parameters
82
82
  #
83
83
  # @return [String] Command string as needed for this host
84
- def prepend_commands(command = '', user_pc = '', opts = {})
84
+ def prepend_commands(command = '', user_pc = '', _opts = {})
85
85
  return user_pc unless command.index('vsh').nil?
86
- if self[:platform] =~ /cisco_nexus/
86
+ if self[:platform].include?('cisco_nexus')
87
87
  return user_pc unless command.index('ntpdate').nil?
88
88
  end
89
89
 
@@ -105,10 +105,10 @@ module Cisco
105
105
  # @param [Hash] opts optional parameters
106
106
  #
107
107
  # @return [String] Command string as needed for this host
108
- def append_commands(command = '', user_ac = '', opts = {})
108
+ def append_commands(command = '', _user_ac = '', _opts = {})
109
109
  command.gsub('"') {'\\"'}
110
110
  # vsh commands, ntpdate or when user is root commands do not require an appended `"`
111
- return '"' unless command =~ /ntpdate|\/isan\/bin\/vsh/ || self[:user] == 'root'
111
+ return '"' unless /ntpdate|\/isan\/bin\/vsh/.match?(command) || self[:user] == 'root'
112
112
  end
113
113
 
114
114
  # Construct the environment string for this command
@@ -128,13 +128,13 @@ module Cisco
128
128
  env_array = self.environment_variable_string_pair_array( env )
129
129
  environment_string = env_array.join(' ')
130
130
 
131
- if self[:platform] =~ /cisco_nexus/
131
+ if self[:platform].include?('cisco_nexus')
132
132
  prestring << " export"
133
133
  else
134
134
  prestring << " env"
135
135
  end
136
136
  environment_string = "#{prestring} #{environment_string}"
137
- environment_string << ';' if prestring =~ /export/
137
+ environment_string << ';' if prestring.include?('export')
138
138
  environment_string
139
139
  end
140
140
 
@@ -145,7 +145,7 @@ module Cisco
145
145
  # this will be raised with the appropriate message
146
146
  def validate_setup
147
147
  msg = nil
148
- if self[:platform] =~ /cisco_nexus/
148
+ if self[:platform].include?('cisco_nexus')
149
149
  if !self[:vrf]
150
150
  msg = 'Cisco Nexus hosts must be provided with a :vrf value.'
151
151
  end
@@ -153,7 +153,7 @@ module Cisco
153
153
  msg = 'Cisco hosts must be provided with a :user value'
154
154
  end
155
155
  end
156
- if self[:platform] =~ /cisco_ios_xr/
156
+ if self[:platform].include?('cisco_ios_xr')
157
157
  if !self[:user]
158
158
  msg = 'Cisco hosts must be provided with a :user value'
159
159
  end
@@ -18,7 +18,7 @@ module Eos
18
18
  # puppet_agent_version) is either not passed or set to nil
19
19
  #
20
20
  # @return [String, String] Path to the directory and filename of the package, respectively
21
- def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
21
+ def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, _opts = {} )
22
22
  error_message = "Must provide %s argument to get puppet agent dev package information"
23
23
  raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
24
24
  raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
@@ -38,7 +38,7 @@ module Eos
38
38
  # about location, so that parameter is ignored
39
39
  #
40
40
  # @return [Result] The result of copying that file to the host
41
- def get_remote_file( remote_url, host_directory = '' )
41
+ def get_remote_file( remote_url, _host_directory = '' )
42
42
  commands = ['enable', "copy #{remote_url} extension:"]
43
43
  command = commands.join("\n")
44
44
  execute("Cli -c '#{command}'")
@@ -21,7 +21,7 @@ module Mac::Exec
21
21
  # (from {#ssh_service_restart})
22
22
  def ssh_permit_user_environment
23
23
  ssh_config_file = '/etc/sshd_config'
24
- ssh_config_file = '/private/etc/ssh/sshd_config' if self['platform'] =~ /^osx-/
24
+ ssh_config_file = '/private/etc/ssh/sshd_config' if /^osx-/.match?(self['platform'])
25
25
 
26
26
  exec(Beaker::Command.new("echo '\nPermitUserEnvironment yes' >> #{ssh_config_file}"))
27
27
  ssh_service_restart()
@@ -6,11 +6,11 @@ module Mac::Group
6
6
  # @param [Proc] block Additional actions or insertions
7
7
  #
8
8
  # @return [Array<String>] The list of group names on the system
9
- def group_list(&block)
9
+ def group_list()
10
10
  execute('dscacheutil -q group') do |result|
11
11
  groups = []
12
12
  result.stdout.each_line do |line|
13
- groups << line.split(': ')[1].strip if line =~ /^name:/
13
+ groups << line.split(': ')[1].strip if /^name:/.match?(line)
14
14
  end
15
15
 
16
16
  yield result if block_given?
@@ -28,9 +28,9 @@ module Mac::Group
28
28
  # @return [String] Group information in /etc/group format
29
29
  # @raise [FailTest] Raises an Assertion failure if it can't find the name
30
30
  # queried for in the returned block
31
- def group_get(name, &block)
31
+ def group_get(name)
32
32
  execute("dscacheutil -q group -a name #{name}") do |result|
33
- fail_test "failed to get group #{name}" unless result.stdout =~ /^name: #{name}/
33
+ fail_test "failed to get group #{name}" unless /^name: #{name}/.match?(result.stdout)
34
34
  gi = Hash.new # group info
35
35
  result.stdout.each_line { |line|
36
36
  pieces = line.split(': ')
@@ -52,7 +52,7 @@ module Mac::Group
52
52
  gid = -1
53
53
  execute("dscacheutil -q group -a name #{name}") do |result|
54
54
  result.stdout.each_line { |line|
55
- if line =~ /^gid:/
55
+ if /^gid:/.match?(line)
56
56
  gid = (line[5, line.length - 5]).chomp
57
57
  break
58
58
  end
@@ -65,10 +65,10 @@ module Mac::Group
65
65
  #
66
66
  # @param [String] name Name of the group
67
67
  # @param [Proc] block Additional actions or insertions
68
- def group_present(name, &block)
68
+ def group_present(name)
69
69
  group_exists = false
70
70
  execute("dscacheutil -q group -a name #{name}") do |result|
71
- group_exists = result.stdout =~ /^name: #{name}/
71
+ group_exists = result.stdout.start_with?("name: #{name}")
72
72
  end
73
73
 
74
74
  return if group_exists
@@ -5,7 +5,7 @@ module Mac::Pkg
5
5
  raise "Package #{name} cannot be queried on #{self}"
6
6
  end
7
7
 
8
- def install_package(name, cmdline_args = '', version = nil)
8
+ def install_package(name, _cmdline_args = '', _version = nil)
9
9
  generic_install_dmg("#{name}.dmg", name, "#{name}.pkg")
10
10
  end
11
11
 
@@ -28,7 +28,7 @@ module Mac::Pkg
28
28
  execute("installer -pkg /Volumes/#{pkg_base}/#{pkg_name} -target /")
29
29
  end
30
30
 
31
- def uninstall_package(name, cmdline_args = '')
31
+ def uninstall_package(name, _cmdline_args = '')
32
32
  raise "Package #{name} cannot be uninstalled on #{self}"
33
33
  end
34
34
 
@@ -37,7 +37,7 @@ module Mac::Pkg
37
37
  # @param [String] name The name of the package to update
38
38
  # @param [String] cmdline_args Additional command line arguments for
39
39
  # the package manager
40
- def upgrade_package(name, cmdline_args = '')
40
+ def upgrade_package(name, _cmdline_args = '')
41
41
  raise "Package #{name} cannot be upgraded on #{self}"
42
42
  end
43
43
 
@@ -48,7 +48,7 @@ module Mac::Pkg
48
48
  #
49
49
  # @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
50
50
  # params
51
- def deploy_package_repo(path, name, version)
51
+ def deploy_package_repo(_path, _name, _version)
52
52
  raise "Package repo cannot be deployed on #{self}; the platform is not supported"
53
53
  end
54
54
 
@@ -116,7 +116,7 @@ module Mac::Pkg
116
116
  error_message = "Must provide %s argument to get puppet agent dev package information"
117
117
  raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
118
118
 
119
- variant, version, arch, codename = self['platform'].to_array
119
+ variant, version, arch, _codename = self['platform'].to_array
120
120
  release_file = "/repos/apple/#{version}/#{puppet_collection}/#{arch}/puppet-agent-*"
121
121
 
122
122
  # macOS puppet-agent tarballs haven't always included arch
@@ -142,7 +142,7 @@ module Mac::Pkg
142
142
  #
143
143
  # @return nil
144
144
  def pe_puppet_agent_promoted_package_install(
145
- onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, opts
145
+ onhost_copy_base, onhost_copied_download, onhost_copied_file, _download_file, _opts
146
146
  )
147
147
  execute("tar -zxvf #{onhost_copied_download} -C #{onhost_copy_base}")
148
148
  # move to better location
@@ -6,11 +6,11 @@ module Mac::User
6
6
  # @param [Proc] block Additional actions or insertions
7
7
  #
8
8
  # @return [Array<String>] The list of user names on the system
9
- def user_list(&block)
9
+ def user_list()
10
10
  execute('dscacheutil -q user') do |result|
11
11
  users = []
12
12
  result.stdout.each_line do |line|
13
- users << line.split(': ')[1].strip if line =~ /^name:/
13
+ users << line.split(': ')[1].strip if /^name:/.match?(line)
14
14
  end
15
15
 
16
16
  yield result if block_given?
@@ -31,9 +31,9 @@ module Mac::User
31
31
  # @return [Result] User information in /etc/passwd format
32
32
  # @raise [FailTest] Raises an Assertion failure if it can't find the name
33
33
  # queried for in the returned block
34
- def user_get(name, &block)
34
+ def user_get(name)
35
35
  execute("id -P #{name}") do |result|
36
- fail_test "failed to get user #{name}" unless result.stdout =~ /^#{name}:/
36
+ fail_test "failed to get user #{name}" unless /^#{name}:/.match?(result.stdout)
37
37
 
38
38
  yield result if block_given?
39
39
  result
@@ -44,10 +44,10 @@ module Mac::User
44
44
  #
45
45
  # @param [String] name Name of the user
46
46
  # @param [Proc] block Additional actions or insertions
47
- def user_present(name, &block)
47
+ def user_present(name)
48
48
  user_exists = false
49
49
  execute("dscacheutil -q user -a name #{name}") do |result|
50
- user_exists = result.stdout =~ /^name: #{name}/
50
+ user_exists = result.stdout.start_with?("name: #{name}")
51
51
  end
52
52
 
53
53
  return if user_exists
@@ -21,7 +21,7 @@ module PSWindows::Exec
21
21
 
22
22
  def rm_rf path
23
23
  # ensure that we have the right slashes for windows
24
- path = path.gsub(/\//, '\\')
24
+ path = path.tr('/', '\\')
25
25
  execute(%(del /s /q "#{path}"))
26
26
  end
27
27
 
@@ -31,8 +31,8 @@ module PSWindows::Exec
31
31
  # @param [Boolean] rm Remove the destination prior to move
32
32
  def mv(orig, dest, rm=true)
33
33
  # ensure that we have the right slashes for windows
34
- orig = orig.gsub(/\//,'\\')
35
- dest = dest.gsub(/\//,'\\')
34
+ orig = orig.tr('/','\\')
35
+ dest = dest.tr('/','\\')
36
36
  rm_rf dest unless !rm
37
37
  execute("move /y #{orig} #{dest}")
38
38
  end
@@ -104,7 +104,7 @@ module PSWindows::Exec
104
104
  # @param [String] dir The directory structure to create on the host
105
105
  # @return [Boolean] True, if directory construction succeeded, otherwise False
106
106
  def mkdir_p dir
107
- normalized_path = dir.gsub('/','\\')
107
+ normalized_path = dir.tr('/','\\')
108
108
  result = exec(powershell("New-Item -Path '#{normalized_path}' -ItemType 'directory'"),
109
109
  :acceptable_exit_codes => [0, 1])
110
110
  result.exit_code == 0
@@ -118,7 +118,7 @@ module PSWindows::Exec
118
118
  def add_env_var key, val
119
119
  key = key.to_s.upcase
120
120
  #see if the key/value pair already exists
121
- cur_val = subbed_val = get_env_var(key, true)
121
+ cur_val = get_env_var(key, true)
122
122
  subbed_val = cur_val.gsub(/#{Regexp.escape(val.gsub(/'|"/, ''))}/, '')
123
123
  if cur_val.empty?
124
124
  exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', '#{val}', 'Machine')"))
@@ -137,7 +137,7 @@ module PSWindows::Exec
137
137
  def delete_env_var key, val
138
138
  key = key.to_s.upcase
139
139
  #get the current value of the key
140
- cur_val = subbed_val = get_env_var(key, true)
140
+ cur_val = get_env_var(key, true)
141
141
  subbed_val = (cur_val.split(';') - [val.gsub(/'|"/, '')]).join(';')
142
142
  if subbed_val != cur_val
143
143
  #remove the current key value
@@ -159,7 +159,7 @@ module PSWindows::Exec
159
159
  if val.empty?
160
160
  return ''
161
161
  else
162
- val = val.split(/\n/)[0] # only take the first result
162
+ val = val.split("\n")[0] # only take the first result
163
163
  if clean
164
164
  val.gsub(/#{key}=/i,'')
165
165
  else
@@ -185,7 +185,7 @@ module PSWindows::Exec
185
185
  env_array = self.environment_variable_string_pair_array( env )
186
186
 
187
187
  environment_string = ''
188
- env_array.each_with_index do |env|
188
+ env_array.each do |env|
189
189
  environment_string += "set \"#{env}\" && "
190
190
  end
191
191
  environment_string
@@ -1,7 +1,7 @@
1
1
  module PSWindows::File
2
2
  include Beaker::CommandFactory
3
3
 
4
- def tmpfile(name = '')
4
+ def tmpfile(_name = '')
5
5
  result = exec(powershell('[System.IO.Path]::GetTempFileName()'))
6
6
  result.stdout.chomp()
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module PSWindows::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 PSWindows::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 PSWindows::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