beaker 4.41.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +26 -13
- data/.rubocop.yml +23 -10
- data/.rubocop_todo.yml +34 -10
- data/CHANGELOG.md +16 -52
- data/Gemfile +12 -7
- data/HISTORY.md +605 -0
- data/Rakefile +99 -111
- data/acceptance/config/acceptance-options.rb +1 -1
- data/acceptance/config/base/acceptance-options.rb +2 -2
- data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
- data/acceptance/config/subcommands/acceptance-options.rb +2 -2
- data/acceptance/fixtures/module/Rakefile +1 -1
- data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
- data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
- data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
- data/acceptance/lib/helpers/test_helper.rb +6 -5
- data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
- data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
- data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
- data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
- data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
- data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
- data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
- data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
- data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
- data/acceptance/tests/base/dsl/structure_test.rb +5 -11
- data/acceptance/tests/base/host/file_test.rb +2 -2
- data/acceptance/tests/base/host/group_test.rb +0 -1
- data/acceptance/tests/base/host/host_test.rb +66 -63
- data/acceptance/tests/base/host/packages.rb +1 -2
- data/acceptance/tests/base/host/packages_unix.rb +0 -55
- data/acceptance/tests/base/host/user_test.rb +0 -1
- data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
- data/acceptance/tests/base/test_suite/export.rb +6 -9
- data/acceptance/tests/install/from_file.rb +2 -4
- data/acceptance/tests/load_path_bootstrap.rb +1 -1
- data/acceptance/tests/subcommands/destroy.rb +19 -21
- data/acceptance/tests/subcommands/exec.rb +0 -1
- data/acceptance/tests/subcommands/init.rb +2 -3
- data/acceptance/tests/subcommands/provision.rb +0 -1
- data/beaker.gemspec +4 -7
- data/docs/concepts/argument_processing_and_precedence.md +1 -10
- data/docs/how_to/debug_beaker_tests.md +12 -12
- data/docs/how_to/hosts/eos.md +2 -12
- data/docs/how_to/install_puppet.md +0 -18
- data/docs/how_to/the_beaker_dsl.md +0 -2
- data/lib/beaker/cli.rb +59 -68
- data/lib/beaker/command.rb +20 -28
- data/lib/beaker/command_factory.rb +3 -2
- data/lib/beaker/dsl/assertions.rb +6 -18
- data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
- data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
- data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
- data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
- data/lib/beaker/dsl/helpers.rb +2 -4
- data/lib/beaker/dsl/outcomes.rb +13 -15
- data/lib/beaker/dsl/patterns.rb +1 -3
- data/lib/beaker/dsl/roles.rb +17 -20
- data/lib/beaker/dsl/structure.rb +53 -65
- data/lib/beaker/dsl/test_tagging.rb +7 -10
- data/lib/beaker/dsl/wrappers.rb +15 -16
- data/lib/beaker/dsl.rb +2 -3
- data/lib/beaker/host/aix/exec.rb +1 -1
- data/lib/beaker/host/aix/file.rb +0 -1
- data/lib/beaker/host/aix/group.rb +1 -1
- data/lib/beaker/host/aix/user.rb +1 -1
- data/lib/beaker/host/aix.rb +3 -4
- data/lib/beaker/host/cisco.rb +27 -39
- data/lib/beaker/host/eos.rb +4 -30
- data/lib/beaker/host/freebsd/exec.rb +1 -1
- data/lib/beaker/host/freebsd/pkg.rb +3 -3
- data/lib/beaker/host/freebsd.rb +9 -12
- data/lib/beaker/host/mac/exec.rb +4 -4
- data/lib/beaker/host/mac/group.rb +7 -7
- data/lib/beaker/host/mac/pkg.rb +3 -106
- data/lib/beaker/host/mac/user.rb +2 -2
- data/lib/beaker/host/mac.rb +8 -9
- data/lib/beaker/host/pswindows/exec.rb +66 -70
- data/lib/beaker/host/pswindows/file.rb +3 -5
- data/lib/beaker/host/pswindows/group.rb +3 -3
- data/lib/beaker/host/pswindows/pkg.rb +12 -12
- data/lib/beaker/host/pswindows/user.rb +3 -3
- data/lib/beaker/host/pswindows.rb +4 -3
- data/lib/beaker/host/unix/exec.rb +81 -83
- data/lib/beaker/host/unix/file.rb +40 -45
- data/lib/beaker/host/unix/group.rb +1 -1
- data/lib/beaker/host/unix/pkg.rb +138 -401
- data/lib/beaker/host/unix/user.rb +2 -2
- data/lib/beaker/host/unix.rb +8 -11
- data/lib/beaker/host/windows/exec.rb +17 -17
- data/lib/beaker/host/windows/file.rb +3 -3
- data/lib/beaker/host/windows/group.rb +3 -3
- data/lib/beaker/host/windows/pkg.rb +3 -54
- data/lib/beaker/host/windows/user.rb +3 -3
- data/lib/beaker/host/windows.rb +12 -12
- data/lib/beaker/host.rb +76 -133
- data/lib/beaker/host_prebuilt_steps.rb +88 -196
- data/lib/beaker/hypervisor/noop.rb +2 -4
- data/lib/beaker/hypervisor.rb +44 -61
- data/lib/beaker/local_connection.rb +2 -4
- data/lib/beaker/logger.rb +68 -76
- data/lib/beaker/logger_junit.rb +21 -25
- data/lib/beaker/network_manager.rb +39 -42
- data/lib/beaker/options/command_line_parser.rb +12 -23
- data/lib/beaker/options/hosts_file_parser.rb +16 -25
- data/lib/beaker/options/options_file_parser.rb +3 -6
- data/lib/beaker/options/options_hash.rb +2 -7
- data/lib/beaker/options/parser.rb +86 -102
- data/lib/beaker/options/presets.rb +114 -123
- data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
- data/lib/beaker/options/validator.rb +26 -31
- data/lib/beaker/perf.rb +25 -30
- data/lib/beaker/platform.rb +26 -37
- data/lib/beaker/result.rb +7 -6
- data/lib/beaker/shared/error_handler.rb +8 -10
- data/lib/beaker/shared/fog_credentials.rb +5 -9
- data/lib/beaker/shared/host_manager.rb +36 -41
- data/lib/beaker/shared/options_resolver.rb +3 -7
- data/lib/beaker/shared/repetition.rb +2 -4
- data/lib/beaker/shared/semvar.rb +37 -41
- data/lib/beaker/shared/timed.rb +0 -3
- data/lib/beaker/shared.rb +1 -1
- data/lib/beaker/ssh_connection.rb +38 -47
- data/lib/beaker/subcommand.rb +17 -24
- data/lib/beaker/subcommands/subcommand_util.rb +4 -4
- data/lib/beaker/tasks/quick_start.rb +4 -9
- data/lib/beaker/tasks/rake_task.rb +25 -27
- data/lib/beaker/tasks/test.rb +4 -4
- data/lib/beaker/test_case.rb +16 -28
- data/lib/beaker/test_suite.rb +35 -39
- data/lib/beaker/test_suite_result.rb +45 -47
- data/lib/beaker/version.rb +1 -1
- data/lib/beaker.rb +6 -7
- data/spec/beaker/cli_spec.rb +121 -142
- data/spec/beaker/command_spec.rb +55 -59
- data/spec/beaker/dsl/assertions_spec.rb +36 -36
- data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
- data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
- data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
- data/spec/beaker/dsl/outcomes_spec.rb +14 -14
- data/spec/beaker/dsl/roles_spec.rb +125 -130
- data/spec/beaker/dsl/structure_spec.rb +172 -161
- data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
- data/spec/beaker/dsl/wrappers_spec.rb +32 -33
- data/spec/beaker/host/aix_spec.rb +14 -14
- data/spec/beaker/host/cisco_spec.rb +84 -94
- data/spec/beaker/host/eos_spec.rb +15 -36
- data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
- data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
- data/spec/beaker/host/mac/exec_spec.rb +2 -3
- data/spec/beaker/host/mac/group_spec.rb +48 -57
- data/spec/beaker/host/mac/user_spec.rb +54 -63
- data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
- data/spec/beaker/host/pswindows/file_spec.rb +16 -16
- data/spec/beaker/host/pswindows/user_spec.rb +17 -23
- data/spec/beaker/host/pswindows_spec.rb +13 -13
- data/spec/beaker/host/unix/exec_spec.rb +75 -80
- data/spec/beaker/host/unix/file_spec.rb +66 -71
- data/spec/beaker/host/unix/pkg_spec.rb +150 -411
- data/spec/beaker/host/unix_spec.rb +11 -207
- data/spec/beaker/host/windows/exec_spec.rb +30 -32
- data/spec/beaker/host/windows/file_spec.rb +18 -19
- data/spec/beaker/host/windows/group_spec.rb +10 -12
- data/spec/beaker/host/windows/pkg_spec.rb +6 -9
- data/spec/beaker/host/windows/user_spec.rb +17 -23
- data/spec/beaker/host/windows_spec.rb +39 -39
- data/spec/beaker/host_prebuilt_steps_spec.rb +168 -349
- data/spec/beaker/host_spec.rb +204 -284
- data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
- data/spec/beaker/localhost_connection_spec.rb +10 -11
- data/spec/beaker/logger_junit_spec.rb +19 -30
- data/spec/beaker/logger_spec.rb +153 -136
- data/spec/beaker/network_manager_spec.rb +23 -23
- data/spec/beaker/options/command_line_parser_spec.rb +20 -23
- data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
- data/spec/beaker/options/options_file_parser_spec.rb +4 -7
- data/spec/beaker/options/options_hash_spec.rb +4 -6
- data/spec/beaker/options/parser_spec.rb +167 -167
- data/spec/beaker/options/presets_spec.rb +7 -9
- data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
- data/spec/beaker/options/validator_spec.rb +10 -11
- data/spec/beaker/perf_spec.rb +18 -21
- data/spec/beaker/platform_spec.rb +25 -50
- data/spec/beaker/shared/error_handler_spec.rb +7 -16
- data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
- data/spec/beaker/shared/host_manager_spec.rb +50 -84
- data/spec/beaker/shared/options_resolver_spec.rb +9 -12
- data/spec/beaker/shared/repetition_spec.rb +17 -24
- data/spec/beaker/shared/semvar_spec.rb +21 -26
- data/spec/beaker/ssh_connection_spec.rb +76 -83
- data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
- data/spec/beaker/subcommand_spec.rb +75 -77
- data/spec/beaker/test_case_spec.rb +25 -50
- data/spec/beaker/test_suite_spec.rb +147 -154
- data/spec/helpers.rb +39 -45
- data/spec/matchers.rb +8 -7
- data/spec/mocks.rb +1 -6
- data/spec/spec_helper.rb +0 -1
- metadata +8 -24
- data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
- data/acceptance/tests/base/external_resources_test.rb +0 -31
- data/spec/beaker/host/mac_spec.rb +0 -113
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
|
-
[
|
|
9
|
+
%w[command ssh_connection local_connection].each do |lib|
|
|
10
10
|
require "beaker/#{lib}"
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -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
|
|
@@ -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'
|
|
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(
|
|
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
|
-
|
|
140
|
+
alias puppet puppet_configprint
|
|
140
141
|
|
|
141
142
|
def []= k, v
|
|
142
143
|
host_hash[k] = v
|
|
@@ -181,35 +182,17 @@ module Beaker
|
|
|
181
182
|
end
|
|
182
183
|
|
|
183
184
|
def is_cygwin?
|
|
184
|
-
self.
|
|
185
|
+
self.instance_of?(Windows::Host)
|
|
185
186
|
end
|
|
186
187
|
|
|
187
188
|
def is_powershell?
|
|
188
|
-
self.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
304
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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,
|
|
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(
|
|
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,9 +400,8 @@ 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
|
-
|
|
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
407
|
if has_ignore and ignore_re&.match?(source)
|
|
@@ -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
|
-
ignore_re&.match?(f.gsub(/\A#{Regexp.escape(source)}/, '')) #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{ |
|
|
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(
|
|
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
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
|
@@ -559,62 +511,53 @@ module Beaker
|
|
|
559
511
|
|
|
560
512
|
if filesystem_ssh_config
|
|
561
513
|
ssh_args << "-F #{filesystem_ssh_config}"
|
|
562
|
-
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
-
|
|
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
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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
|