beaker 4.38.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) 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 +36 -11
  5. data/.rubocop.yml +75 -0
  6. data/.rubocop_todo.yml +239 -0
  7. data/CHANGELOG.md +88 -33
  8. data/Gemfile +16 -4
  9. data/HISTORY.md +103 -0
  10. data/Rakefile +101 -112
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Gemfile +1 -1
  16. data/acceptance/fixtures/module/Rakefile +3 -3
  17. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +16 -23
  18. data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -2
  19. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  20. data/acceptance/lib/helpers/test_helper.rb +7 -6
  21. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  22. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  24. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +7 -8
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +9 -7
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +15 -21
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +23 -30
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +3 -3
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +21 -16
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +7 -7
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +30 -38
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +14 -18
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +8 -14
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +7 -11
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +4 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +8 -8
  41. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +4 -6
  42. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  43. data/acceptance/tests/base/dsl/structure_test.rb +9 -21
  44. data/acceptance/tests/base/host/file_test.rb +8 -8
  45. data/acceptance/tests/base/host/group_test.rb +2 -3
  46. data/acceptance/tests/base/host/host_test.rb +69 -66
  47. data/acceptance/tests/base/host/packages.rb +27 -30
  48. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  49. data/acceptance/tests/base/host/user_test.rb +2 -3
  50. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  51. data/acceptance/tests/base/test_suite/export.rb +6 -9
  52. data/acceptance/tests/install/from_file.rb +3 -5
  53. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  54. data/acceptance/tests/subcommands/destroy.rb +19 -21
  55. data/acceptance/tests/subcommands/exec.rb +0 -1
  56. data/acceptance/tests/subcommands/init.rb +2 -3
  57. data/acceptance/tests/subcommands/provision.rb +0 -1
  58. data/beaker.gemspec +10 -14
  59. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  60. data/docs/concepts/style_guide.md +1 -1
  61. data/docs/how_to/debug_beaker_tests.md +13 -13
  62. data/docs/how_to/hosts/eos.md +2 -12
  63. data/docs/how_to/install_puppet.md +0 -18
  64. data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
  65. data/docs/how_to/the_beaker_dsl.md +0 -2
  66. data/lib/beaker/cli.rb +63 -74
  67. data/lib/beaker/command.rb +22 -30
  68. data/lib/beaker/command_factory.rb +4 -3
  69. data/lib/beaker/dsl/assertions.rb +7 -19
  70. data/lib/beaker/dsl/helpers/hocon_helpers.rb +5 -9
  71. data/lib/beaker/dsl/helpers/host_helpers.rb +72 -133
  72. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  73. data/lib/beaker/dsl/helpers/web_helpers.rb +20 -28
  74. data/lib/beaker/dsl/helpers.rb +2 -4
  75. data/lib/beaker/dsl/outcomes.rb +17 -19
  76. data/lib/beaker/dsl/patterns.rb +1 -3
  77. data/lib/beaker/dsl/roles.rb +18 -21
  78. data/lib/beaker/dsl/structure.rb +55 -67
  79. data/lib/beaker/dsl/test_tagging.rb +7 -10
  80. data/lib/beaker/dsl/wrappers.rb +15 -16
  81. data/lib/beaker/dsl.rb +2 -3
  82. data/lib/beaker/host/aix/exec.rb +1 -1
  83. data/lib/beaker/host/aix/file.rb +0 -1
  84. data/lib/beaker/host/aix/group.rb +3 -3
  85. data/lib/beaker/host/aix/user.rb +3 -3
  86. data/lib/beaker/host/aix.rb +3 -4
  87. data/lib/beaker/host/cisco.rb +36 -48
  88. data/lib/beaker/host/eos.rb +4 -30
  89. data/lib/beaker/host/freebsd/exec.rb +1 -1
  90. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  91. data/lib/beaker/host/freebsd.rb +9 -12
  92. data/lib/beaker/host/mac/exec.rb +5 -5
  93. data/lib/beaker/host/mac/group.rb +13 -13
  94. data/lib/beaker/host/mac/pkg.rb +6 -109
  95. data/lib/beaker/host/mac/user.rb +7 -7
  96. data/lib/beaker/host/mac.rb +8 -9
  97. data/lib/beaker/host/pswindows/exec.rb +70 -74
  98. data/lib/beaker/host/pswindows/file.rb +4 -6
  99. data/lib/beaker/host/pswindows/group.rb +5 -5
  100. data/lib/beaker/host/pswindows/pkg.rb +17 -17
  101. data/lib/beaker/host/pswindows/user.rb +4 -4
  102. data/lib/beaker/host/pswindows.rb +4 -3
  103. data/lib/beaker/host/unix/exec.rb +86 -88
  104. data/lib/beaker/host/unix/file.rb +41 -47
  105. data/lib/beaker/host/unix/group.rb +3 -3
  106. data/lib/beaker/host/unix/pkg.rb +158 -421
  107. data/lib/beaker/host/unix/user.rb +4 -4
  108. data/lib/beaker/host/unix.rb +18 -20
  109. data/lib/beaker/host/windows/exec.rb +20 -20
  110. data/lib/beaker/host/windows/file.rb +5 -5
  111. data/lib/beaker/host/windows/group.rb +5 -5
  112. data/lib/beaker/host/windows/pkg.rb +6 -57
  113. data/lib/beaker/host/windows/user.rb +4 -4
  114. data/lib/beaker/host/windows.rb +13 -13
  115. data/lib/beaker/host.rb +82 -139
  116. data/lib/beaker/host_prebuilt_steps.rb +121 -233
  117. data/lib/beaker/hypervisor/noop.rb +2 -4
  118. data/lib/beaker/hypervisor.rb +46 -63
  119. data/lib/beaker/local_connection.rb +4 -6
  120. data/lib/beaker/logger.rb +71 -85
  121. data/lib/beaker/logger_junit.rb +22 -26
  122. data/lib/beaker/network_manager.rb +40 -43
  123. data/lib/beaker/options/command_line_parser.rb +12 -23
  124. data/lib/beaker/options/hosts_file_parser.rb +34 -25
  125. data/lib/beaker/options/options_file_parser.rb +3 -6
  126. data/lib/beaker/options/options_hash.rb +3 -10
  127. data/lib/beaker/options/parser.rb +89 -105
  128. data/lib/beaker/options/presets.rb +114 -123
  129. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  130. data/lib/beaker/options/validator.rb +26 -31
  131. data/lib/beaker/perf.rb +29 -34
  132. data/lib/beaker/platform.rb +38 -46
  133. data/lib/beaker/result.rb +7 -6
  134. data/lib/beaker/shared/error_handler.rb +8 -10
  135. data/lib/beaker/shared/fog_credentials.rb +5 -9
  136. data/lib/beaker/shared/host_manager.rb +40 -46
  137. data/lib/beaker/shared/options_resolver.rb +3 -7
  138. data/lib/beaker/shared/repetition.rb +6 -8
  139. data/lib/beaker/shared/semvar.rb +39 -43
  140. data/lib/beaker/shared/timed.rb +2 -5
  141. data/lib/beaker/shared.rb +1 -1
  142. data/lib/beaker/ssh_connection.rb +46 -55
  143. data/lib/beaker/subcommand.rb +23 -30
  144. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  145. data/lib/beaker/tasks/quick_start.rb +5 -10
  146. data/lib/beaker/tasks/rake_task.rb +26 -28
  147. data/lib/beaker/tasks/test.rb +4 -4
  148. data/lib/beaker/test_case.rb +15 -27
  149. data/lib/beaker/test_suite.rb +35 -39
  150. data/lib/beaker/test_suite_result.rb +52 -57
  151. data/lib/beaker/version.rb +1 -1
  152. data/lib/beaker.rb +5 -6
  153. data/spec/beaker/cli_spec.rb +135 -153
  154. data/spec/beaker/command_spec.rb +64 -58
  155. data/spec/beaker/dsl/assertions_spec.rb +38 -47
  156. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +114 -135
  157. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  158. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +30 -36
  159. data/spec/beaker/dsl/outcomes_spec.rb +15 -14
  160. data/spec/beaker/dsl/roles_spec.rb +170 -132
  161. data/spec/beaker/dsl/structure_spec.rb +181 -163
  162. data/spec/beaker/dsl/test_tagging_spec.rb +94 -95
  163. data/spec/beaker/dsl/wrappers_spec.rb +39 -40
  164. data/spec/beaker/host/aix_spec.rb +14 -14
  165. data/spec/beaker/host/cisco_spec.rb +92 -102
  166. data/spec/beaker/host/eos_spec.rb +15 -36
  167. data/spec/beaker/host/freebsd/exec_spec.rb +5 -8
  168. data/spec/beaker/host/freebsd/pkg_spec.rb +29 -29
  169. data/spec/beaker/host/mac/exec_spec.rb +4 -5
  170. data/spec/beaker/host/mac/group_spec.rb +47 -56
  171. data/spec/beaker/host/mac/user_spec.rb +53 -62
  172. data/spec/beaker/host/pswindows/exec_spec.rb +36 -35
  173. data/spec/beaker/host/pswindows/file_spec.rb +21 -18
  174. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  175. data/spec/beaker/host/pswindows_spec.rb +14 -14
  176. data/spec/beaker/host/unix/exec_spec.rb +87 -92
  177. data/spec/beaker/host/unix/file_spec.rb +76 -82
  178. data/spec/beaker/host/unix/pkg_spec.rb +165 -407
  179. data/spec/beaker/host/unix_spec.rb +11 -207
  180. data/spec/beaker/host/windows/exec_spec.rb +32 -34
  181. data/spec/beaker/host/windows/file_spec.rb +22 -23
  182. data/spec/beaker/host/windows/group_spec.rb +17 -19
  183. data/spec/beaker/host/windows/pkg_spec.rb +10 -13
  184. data/spec/beaker/host/windows/user_spec.rb +17 -23
  185. data/spec/beaker/host/windows_spec.rb +39 -39
  186. data/spec/beaker/host_prebuilt_steps_spec.rb +193 -341
  187. data/spec/beaker/host_spec.rb +241 -312
  188. data/spec/beaker/hypervisor/hypervisor_spec.rb +38 -63
  189. data/spec/beaker/localhost_connection_spec.rb +14 -13
  190. data/spec/beaker/logger_junit_spec.rb +22 -34
  191. data/spec/beaker/logger_spec.rb +174 -155
  192. data/spec/beaker/network_manager_spec.rb +27 -27
  193. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  194. data/spec/beaker/options/data/hosts_preserved.yml +395 -0
  195. data/spec/beaker/options/hosts_file_parser_spec.rb +36 -31
  196. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  197. data/spec/beaker/options/options_hash_spec.rb +7 -9
  198. data/spec/beaker/options/parser_spec.rb +187 -187
  199. data/spec/beaker/options/presets_spec.rb +8 -10
  200. data/spec/beaker/options/subcommand_options_parser_spec.rb +15 -15
  201. data/spec/beaker/options/validator_spec.rb +27 -28
  202. data/spec/beaker/perf_spec.rb +32 -34
  203. data/spec/beaker/platform_spec.rb +27 -37
  204. data/spec/beaker/shared/error_handler_spec.rb +8 -17
  205. data/spec/beaker/shared/fog_credentials_spec.rb +30 -30
  206. data/spec/beaker/shared/host_manager_spec.rb +55 -89
  207. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  208. data/spec/beaker/shared/repetition_spec.rb +24 -31
  209. data/spec/beaker/shared/semvar_spec.rb +21 -26
  210. data/spec/beaker/ssh_connection_spec.rb +85 -90
  211. data/spec/beaker/subcommand/subcommand_util_spec.rb +40 -37
  212. data/spec/beaker/subcommand_spec.rb +89 -89
  213. data/spec/beaker/test_case_spec.rb +33 -62
  214. data/spec/beaker/test_suite_spec.rb +153 -160
  215. data/spec/helpers.rb +48 -53
  216. data/spec/matchers.rb +9 -8
  217. data/spec/mocks.rb +6 -11
  218. data/spec/spec_helper.rb +0 -4
  219. metadata +60 -85
  220. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  221. data/acceptance/tests/base/external_resources_test.rb +0 -31
  222. data/spec/beaker/host/mac_spec.rb +0 -113
  223. data/spec/mock_fission.rb +0 -60
  224. data/spec/mock_vsphere.rb +0 -314
  225. data/spec/mock_vsphere_helper.rb +0 -183
data/lib/beaker/host.rb CHANGED
@@ -6,7 +6,7 @@ require 'rsync'
6
6
  require 'beaker/dsl/helpers'
7
7
  require 'beaker/dsl/patterns'
8
8
 
9
- [ 'command', 'ssh_connection', 'local_connection' ].each do |lib|
9
+ %w[command ssh_connection local_connection].each do |lib|
10
10
  require "beaker/#{lib}"
11
11
  end
12
12
 
@@ -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
@@ -68,6 +68,7 @@ module Beaker
68
68
 
69
69
  attr_accessor :logger
70
70
  attr_reader :name, :host_hash, :options
71
+
71
72
  def initialize name, host_hash, options
72
73
  @logger = host_hash[:logger] || options[:logger]
73
74
  @name, @host_hash, @options = name.to_s, host_hash.dup, options.dup
@@ -86,7 +87,7 @@ module Beaker
86
87
  # TODO: might want to consider caching here; not doing it for now because
87
88
  # I haven't thought through all of the possible scenarios that could
88
89
  # cause the value to change after it had been cached.
89
- result = puppet_configprint['node_name_value'].strip
90
+ puppet_configprint['node_name_value'].strip
90
91
  end
91
92
 
92
93
  def port_open? port
@@ -103,12 +104,12 @@ module Beaker
103
104
  # Wait for a port on the host. Useful for those occasions when you've called
104
105
  # host.reboot and want to avoid spam from subsequent SSH connections retrying
105
106
  # to connect from say retry_on()
106
- def wait_for_port(port, attempts=15)
107
+ def wait_for_port(port, attempts = 15)
107
108
  @logger.debug(" Waiting for port #{port} ... ", false)
108
109
  start = Time.now
109
110
  done = repeat_fibonacci_style_for(attempts) { port_open?(port) }
110
111
  if done
111
- @logger.debug('connected in %0.2f seconds' % (Time.now - start))
112
+ @logger.debug(format('connected in %0.2f seconds', (Time.now - start)))
112
113
  else
113
114
  @logger.debug('timeout')
114
115
  end
@@ -117,7 +118,7 @@ module Beaker
117
118
 
118
119
  def up?
119
120
  begin
120
- Socket.getaddrinfo( reachable_name, nil )
121
+ Socket.getaddrinfo(reachable_name, nil)
121
122
  return true
122
123
  rescue SocketError
123
124
  return false
@@ -133,10 +134,10 @@ module Beaker
133
134
  # class to do things like `host.puppet['vardir']` to query the
134
135
  # 'main' section or, if they want the configuration for a
135
136
  # particular run type, `host.puppet('agent')['vardir']`
136
- def puppet_configprint(command='agent')
137
+ def puppet_configprint(command = 'agent')
137
138
  PuppetConfigReader.new(self, command)
138
139
  end
139
- alias_method :puppet, :puppet_configprint
140
+ alias puppet puppet_configprint
140
141
 
141
142
  def []= k, v
142
143
  host_hash[k] = v
@@ -177,39 +178,21 @@ module Beaker
177
178
  end
178
179
 
179
180
  def is_pe?
180
- self['type'] && self['type'].to_s =~ /pe/
181
+ self['type'] && self['type'].to_s.include?('pe')
181
182
  end
182
183
 
183
184
  def is_cygwin?
184
- self.class == Windows::Host
185
+ self.instance_of?(Windows::Host)
185
186
  end
186
187
 
187
188
  def is_powershell?
188
- self.class == PSWindows::Host
189
+ self.instance_of?(PSWindows::Host)
189
190
  end
190
191
 
191
192
  def platform
192
193
  self['platform']
193
194
  end
194
195
 
195
- # True if this is a pe run, or if the host has had a 'use-service' property set.
196
- def use_service_scripts?
197
- is_pe? || self['use-service']
198
- end
199
-
200
- # Mirrors the true/false value of the host's 'graceful-restarts' property,
201
- # or falls back to the value of +is_using_passenger?+ if
202
- # 'graceful-restarts' is nil, but only if this is not a PE run (foss only).
203
- def graceful_restarts?
204
- graceful =
205
- if !self['graceful-restarts'].nil?
206
- self['graceful-restarts']
207
- else
208
- !is_pe? && is_using_passenger?
209
- end
210
- graceful
211
- end
212
-
213
196
  # Returns true if the host is running in FIPS mode.
214
197
  def fips_mode?
215
198
  if self.file_exist?('/proc/sys/crypto/fips_enabled')
@@ -223,25 +206,6 @@ module Beaker
223
206
  end
224
207
  end
225
208
 
226
- # Modifies the host settings to indicate that it will be using passenger service scripts,
227
- # (apache2) by default. Does nothing if this is a PE host, since it is already using
228
- # passenger.
229
- # @param [String] puppetservice Name of the service script that should be
230
- # called to stop/startPuppet on this host. Defaults to 'apache2'.
231
- def uses_passenger!(puppetservice = 'apache2')
232
- if !is_pe?
233
- self['passenger'] = true
234
- self['puppetservice'] = puppetservice
235
- self['use-service'] = true
236
- end
237
- return true
238
- end
239
-
240
- # True if this is a PE run, or if the host's 'passenger' property has been set.
241
- def is_using_passenger?
242
- is_pe? || self['passenger']
243
- end
244
-
245
209
  def log_prefix
246
210
  if host_hash['vmhostname']
247
211
  "#{self} (#{@name})"
@@ -250,7 +214,7 @@ module Beaker
250
214
  end
251
215
  end
252
216
 
253
- #Determine the ip address of this host
217
+ # Determine the ip address of this host
254
218
  def get_ip
255
219
  @logger.warn("Uh oh, this should be handled by sub-classes but hasn't been")
256
220
  end
@@ -263,27 +227,25 @@ module Beaker
263
227
  return self[:instance].ip_address
264
228
  elsif self[:hypervisor] == 'openstack' && self[:ip]
265
229
  return self[:ip]
266
- else
230
+ elsif self.instance_of?(Windows::Host)
267
231
  # In the case of using ec2 instances with the --no-provision flag, the ec2
268
232
  # instance object does not exist and we should just use the curl endpoint
269
233
  # specified here:
270
234
  # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
271
- if self.instance_of?(Windows::Host)
272
235
  execute("wget http://169.254.169.254/latest/meta-data/public-ipv4").strip
273
- else
236
+ else
274
237
  execute("curl http://169.254.169.254/latest/meta-data/public-ipv4").strip
275
- end
276
238
  end
277
239
  end
278
240
  end
279
241
 
280
- #Return the ip address of this host
281
- #Always pull fresh, because this can sometimes change
242
+ # Return the ip address of this host
243
+ # Always pull fresh, because this can sometimes change
282
244
  def ip
283
245
  self['ip'] = get_public_ip || get_ip
284
246
  end
285
247
 
286
- #@return [Boolean] true if x86_64, false otherwise
248
+ # @return [Boolean] true if x86_64, false otherwise
287
249
  def is_x86_64?
288
250
  @x86_64 ||= determine_if_x86_64
289
251
  end
@@ -291,23 +253,17 @@ module Beaker
291
253
  def connection
292
254
  # create new connection object if necessary
293
255
  if self['hypervisor'] == 'none' && @name == 'localhost'
294
- @connection ||= LocalConnection.connect( { :ssh_env_file => self['ssh_env_file'], :logger => @logger })
256
+ @connection ||= LocalConnection.connect({ :ssh_env_file => self['ssh_env_file'], :logger => @logger })
295
257
  return @connection
296
258
  end
297
259
 
298
- @connection ||= SshConnection.connect( { :ip => self['ip'], :vmhostname => self['vmhostname'], :hostname => @name },
299
- self['user'],
300
- self['ssh'], { :logger => @logger, :ssh_connection_preference => self[:ssh_connection_preference]} )
260
+ @connection ||= SshConnection.connect({ :ip => self['ip'], :vmhostname => self['vmhostname'], :hostname => @name },
261
+ self['user'],
262
+ self['ssh'], { :logger => @logger, :ssh_connection_preference => self[:ssh_connection_preference] })
301
263
  # update connection information
302
- if self['ip'] && (@connection.ip != self['ip'])
303
- @connection.ip = self['ip']
304
- end
305
- if self['vmhostname'] && (@connection.vmhostname != self['vmhostname'])
306
- @connection.vmhostname = self['vmhostname']
307
- end
308
- if @name && (@connection.hostname != @name)
309
- @connection.hostname = @name
310
- end
264
+ @connection.ip = self['ip'] if self['ip'] && (@connection.ip != self['ip'])
265
+ @connection.vmhostname = self['vmhostname'] if self['vmhostname'] && (@connection.vmhostname != self['vmhostname'])
266
+ @connection.hostname = @name if @name && (@connection.hostname != @name)
311
267
  @connection
312
268
  end
313
269
 
@@ -322,7 +278,7 @@ module Beaker
322
278
  @connection = nil
323
279
  end
324
280
 
325
- def exec command, options={}
281
+ def exec command, options = {}
326
282
  result = nil
327
283
  # I've always found this confusing
328
284
  cmdline = command.cmd_line(self)
@@ -341,11 +297,11 @@ module Beaker
341
297
  output_callback = nil
342
298
  else
343
299
  @logger.debug "\n#{log_prefix} #{Time.new.strftime('%H:%M:%S')}$ #{cmdline}"
344
- if @options[:color_host_output]
345
- output_callback = logger.method(:color_host_output)
346
- else
347
- output_callback = logger.method(:host_output)
348
- end
300
+ output_callback = if @options[:color_host_output]
301
+ logger.method(:color_host_output)
302
+ else
303
+ logger.method(:host_output)
304
+ end
349
305
  end
350
306
 
351
307
  unless options[:dry_run]
@@ -353,16 +309,14 @@ module Beaker
353
309
  # the options should come at the end of the method signature (rubyism)
354
310
  # and they shouldn't be ssh specific
355
311
 
356
- seconds = Benchmark.realtime {
312
+ seconds = Benchmark.realtime do
357
313
  @logger.with_indent do
358
314
  result = connection.execute(cmdline, options, output_callback)
359
315
  end
360
- }
361
-
362
- if not options[:silent]
363
- @logger.debug "\n#{log_prefix} executed in %0.2f seconds" % seconds
364
316
  end
365
317
 
318
+ @logger.debug "\n#{log_prefix} executed in %0.2f seconds" % seconds if not options[:silent]
319
+
366
320
  if options[:reset_connection]
367
321
  # Expect the connection to fail hard and possibly take a long time timeout.
368
322
  # Pre-emptively reset it so we don't wait forever.
@@ -378,11 +332,12 @@ module Beaker
378
332
  raise CommandFailure, "Host '#{self}' connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}"
379
333
 
380
334
  end
335
+
381
336
  if options[:expect_connection_failure] && result.exit_code
382
337
  # should have had a connection failure, but didn't
383
338
  # wait to see if the connection failure will be generation, otherwise raise error
384
339
  if not connection.wait_for_connection_failure(options, output_callback)
385
- raise CommandFailure, "Host '#{self}' should have resulted in a connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}"
340
+ raise CommandFailure, "Host '#{self}' should have resulted in a connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}"
386
341
  end
387
342
  end
388
343
  # No, TestCase has the knowledge about whether its failed, checking acceptable
@@ -418,7 +373,7 @@ module Beaker
418
373
  # do_scp_to('source/file.rb', 'target', { :ignore => 'file.rb' }
419
374
  # -> will result in not files copyed to the host, all are ignored
420
375
  def do_scp_to source, target_path, options
421
- target = self.scp_path( target_path )
376
+ target = self.scp_path(target_path)
422
377
 
423
378
  # use the value of :dry_run passed to the method unless
424
379
  # undefined, then use parsed @options hash.
@@ -445,12 +400,11 @@ module Beaker
445
400
  end
446
401
 
447
402
  # either a single file, or a directory with no ignores
448
- if not File.file?(source) and not File.directory?(source)
449
- raise IOError, "No such file or directory - #{source}"
450
- end
403
+ raise IOError, "No such file or directory - #{source}" if not File.file?(source) and not File.directory?(source)
404
+
451
405
  if File.file?(source) or (File.directory?(source) and not has_ignore)
452
406
  source_file = source
453
- if has_ignore and (source =~ ignore_re)
407
+ if has_ignore and ignore_re&.match?(source)
454
408
  @logger.trace "After rejecting ignored files/dirs, there is no file to copy"
455
409
  source_file = nil
456
410
  result.stdout = "No files to copy"
@@ -462,21 +416,21 @@ module Beaker
462
416
  end
463
417
  else # a directory with ignores
464
418
  dir_source = Dir.glob("#{source}/**/*").reject do |f|
465
- f.gsub(/\A#{Regexp.escape(source)}/, '') =~ ignore_re #only match against subdirs, not full path
419
+ ignore_re&.match?(f.gsub(/\A#{Regexp.escape(source)}/, '')) # only match against subdirs, not full path
466
420
  end
467
- @logger.trace "After rejecting ignored files/dirs, going to scp [#{dir_source.join(", ")}]"
421
+ @logger.trace "After rejecting ignored files/dirs, going to scp [#{dir_source.join(', ')}]"
468
422
 
469
423
  # create necessary directory structure on host
470
424
  # run this quietly (no STDOUT)
471
425
  @logger.quiet(true)
472
- required_dirs = (dir_source.map{ | dir | File.dirname(dir) }).uniq
426
+ required_dirs = (dir_source.map { |dir| File.dirname(dir) }).uniq
473
427
  require 'pathname'
474
428
  required_dirs.each do |dir|
475
429
  dir_path = Pathname.new(dir)
476
430
  if dir_path.absolute? and (File.dirname(File.absolute_path(source)).to_s != '/')
477
431
  mkdir_p(File.join(target, dir.gsub(/#{Regexp.escape(File.dirname(File.absolute_path(source)))}/, '')))
478
432
  else
479
- mkdir_p( File.join(target, dir) )
433
+ mkdir_p(File.join(target, dir))
480
434
  end
481
435
  end
482
436
  @logger.quiet(false)
@@ -487,17 +441,17 @@ module Beaker
487
441
  next if File.directory?(s)
488
442
 
489
443
  s_path = Pathname.new(s)
490
- if s_path.absolute? and (File.dirname(File.absolute_path(source)).to_s != '/')
491
- file_path = File.join(target, File.dirname(s).gsub(/#{Regexp.escape(File.dirname(File.absolute_path(source)))}/,''))
492
- else
493
- file_path = File.join(target, File.dirname(s))
494
- end
444
+ file_path = if s_path.absolute? and (File.dirname(File.absolute_path(source)).to_s != '/')
445
+ File.join(target, File.dirname(s).gsub(/#{Regexp.escape(File.dirname(File.absolute_path(source)))}/, ''))
446
+ else
447
+ File.join(target, File.dirname(s))
448
+ end
495
449
  result = connection.scp_to(s, file_path, options)
496
450
  @logger.trace result.stdout
497
451
  end
498
452
  end
499
453
 
500
- self.scp_post_operations( target, target_path )
454
+ self.scp_post_operations(target, target_path)
501
455
  return result
502
456
  end
503
457
 
@@ -509,7 +463,7 @@ module Beaker
509
463
  if options[:dry_run]
510
464
  scp_cmd = "scp #{@name}:#{source} #{target}"
511
465
  @logger.debug "\n Running in :dry_run mode. localhost $ #{scp_cmd} not executed."
512
- return NullResult.new(self, scp_cmd)
466
+ return NullResult.new(self, scp_cmd)
513
467
  end
514
468
 
515
469
  @logger.debug "localhost $ scp #{@name}:#{source} #{target}"
@@ -530,18 +484,16 @@ module Beaker
530
484
  rsync_args = []
531
485
  ssh_args = []
532
486
 
533
- if not File.file?(from_path) and not File.directory?(from_path)
534
- raise IOError, "No such file or directory - #{from_path}"
535
- end
487
+ raise IOError, "No such file or directory - #{from_path}" if not File.file?(from_path) and not File.directory?(from_path)
536
488
 
537
489
  # We enable achieve mode and compression
538
490
  rsync_args << "-az"
539
491
 
540
- if not self['user']
541
- user = "root"
542
- else
543
- user = self['user']
544
- end
492
+ user = if not self['user']
493
+ "root"
494
+ else
495
+ self['user']
496
+ end
545
497
  hostname_with_user = "#{user}@#{reachable_name}"
546
498
 
547
499
  Rsync.host = hostname_with_user
@@ -551,70 +503,61 @@ module Beaker
551
503
  #
552
504
  # We still want any user-set SSH config to win though
553
505
  filesystem_ssh_config = nil
554
- if ssh_opts[:config] && File.exists?(ssh_opts[:config])
506
+ if ssh_opts[:config] && File.exist?(ssh_opts[:config])
555
507
  filesystem_ssh_config = ssh_opts[:config]
556
- elsif self[:vagrant_ssh_config] && File.exists?(self[:vagrant_ssh_config])
508
+ elsif self[:vagrant_ssh_config] && File.exist?(self[:vagrant_ssh_config])
557
509
  filesystem_ssh_config = self[:vagrant_ssh_config]
558
510
  end
559
511
 
560
512
  if filesystem_ssh_config
561
513
  ssh_args << "-F #{filesystem_ssh_config}"
562
- else
563
- if ssh_opts.has_key?('keys') and
514
+ elsif ssh_opts.has_key?('keys') and
564
515
  ssh_opts.has_key?('auth_methods') and
565
516
  ssh_opts['auth_methods'].include?('publickey')
517
+ key = Array(ssh_opts['keys']).find do |k|
518
+ File.exist?(k)
519
+ end
566
520
 
567
- # find the first SSH key that exists
568
- key = Array(ssh_opts['keys']).find do |k|
569
- File.exist?(k)
570
- end
571
-
572
- if key
573
- # rsync doesn't always play nice with tilde, so be sure to expand first
574
- ssh_args << "-i #{File.expand_path(key)}"
575
- end
521
+ if key
522
+ # rsync doesn't always play nice with tilde, so be sure to expand first
523
+ ssh_args << "-i #{File.expand_path(key)}"
576
524
  end
577
- end
578
525
 
579
- if ssh_opts.has_key?(:port)
580
- ssh_args << "-p #{ssh_opts[:port]}"
526
+ # find the first SSH key that exists
581
527
  end
582
528
 
529
+ ssh_args << "-p #{ssh_opts[:port]}" if ssh_opts.has_key?(:port)
530
+
583
531
  # We disable prompt when host isn't known
584
532
  ssh_args << "-o 'StrictHostKeyChecking no'"
585
533
 
586
- if not ssh_args.empty?
587
- rsync_args << "-e \"ssh #{ssh_args.join(' ')}\""
588
- end
534
+ rsync_args << "-e \"ssh #{ssh_args.join(' ')}\"" if not ssh_args.empty?
589
535
 
590
- if opts.has_key?(:ignore) and not opts[:ignore].empty?
591
- rsync_args << opts[:ignore].map { |value| "--exclude '#{value}'" }.join(' ')
592
- end
536
+ rsync_args << opts[:ignore].map { |value| "--exclude '#{value}'" }.join(' ') if opts.has_key?(:ignore) and not opts[:ignore].empty?
593
537
 
594
538
  # We assume that the *contents* of the directory 'from_path' needs to be
595
539
  # copied into the directory 'to_path'
596
- if File.directory?(from_path) and not from_path.end_with?('/')
597
- from_path += '/'
598
- end
540
+ from_path += '/' if File.directory?(from_path) and not from_path.end_with?('/')
599
541
 
600
542
  @logger.notify "rsync: localhost:#{from_path} to #{hostname_with_user}:#{to_path} {:ignore => #{opts[:ignore]}}"
601
543
  result = Rsync.run(from_path, to_path, rsync_args)
602
544
  @logger.debug("rsync returned #{result.inspect}")
603
545
 
604
546
  return result if result.success?
547
+
605
548
  raise Beaker::Host::CommandFailure, result.error
606
549
  end
607
550
  end
608
551
 
609
- [
610
- 'unix',
611
- 'aix',
612
- 'mac',
613
- 'freebsd',
614
- 'windows',
615
- 'pswindows',
616
- 'eos',
617
- 'cisco',
552
+ %w[
553
+ unix
554
+ aix
555
+ mac
556
+ freebsd
557
+ windows
558
+ pswindows
559
+ eos
560
+ cisco
618
561
  ].each do |lib|
619
562
  require "beaker/host/#{lib}"
620
563
  end