beaker 4.40.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +14 -6
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +4 -3
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -7
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +15 -27
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +5 -6
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +169 -158
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +47 -56
  167. data/spec/beaker/host/mac/user_spec.rb +53 -62
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +13 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -4,11 +4,9 @@ require 'net/scp'
4
4
 
5
5
  module Beaker
6
6
  class SshConnection
7
+ attr_accessor :logger, :ip, :vmhostname, :hostname, :ssh_connection_preference
7
8
 
8
- attr_accessor :logger
9
- attr_accessor :ip, :vmhostname, :hostname, :ssh_connection_preference
10
-
11
- SUPPORTED_CONNECTION_METHODS = [:ip, :vmhostname, :hostname]
9
+ SUPPORTED_CONNECTION_METHODS = %i[ip vmhostname hostname]
12
10
 
13
11
  RETRYABLE_EXCEPTIONS = [
14
12
  SocketError,
@@ -67,18 +65,18 @@ module Beaker
67
65
  wait = 3
68
66
  max_connection_tries = options[:max_connection_tries] || 11
69
67
  begin
70
- @logger.debug "Attempting ssh connection to #{host}, user: #{user}, opts: #{ssh_opts}"
68
+ @logger.debug "Attempting ssh connection to #{host}, user: #{user}, opts: #{ssh_opts}"
71
69
 
72
- # Work around net-ssh 6+ incompatibilities
73
- if ssh_opts.include?(:strict_host_key_checking) && (Net::SSH::Version::CURRENT.major > 5)
74
- strict_host_key_checking = ssh_opts.delete(:strict_host_key_checking)
70
+ # Work around net-ssh 6+ incompatibilities
71
+ if ssh_opts.include?(:strict_host_key_checking) && (Net::SSH::Version::CURRENT.major > 5)
72
+ strict_host_key_checking = ssh_opts.delete(:strict_host_key_checking)
75
73
 
76
- unless ssh_opts[:verify_host_key].is_a?(Symbol)
77
- ssh_opts[:verify_host_key] ||= strict_host_key_checking ? :always : :never
78
- end
79
- end
74
+ unless ssh_opts[:verify_host_key].is_a?(Symbol)
75
+ ssh_opts[:verify_host_key] ||= strict_host_key_checking ? :always : :never
76
+ end
77
+ end
80
78
 
81
- Net::SSH.start(host, user, ssh_opts)
79
+ Net::SSH.start(host, user, ssh_opts)
82
80
  rescue *RETRYABLE_EXCEPTIONS => e
83
81
  if try <= max_connection_tries
84
82
  @logger.warn "Try #{try} -- Host #{host} unreachable: #{e.class.name} - #{e.message}" unless options[:silent]
@@ -105,16 +103,14 @@ module Beaker
105
103
  # Try three ways to connect to host (vmhostname, ip, hostname)
106
104
  # Try each method in turn until we succeed
107
105
  methods = @ssh_connection_preference.dup
108
- while (not @ssh) && (not methods.empty?) do
109
- unless instance_variable_get("@#{methods[0]}").nil?
110
- if SUPPORTED_CONNECTION_METHODS.include?(methods[0])
111
- @ssh = connect_block(instance_variable_get("@#{methods[0]}"), @user, @ssh_opts, options)
112
- else
113
- @logger.warn "Beaker does not support #{methods[0]} to SSH to host, trying next available method."
114
- @ssh_connection_preference.delete(methods[0])
115
- end
116
- else
106
+ while (not @ssh) && (not methods.empty?)
107
+ if instance_variable_get("@#{methods[0]}").nil?
117
108
  @logger.warn "Skipping #{methods[0]} method to ssh to host as its value is not set. Refer to https://github.com/puppetlabs/beaker/tree/master/docs/how_to/ssh_connection_preference.md to remove this warning"
109
+ elsif SUPPORTED_CONNECTION_METHODS.include?(methods[0])
110
+ @ssh = connect_block(instance_variable_get("@#{methods[0]}"), @user, @ssh_opts, options)
111
+ else
112
+ @logger.warn "Beaker does not support #{methods[0]} to SSH to host, trying next available method."
113
+ @ssh_connection_preference.delete(methods[0])
118
114
  end
119
115
  methods.shift
120
116
  end
@@ -157,30 +153,31 @@ module Beaker
157
153
  try = 1
158
154
  last_wait = 2
159
155
  wait = 3
160
- command = 'echo echo' #can be run on all platforms (I'm looking at you, windows)
156
+ command = 'echo echo' # can be run on all platforms (I'm looking at you, windows)
161
157
  while try < 11
162
158
  result = Result.new(@hostname, command)
163
159
  begin
164
160
  @logger.notify "Waiting for connection failure on #{@hostname} (attempt #{try}, try again in #{wait} second(s))"
165
161
  @logger.debug("\n#{@hostname} #{Time.new.strftime('%H:%M:%S')}$ #{command}")
166
162
  @ssh.open_channel do |channel|
167
- request_terminal_for( channel, command ) if options[:pty]
163
+ request_terminal_for(channel, command) if options[:pty]
168
164
 
169
165
  channel.exec(command) do |terminal, success|
170
166
  raise Net::SSH::Exception.new("FAILED: to execute command on a new channel on #{@hostname}") unless success
167
+
171
168
  register_stdout_for terminal, result, stdout_callback
172
169
  register_stderr_for terminal, result, stderr_callback
173
170
  register_exit_code_for terminal, result
174
171
 
175
- process_stdin_for( terminal, options[:stdin] ) if options[:stdin]
176
- end
177
- end
178
- loop_tries = 0
179
- #loop is actually loop_forever, so let it try 3 times and then quit instead of endless blocking
180
- @ssh.loop { loop_tries += 1 ; loop_tries < 4 }
172
+ process_stdin_for(terminal, options[:stdin]) if options[:stdin]
173
+ end
174
+ end
175
+ loop_tries = 0
176
+ # loop is actually loop_forever, so let it try 3 times and then quit instead of endless blocking
177
+ @ssh.loop { loop_tries += 1; loop_tries < 4 }
181
178
  rescue *RETRYABLE_EXCEPTIONS => e
182
179
  @logger.debug "Connection on #{@hostname} failed as expected (#{e.class.name} - #{e.message})"
183
- close #this connection is bad, shut it down
180
+ close # this connection is bad, shut it down
184
181
  return true
185
182
  end
186
183
  slept = 0
@@ -198,20 +195,21 @@ module Beaker
198
195
  end
199
196
 
200
197
  def try_to_execute command, options = {}, stdout_callback = nil,
201
- stderr_callback = stdout_callback
198
+ stderr_callback = stdout_callback
202
199
 
203
200
  result = Result.new(@hostname, command)
204
201
 
205
202
  @ssh.open_channel do |channel|
206
- request_terminal_for( channel, command ) if options[:pty]
203
+ request_terminal_for(channel, command) if options[:pty]
207
204
 
208
205
  channel.exec(command) do |terminal, success|
209
206
  raise Net::SSH::Exception.new("FAILED: to execute command on a new channel on #{@hostname}") unless success
207
+
210
208
  register_stdout_for terminal, result, stdout_callback
211
209
  register_stderr_for terminal, result, stderr_callback
212
210
  register_exit_code_for terminal, result
213
211
 
214
- process_stdin_for( terminal, options[:stdin] ) if options[:stdin]
212
+ process_stdin_for(terminal, options[:stdin]) if options[:stdin]
215
213
  end
216
214
  end
217
215
 
@@ -288,11 +286,8 @@ module Beaker
288
286
  end
289
287
 
290
288
  def scp_to source, target, options = {}
291
-
292
289
  local_opts = options.dup
293
- if local_opts[:recursive].nil?
294
- local_opts[:recursive] = File.directory?(source)
295
- end
290
+ local_opts[:recursive] = File.directory?(source) if local_opts[:recursive].nil?
296
291
  local_opts[:chunk_size] ||= 16384
297
292
 
298
293
  result = Result.new(@hostname, [source, target])
@@ -304,15 +299,14 @@ module Beaker
304
299
  target = self.execute(%{echo "#{target}"}).output.strip.delete('"') if target.include?('%')
305
300
 
306
301
  @ssh.scp.upload! source, target, local_opts do |_ch, name, sent, total|
307
- result.stdout << "\tcopying %s: %10d/%d\n" % [name, sent, total]
302
+ result.stdout << (format("\tcopying %s: %10d/%d\n", name, sent, total))
308
303
  end
309
304
  rescue => e
310
305
  logger.warn "#{e.class} error in scp'ing. Forcing the connection to close, which should " <<
311
- "raise an error."
306
+ "raise an error."
312
307
  close
313
308
  end
314
309
 
315
-
316
310
  # Setting these values allows reporting via result.log(test_name)
317
311
  result.stdout << " SCP'ed file #{source} to #{@hostname}:#{target}"
318
312
 
@@ -324,11 +318,8 @@ module Beaker
324
318
  end
325
319
 
326
320
  def scp_from source, target, options = {}
327
-
328
321
  local_opts = options.dup
329
- if local_opts[:recursive].nil?
330
- local_opts[:recursive] = true
331
- end
322
+ local_opts[:recursive] = true if local_opts[:recursive].nil?
332
323
  local_opts[:chunk_size] ||= 16384
333
324
 
334
325
  result = Result.new(@hostname, [source, target])
@@ -340,11 +331,11 @@ module Beaker
340
331
  source = self.execute(%{echo "#{source}"}).output.strip.delete('"') if source.include?('%')
341
332
 
342
333
  @ssh.scp.download! source, target, local_opts do |_ch, name, sent, total|
343
- result.stdout << "\tcopying %s: %10d/%d\n" % [name, sent, total]
334
+ result.stdout << (format("\tcopying %s: %10d/%d\n", name, sent, total))
344
335
  end
345
336
  rescue => e
346
337
  logger.warn "#{e.class} error in scp'ing. Forcing the connection to close, which should " <<
347
- "raise an error."
338
+ "raise an error."
348
339
  close
349
340
  end
350
341
 
@@ -46,7 +46,6 @@ module Beaker
46
46
  class_option :'test-results-file', :type => :string, :group => 'Beaker run'
47
47
  class_option :ntp, :type => :boolean, :group => 'Beaker run'
48
48
  class_option :'repo-proxy', :type => :boolean, :group => 'Beaker run'
49
- class_option :'add-el-extras', :type => :boolean, :group => 'Beaker run'
50
49
  class_option :'package-proxy', :type => :string, :group => 'Beaker run'
51
50
  class_option :validate, :type => :boolean, :group => 'Beaker run'
52
51
  class_option :'collect-perf-data', :type => :boolean, :group => 'Beaker run'
@@ -76,7 +75,7 @@ module Beaker
76
75
  LONGDESC
77
76
  option :help, :type => :boolean, :hide => true
78
77
  method_option :hosts, :aliases => '-h', :type => :string, :required => true
79
- def init()
78
+ def init
80
79
  if options[:help]
81
80
  invoke :help, [], ["init"]
82
81
  return
@@ -87,9 +86,7 @@ module Beaker
87
86
  options_to_write = SubcommandUtil.sanitize_options_for_save(@cli.configured_options)
88
87
 
89
88
  @cli.logger.notify 'Writing configured options to disk'
90
- File.open(SubcommandUtil::SUBCOMMAND_OPTIONS, 'w') do |f|
91
- f.write(options_to_write.to_yaml)
92
- end
89
+ File.write(SubcommandUtil::SUBCOMMAND_OPTIONS, options_to_write.to_yaml)
93
90
  @cli.logger.notify "Options written to #{SubcommandUtil::SUBCOMMAND_OPTIONS}"
94
91
 
95
92
  state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE)
@@ -105,16 +102,14 @@ module Beaker
105
102
  flag here to override.
106
103
  LONGDESC
107
104
  option :help, :type => :boolean, :hide => true
108
- def provision()
105
+ def provision
109
106
  if options[:help]
110
107
  invoke :help, [], ["provision"]
111
108
  return
112
109
  end
113
110
 
114
111
  state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE)
115
- if state.transaction { state['provisioned']}
116
- SubcommandUtil.error_with('Provisioned SUTs detected. Please destroy and reprovision.')
117
- end
112
+ SubcommandUtil.error_with('Provisioned SUTs detected. Please destroy and reprovision.') if state.transaction { state['provisioned'] }
118
113
 
119
114
  @cli.parse_options
120
115
  @cli.provision
@@ -154,7 +149,7 @@ module Beaker
154
149
  such as: exec pre-suite,tests
155
150
  LONG_DESC
156
151
  option :help, :type => :boolean, :hide => true
157
- def exec(resource=nil)
152
+ def exec(resource = nil)
158
153
  if options[:help]
159
154
  invoke :help, [], ["exec"]
160
155
  return
@@ -168,7 +163,7 @@ module Beaker
168
163
  return
169
164
  end
170
165
 
171
- beaker_suites = [:pre_suite, :tests, :post_suite, :pre_cleanup]
166
+ beaker_suites = %i[pre_suite tests post_suite pre_cleanup]
172
167
  resources = resource.split(',')
173
168
  paths = resources.map { |r| Pathname(r) }
174
169
  if paths.all?(&:exist?)
@@ -198,13 +193,13 @@ module Beaker
198
193
 
199
194
  @cli.execute!
200
195
 
201
- if options['preserve-state']
202
- @cli.logger.notify 'updating HOSTS key in subcommand_options'
203
- hosts = SubcommandUtil.sanitize_options_for_save(@cli.combined_instance_and_options_hosts)
204
- options_storage = YAML::Store.new(SubcommandUtil::SUBCOMMAND_OPTIONS)
205
- options_storage.transaction do
206
- options_storage['HOSTS'] = hosts
207
- end
196
+ return unless options['preserve-state']
197
+
198
+ @cli.logger.notify 'updating HOSTS key in subcommand_options'
199
+ hosts = SubcommandUtil.sanitize_options_for_save(@cli.combined_instance_and_options_hosts)
200
+ options_storage = YAML::Store.new(SubcommandUtil::SUBCOMMAND_OPTIONS)
201
+ options_storage.transaction do
202
+ options_storage['HOSTS'] = hosts
208
203
  end
209
204
  end
210
205
 
@@ -213,25 +208,23 @@ module Beaker
213
208
  Destroys the currently provisioned VMs
214
209
  LONG_DESC
215
210
  option :help, :type => :boolean, :hide => true
216
- def destroy()
211
+ def destroy
217
212
  if options[:help]
218
213
  invoke :help, [], ["destroy"]
219
214
  return
220
215
  end
221
216
 
222
217
  state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE)
223
- unless state.transaction { state['provisioned']}
224
- SubcommandUtil.error_with('Please provision an environment')
225
- end
218
+ SubcommandUtil.error_with('Please provision an environment') unless state.transaction { state['provisioned'] }
226
219
 
227
220
  @cli.parse_options
228
221
  @cli.options[:provision] = false
229
222
  @cli.initialize_network_manager
230
223
  @cli.network_manager.cleanup
231
224
 
232
- state.transaction {
225
+ state.transaction do
233
226
  state.delete('provisioned')
234
- }
227
+ end
235
228
  end
236
229
  end
237
230
  end
@@ -17,10 +17,11 @@ module Beaker
17
17
  PERSISTED_HOSTS = Pathname("#{CONFIG_DIR}/.hosts.yaml")
18
18
  PERSISTED_HYPERVISORS = Pathname("#{CONFIG_DIR}/.hypervisors.yaml")
19
19
  # These options should not be part of persisted subcommand state
20
- UNPERSISTED_OPTIONS = [:beaker_version, :command_line, :hosts_file, :logger, :password_prompt, :timestamp]
20
+ UNPERSISTED_OPTIONS = %i[beaker_version command_line hosts_file logger password_prompt timestamp]
21
21
 
22
22
  def self.execute_subcommand?(arg0)
23
23
  return false if arg0.nil?
24
+
24
25
  (Beaker::Subcommand.instance_methods(false) << :help).include? arg0.to_sym
25
26
  end
26
27
 
@@ -46,9 +47,9 @@ module Beaker
46
47
  end
47
48
 
48
49
  # Print a message to the console and exit with specified exit code, defaults to 1
49
- # @param [String] msg the message to output
50
+ #  @param [String] msg the message to output
50
51
  # @param [Hash<Object>] options to specify exit code or output stack trace
51
- def self.error_with(msg, options={})
52
+ def self.error_with(msg, options = {})
52
53
  puts msg
53
54
  puts options[:stack_trace] if options[:stack_trace]
54
55
  exit_code = options[:exit_code] ? options[:exit_code] : 1
@@ -68,7 +69,6 @@ module Beaker
68
69
  $stderr = old_stderr
69
70
  end
70
71
  end
71
-
72
72
  end
73
73
  end
74
74
  end
@@ -3,12 +3,11 @@ require 'beaker-hostgenerator'
3
3
  CONFIG_DIR = 'acceptance/config'
4
4
 
5
5
  VAGRANT = ['ubuntu1404-64default.mdcal-ubuntu1404-64af', '--hypervisor=vagrant',
6
- '--global-config={box_url=https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm,box=puppetlabs/ubuntu-14.04-64-nocm}']
6
+ '--global-config={box_url=https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm,box=puppetlabs/ubuntu-14.04-64-nocm}',]
7
7
 
8
8
  VMPOOLER = ['redhat7-64default.mdcal-redhat7-64af']
9
9
 
10
10
  namespace :beaker_quickstart do
11
-
12
11
  desc 'Generate Default Beaker Host Config File, valid options are: vmpooler or vagrant.'
13
12
  task :gen_hosts, [:hypervisor] do |_t, args|
14
13
  hosts_file = "#{CONFIG_DIR}/default_#{args[:hypervisor]}_hosts.yaml"
@@ -33,7 +32,6 @@ namespace :beaker_quickstart do
33
32
  end
34
33
  end
35
34
 
36
-
37
35
  desc 'Generate Default Pre-Suite'
38
36
  task :gen_pre_suite do
39
37
  pre_suite_file = "acceptance/setup/default_pre_suite.rb"
@@ -71,20 +69,17 @@ end")
71
69
 
72
70
  desc 'Run Default Smoke Test, after generating default host config and test files, valid options are: vmpooler or vagrant.'
73
71
  task :run_test, [:hypervisor] => ["beaker_quickstart:gen_hosts", 'beaker_quickstart:gen_pre_suite',
74
- 'beaker_quickstart:gen_smoke_test'] do
75
- |_t, args|
76
- hypervisor = args[:hypervisor] ||='vagrant'
77
- system_args = Hash.new
72
+ 'beaker_quickstart:gen_smoke_test',] do |_t, args|
73
+ hypervisor = args[:hypervisor] ||= 'vagrant'
74
+ system_args = {}
78
75
  system_args[:hosts] = "acceptance/config/default_#{hypervisor}_hosts.yaml"
79
76
  system_args[:pre_suite] = 'acceptance/setup/default_pre_suite.rb'
80
77
  system_args[:tests] = 'acceptance/tests/default_smoke_test.rb'
81
78
  puts "About to run - #{beaker_command(system_args)}"
82
79
  system(beaker_command(system_args))
83
80
  end
84
-
85
81
  end
86
82
 
87
-
88
83
  def beaker_command(system_args)
89
84
  cmd_parts = []
90
85
  cmd_parts << "beaker"
@@ -3,7 +3,6 @@ require 'rake/tasklib'
3
3
  require 'rake'
4
4
  require 'beaker'
5
5
 
6
-
7
6
  module Beaker
8
7
  module Tasks
9
8
  class RakeTask < ::Rake::TaskLib
@@ -11,17 +10,17 @@ module Beaker
11
10
 
12
11
  DEFAULT_ACCEPTANCE_ROOT = "./acceptance"
13
12
 
14
- COMMAND_OPTIONS = [:fail_mode,
15
- :hosts,
16
- :helper,
17
- :keyfile,
18
- :log_level,
19
- :options_file,
20
- :preserve_hosts,
21
- :tests,
22
- :type,
23
- :acceptance_root,
24
- :name]
13
+ COMMAND_OPTIONS = %i[fail_mode
14
+ hosts
15
+ helper
16
+ keyfile
17
+ log_level
18
+ options_file
19
+ preserve_hosts
20
+ tests
21
+ type
22
+ acceptance_root
23
+ name]
25
24
  # iterates of acceptable params
26
25
  COMMAND_OPTIONS.each do |sym|
27
26
  attr_accessor(sym.to_sym)
@@ -31,16 +30,17 @@ module Beaker
31
30
  # @param args [Array] First argument is always the name of the task
32
31
  # if no additonal arguments are defined such as parameters it will default to [:hosts,:type]
33
32
  def initialize(*args, &task_block)
33
+ super
34
+
34
35
  @name = args.shift || 'beaker:test'
35
- if args.empty?
36
- args = [:hosts,:type]
37
- end
36
+ args = %i[hosts type] if args.empty?
38
37
  @acceptance_root = DEFAULT_ACCEPTANCE_ROOT
39
38
  @options_file = nil
40
39
  define(args, &task_block)
41
40
  end
42
41
 
43
42
  private
43
+
44
44
  # Run the task provided, implements the rake task interface
45
45
  #
46
46
  # @param verbose [bool] Defines wether to run in verbose mode or not
@@ -51,10 +51,10 @@ module Beaker
51
51
  command = beaker_command
52
52
  puts command if verbose
53
53
  success = system(command)
54
- if fail_mode == "fast" && !success
55
- $stderr.puts "#{command} failed"
56
- exit $?.exitstatus
57
- end
54
+ return unless fail_mode == "fast" && !success
55
+
56
+ $stderr.puts "#{command} failed"
57
+ exit $?.exitstatus
58
58
  end
59
59
 
60
60
  # @private
@@ -75,19 +75,17 @@ module Beaker
75
75
  # if no other options file is provided
76
76
  #
77
77
  def check_for_beaker_type_config
78
- if !@options_file && File.exist?("#{@acceptance_root}/.beaker-#{@type}.cfg")
79
- @options_file = File.join(@acceptance_root, ".beaker-#{@type}.cfg")
80
- end
78
+ return unless !@options_file && File.exist?("#{@acceptance_root}/.beaker-#{@type}.cfg")
79
+
80
+ @options_file = File.join(@acceptance_root, ".beaker-#{@type}.cfg")
81
81
  end
82
82
 
83
83
  #
84
84
  # Check for existence of ENV variables for test if !@tests is undef
85
85
  #
86
86
  def check_env_variables
87
- if File.exist?(File.join(DEFAULT_ACCEPTANCE_ROOT, 'tests'))
88
- @tests = File.join(DEFAULT_ACCEPTANCE_ROOT, 'tests')
89
- end
90
- @tests = ENV['TESTS'] || ENV['TEST'] if !@tests
87
+ @tests = File.join(DEFAULT_ACCEPTANCE_ROOT, 'tests') if File.exist?(File.join(DEFAULT_ACCEPTANCE_ROOT, 'tests'))
88
+ @tests = ENV['TESTS'] || ENV.fetch('TEST', nil) if !@tests
91
89
  end
92
90
 
93
91
  #
@@ -97,7 +95,7 @@ module Beaker
97
95
  cmd_parts = []
98
96
  cmd_parts << "beaker"
99
97
  cmd_parts << "--keyfile #{@keyfile}" if @keyfile
100
- cmd_parts << "--hosts #{@hosts}" if (@hosts!=nil && !@hosts.empty?)
98
+ cmd_parts << "--hosts #{@hosts}" if (@hosts != nil && !@hosts.empty?)
101
99
  cmd_parts << "--tests #{tests}" if @tests
102
100
  cmd_parts << "--options-file #{@options_file}" if @options_file
103
101
  cmd_parts << "--type #{@type}" if @type
@@ -1,18 +1,18 @@
1
1
  require 'beaker/tasks/rake_task'
2
2
 
3
- Beaker::Tasks::RakeTask.new do |t,args|
3
+ Beaker::Tasks::RakeTask.new do |t, args|
4
4
  t.type = args[:type]
5
5
  t.hosts = args[:hosts]
6
6
  end
7
7
 
8
8
  desc "Run Beaker PE tests"
9
- Beaker::Tasks::RakeTask.new("beaker:test:pe",:hosts) do |t,args|
9
+ Beaker::Tasks::RakeTask.new("beaker:test:pe", :hosts) do |t, args|
10
10
  t.type = 'pe'
11
11
  t.hosts = args[:hosts]
12
12
  end
13
13
 
14
14
  desc "Run Beaker Git tests"
15
- Beaker::Tasks::RakeTask.new("beaker:test:git",:hosts) do |t,args|
15
+ Beaker::Tasks::RakeTask.new("beaker:test:git", :hosts) do |t, args|
16
16
  t.type = 'git'
17
17
  t.hosts = args[:hosts]
18
- end
18
+ end
@@ -1,4 +1,4 @@
1
- [ 'host', 'dsl' ].each do |lib|
1
+ %w[host dsl].each do |lib|
2
2
  require "beaker/#{lib}"
3
3
  end
4
4
 
@@ -41,10 +41,10 @@ module Beaker
41
41
  # Assumed to be an Array.
42
42
  attr_accessor :exports
43
43
 
44
- #The full log for this test
44
+ # The full log for this test
45
45
  attr_accessor :sublog
46
46
 
47
- #The result for the last command run
47
+ # The result for the last command run
48
48
  attr_accessor :last_result
49
49
 
50
50
  # A Hash of 'product name' => 'version installed', only set when
@@ -71,31 +71,21 @@ module Beaker
71
71
  # The exception that may have stopped this test's execution.
72
72
  attr_reader :exception
73
73
 
74
- # @deprecated
75
- # The amount of time taken to execute the test. Unused, probably soon
76
- # to be removed or refactored.
74
+ # The amount of time taken to execute the test
77
75
  attr_reader :runtime
78
76
 
79
77
  # An Array of Procs to be called after test execution has stopped
80
78
  # (whether by exception or not).
81
79
  attr_reader :teardown_procs
82
80
 
83
- # @deprecated
84
- # Legacy accessor from when test files would only contain one remote
85
- # action. Contains the Result of the last call to utilize
86
- # {Beaker::DSL::Helpers#on}. Do not use as it is not safe
87
- # in test files that use multiple calls to
88
- # {Beaker::DSL::Helpers#on}.
89
- attr_accessor :result
90
-
91
81
  # @param [Hosts,Array<Host>] these_hosts The hosts to execute this test
92
82
  # against/on.
93
83
  # @param [Logger] logger A logger that implements
94
84
  # {Beaker::Logger}'s interface.
95
85
  # @param [Hash{Symbol=>String}] options Parsed command line options.
96
86
  # @param [String] path The local path to a test file to be executed.
97
- def initialize(these_hosts, logger, options={}, path=nil)
98
- @hosts = these_hosts
87
+ def initialize(these_hosts, logger, options = {}, path = nil)
88
+ @hosts = these_hosts
99
89
  @logger = logger
100
90
  @sublog = ""
101
91
  @options = options
@@ -109,7 +99,6 @@ module Beaker
109
99
  @exports = []
110
100
  set_current_test_filename(@path ? File.basename(@path, '.rb') : nil)
111
101
 
112
-
113
102
  #
114
103
  # We put this on each wrapper (rather than the class) so that methods
115
104
  # defined in the tests don't leak out to other tests.
@@ -120,17 +109,17 @@ module Beaker
120
109
 
121
110
  set_current_step_name(nil)
122
111
 
123
- #add arbitrary role methods
112
+ # add arbitrary role methods
124
113
  roles = []
125
114
  @hosts.each do |host|
126
115
  roles << host[:roles]
127
116
  end
128
- add_role_def( roles.flatten.uniq )
117
+ add_role_def(roles.flatten.uniq)
129
118
 
130
119
  @runtime = Benchmark.realtime do
131
120
  begin
132
121
  test = File.read(path)
133
- eval test,nil,path,1
122
+ eval test, nil, path, 1
134
123
  rescue FailTest, TEST_EXCEPTION_CLASS => e
135
124
  log_and_fail_test(e, :fail)
136
125
  rescue PassTest
@@ -168,18 +157,18 @@ module Beaker
168
157
  #
169
158
  # @param exception [Exception] exception to fail with
170
159
  # @param exception [Symbol] the test status
171
- def log_and_fail_test(exception, status=:error)
160
+ def log_and_fail_test(exception, status = :error)
172
161
  logger.error("#{exception.class}: #{exception.message}")
173
162
  bt = exception.backtrace
174
163
  logger.pretty_backtrace(bt).each_line do |line|
175
164
  logger.error(line)
176
165
  end
177
166
  # If the status is already a test failure or error, don't overwrite with the teardown failure.
178
- unless status == :teardown_error && (@test_status == :error || @test_status == :fail)
179
- status = :error if status == :teardown_error
180
- @test_status = status
181
- @exception = exception
182
- end
167
+ return if status == :teardown_error && (@test_status == :error || @test_status == :fail)
168
+
169
+ status = :error if status == :teardown_error
170
+ @test_status = status
171
+ @exception = exception
183
172
  end
184
173
  end
185
174
  end
@@ -198,6 +187,5 @@ module Beaker
198
187
  end
199
188
  hash
200
189
  end
201
-
202
190
  end
203
191
  end