beaker 4.38.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +36 -11
- data/.rubocop.yml +75 -0
- data/.rubocop_todo.yml +239 -0
- data/CHANGELOG.md +88 -33
- data/Gemfile +16 -4
- data/HISTORY.md +103 -0
- data/Rakefile +101 -112
- 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/Gemfile +1 -1
- data/acceptance/fixtures/module/Rakefile +3 -3
- data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +16 -23
- data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -2
- data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
- data/acceptance/lib/helpers/test_helper.rb +7 -6
- 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 +7 -8
- 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 +9 -7
- data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +15 -21
- 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 +23 -30
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +3 -3
- 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 +21 -16
- data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +7 -7
- data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +30 -38
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +14 -18
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +8 -14
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +7 -11
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +5 -5
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +4 -5
- data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +8 -8
- data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +4 -6
- data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
- data/acceptance/tests/base/dsl/structure_test.rb +9 -21
- data/acceptance/tests/base/host/file_test.rb +8 -8
- data/acceptance/tests/base/host/group_test.rb +2 -3
- data/acceptance/tests/base/host/host_test.rb +69 -66
- data/acceptance/tests/base/host/packages.rb +27 -30
- data/acceptance/tests/base/host/packages_unix.rb +0 -55
- data/acceptance/tests/base/host/user_test.rb +2 -3
- 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 +3 -5
- 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 +10 -14
- data/docs/concepts/argument_processing_and_precedence.md +1 -10
- data/docs/concepts/style_guide.md +1 -1
- data/docs/how_to/debug_beaker_tests.md +13 -13
- data/docs/how_to/hosts/eos.md +2 -12
- data/docs/how_to/install_puppet.md +0 -18
- data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
- data/docs/how_to/the_beaker_dsl.md +0 -2
- data/lib/beaker/cli.rb +63 -74
- data/lib/beaker/command.rb +22 -30
- data/lib/beaker/command_factory.rb +4 -3
- data/lib/beaker/dsl/assertions.rb +7 -19
- data/lib/beaker/dsl/helpers/hocon_helpers.rb +5 -9
- data/lib/beaker/dsl/helpers/host_helpers.rb +72 -133
- data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
- data/lib/beaker/dsl/helpers/web_helpers.rb +20 -28
- data/lib/beaker/dsl/helpers.rb +2 -4
- data/lib/beaker/dsl/outcomes.rb +17 -19
- data/lib/beaker/dsl/patterns.rb +1 -3
- data/lib/beaker/dsl/roles.rb +18 -21
- data/lib/beaker/dsl/structure.rb +55 -67
- 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 +3 -3
- data/lib/beaker/host/aix/user.rb +3 -3
- data/lib/beaker/host/aix.rb +3 -4
- data/lib/beaker/host/cisco.rb +36 -48
- 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 +5 -5
- data/lib/beaker/host/mac/group.rb +13 -13
- data/lib/beaker/host/mac/pkg.rb +6 -109
- data/lib/beaker/host/mac/user.rb +7 -7
- data/lib/beaker/host/mac.rb +8 -9
- data/lib/beaker/host/pswindows/exec.rb +70 -74
- data/lib/beaker/host/pswindows/file.rb +4 -6
- data/lib/beaker/host/pswindows/group.rb +5 -5
- data/lib/beaker/host/pswindows/pkg.rb +17 -17
- data/lib/beaker/host/pswindows/user.rb +4 -4
- data/lib/beaker/host/pswindows.rb +4 -3
- data/lib/beaker/host/unix/exec.rb +86 -88
- data/lib/beaker/host/unix/file.rb +41 -47
- data/lib/beaker/host/unix/group.rb +3 -3
- data/lib/beaker/host/unix/pkg.rb +158 -421
- data/lib/beaker/host/unix/user.rb +4 -4
- data/lib/beaker/host/unix.rb +18 -20
- data/lib/beaker/host/windows/exec.rb +20 -20
- data/lib/beaker/host/windows/file.rb +5 -5
- data/lib/beaker/host/windows/group.rb +5 -5
- data/lib/beaker/host/windows/pkg.rb +6 -57
- data/lib/beaker/host/windows/user.rb +4 -4
- data/lib/beaker/host/windows.rb +13 -13
- data/lib/beaker/host.rb +82 -139
- data/lib/beaker/host_prebuilt_steps.rb +121 -233
- data/lib/beaker/hypervisor/noop.rb +2 -4
- data/lib/beaker/hypervisor.rb +46 -63
- data/lib/beaker/local_connection.rb +4 -6
- data/lib/beaker/logger.rb +71 -85
- data/lib/beaker/logger_junit.rb +22 -26
- data/lib/beaker/network_manager.rb +40 -43
- data/lib/beaker/options/command_line_parser.rb +12 -23
- data/lib/beaker/options/hosts_file_parser.rb +34 -25
- data/lib/beaker/options/options_file_parser.rb +3 -6
- data/lib/beaker/options/options_hash.rb +3 -10
- data/lib/beaker/options/parser.rb +89 -105
- 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 +29 -34
- data/lib/beaker/platform.rb +38 -46
- 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 +40 -46
- data/lib/beaker/shared/options_resolver.rb +3 -7
- data/lib/beaker/shared/repetition.rb +6 -8
- data/lib/beaker/shared/semvar.rb +39 -43
- data/lib/beaker/shared/timed.rb +2 -5
- data/lib/beaker/shared.rb +1 -1
- data/lib/beaker/ssh_connection.rb +46 -55
- data/lib/beaker/subcommand.rb +23 -30
- data/lib/beaker/subcommands/subcommand_util.rb +4 -4
- data/lib/beaker/tasks/quick_start.rb +5 -10
- data/lib/beaker/tasks/rake_task.rb +26 -28
- data/lib/beaker/tasks/test.rb +4 -4
- data/lib/beaker/test_case.rb +15 -27
- data/lib/beaker/test_suite.rb +35 -39
- data/lib/beaker/test_suite_result.rb +52 -57
- data/lib/beaker/version.rb +1 -1
- data/lib/beaker.rb +5 -6
- data/spec/beaker/cli_spec.rb +135 -153
- data/spec/beaker/command_spec.rb +64 -58
- data/spec/beaker/dsl/assertions_spec.rb +38 -47
- data/spec/beaker/dsl/helpers/host_helpers_spec.rb +114 -135
- data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
- data/spec/beaker/dsl/helpers/web_helpers_spec.rb +30 -36
- data/spec/beaker/dsl/outcomes_spec.rb +15 -14
- data/spec/beaker/dsl/roles_spec.rb +170 -132
- data/spec/beaker/dsl/structure_spec.rb +181 -163
- data/spec/beaker/dsl/test_tagging_spec.rb +94 -95
- data/spec/beaker/dsl/wrappers_spec.rb +39 -40
- data/spec/beaker/host/aix_spec.rb +14 -14
- data/spec/beaker/host/cisco_spec.rb +92 -102
- data/spec/beaker/host/eos_spec.rb +15 -36
- data/spec/beaker/host/freebsd/exec_spec.rb +5 -8
- data/spec/beaker/host/freebsd/pkg_spec.rb +29 -29
- data/spec/beaker/host/mac/exec_spec.rb +4 -5
- data/spec/beaker/host/mac/group_spec.rb +47 -56
- data/spec/beaker/host/mac/user_spec.rb +53 -62
- data/spec/beaker/host/pswindows/exec_spec.rb +36 -35
- data/spec/beaker/host/pswindows/file_spec.rb +21 -18
- data/spec/beaker/host/pswindows/user_spec.rb +17 -23
- data/spec/beaker/host/pswindows_spec.rb +14 -14
- data/spec/beaker/host/unix/exec_spec.rb +87 -92
- data/spec/beaker/host/unix/file_spec.rb +76 -82
- data/spec/beaker/host/unix/pkg_spec.rb +165 -407
- data/spec/beaker/host/unix_spec.rb +11 -207
- data/spec/beaker/host/windows/exec_spec.rb +32 -34
- data/spec/beaker/host/windows/file_spec.rb +22 -23
- data/spec/beaker/host/windows/group_spec.rb +17 -19
- data/spec/beaker/host/windows/pkg_spec.rb +10 -13
- 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 +193 -341
- data/spec/beaker/host_spec.rb +241 -312
- data/spec/beaker/hypervisor/hypervisor_spec.rb +38 -63
- data/spec/beaker/localhost_connection_spec.rb +14 -13
- data/spec/beaker/logger_junit_spec.rb +22 -34
- data/spec/beaker/logger_spec.rb +174 -155
- data/spec/beaker/network_manager_spec.rb +27 -27
- data/spec/beaker/options/command_line_parser_spec.rb +20 -23
- data/spec/beaker/options/data/hosts_preserved.yml +395 -0
- data/spec/beaker/options/hosts_file_parser_spec.rb +36 -31
- data/spec/beaker/options/options_file_parser_spec.rb +4 -7
- data/spec/beaker/options/options_hash_spec.rb +7 -9
- data/spec/beaker/options/parser_spec.rb +187 -187
- data/spec/beaker/options/presets_spec.rb +8 -10
- data/spec/beaker/options/subcommand_options_parser_spec.rb +15 -15
- data/spec/beaker/options/validator_spec.rb +27 -28
- data/spec/beaker/perf_spec.rb +32 -34
- data/spec/beaker/platform_spec.rb +27 -37
- data/spec/beaker/shared/error_handler_spec.rb +8 -17
- data/spec/beaker/shared/fog_credentials_spec.rb +30 -30
- data/spec/beaker/shared/host_manager_spec.rb +55 -89
- data/spec/beaker/shared/options_resolver_spec.rb +9 -12
- data/spec/beaker/shared/repetition_spec.rb +24 -31
- data/spec/beaker/shared/semvar_spec.rb +21 -26
- data/spec/beaker/ssh_connection_spec.rb +85 -90
- data/spec/beaker/subcommand/subcommand_util_spec.rb +40 -37
- data/spec/beaker/subcommand_spec.rb +89 -89
- data/spec/beaker/test_case_spec.rb +33 -62
- data/spec/beaker/test_suite_spec.rb +153 -160
- data/spec/helpers.rb +48 -53
- data/spec/matchers.rb +9 -8
- data/spec/mocks.rb +6 -11
- data/spec/spec_helper.rb +0 -4
- metadata +60 -85
- 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/spec/mock_fission.rb +0 -60
- data/spec/mock_vsphere.rb +0 -314
- data/spec/mock_vsphere_helper.rb +0 -183
@@ -4,7 +4,6 @@ module Beaker
|
|
4
4
|
# Methods that help you interact and manage the state of your Beaker SUTs, these
|
5
5
|
# methods do not require puppet to be installed to execute correctly
|
6
6
|
module HostHelpers
|
7
|
-
|
8
7
|
# @!macro [new] common_opts
|
9
8
|
# @param [Hash{Symbol=>String}] opts Options to alter execution.
|
10
9
|
# @option opts [Boolean] :silent (false) Do not produce log output
|
@@ -60,13 +59,11 @@ module Beaker
|
|
60
59
|
# @return [Result] An object representing the outcome of *command*.
|
61
60
|
# @raise [FailTest] Raises an exception if *command* obviously fails.
|
62
61
|
def on(host, command, opts = {}, &block)
|
63
|
-
block_on host, opts do |
|
62
|
+
block_on host, opts do |host|
|
64
63
|
if command.is_a? String
|
65
64
|
cmd_opts = {}
|
66
|
-
#add any additional environment variables to the command
|
67
|
-
if opts[:environment]
|
68
|
-
cmd_opts['ENV'] = opts[:environment]
|
69
|
-
end
|
65
|
+
# add any additional environment variables to the command
|
66
|
+
cmd_opts['ENV'] = opts[:environment] if opts[:environment]
|
70
67
|
command_object = Command.new(command.to_s, [], cmd_opts)
|
71
68
|
elsif command.is_a? Command
|
72
69
|
if opts[:environment]
|
@@ -80,20 +77,20 @@ module Beaker
|
|
80
77
|
msg << " object as the command parameter, not #{command.class}."
|
81
78
|
raise ArgumentError, msg
|
82
79
|
end
|
83
|
-
|
80
|
+
result = host.exec(command_object, opts)
|
84
81
|
|
85
82
|
# Also, let additional checking be performed by the caller.
|
86
|
-
if
|
83
|
+
if block
|
87
84
|
case block.arity
|
88
|
-
#block with arity of 0, just hand back yourself
|
89
|
-
|
90
|
-
|
91
|
-
#block with arity of 1 or greater, hand back the result object
|
92
|
-
|
93
|
-
|
85
|
+
# block with arity of 0, just hand back yourself
|
86
|
+
when 0
|
87
|
+
yield self
|
88
|
+
# block with arity of 1 or greater, hand back the result object
|
89
|
+
else
|
90
|
+
yield result
|
94
91
|
end
|
95
92
|
end
|
96
|
-
|
93
|
+
result
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|
@@ -125,36 +122,6 @@ module Beaker
|
|
125
122
|
on(default, command, opts, &block)
|
126
123
|
end
|
127
124
|
|
128
|
-
# @deprecated
|
129
|
-
# An proxy for the last {Beaker::Result#stdout} returned by
|
130
|
-
# a method that makes remote calls. Use the {Beaker::Result}
|
131
|
-
# object returned by the method directly instead. For Usage see
|
132
|
-
# {Beaker::Result}.
|
133
|
-
def stdout
|
134
|
-
return nil if @result.nil?
|
135
|
-
@result.stdout
|
136
|
-
end
|
137
|
-
|
138
|
-
# @deprecated
|
139
|
-
# An proxy for the last {Beaker::Result#stderr} returned by
|
140
|
-
# a method that makes remote calls. Use the {Beaker::Result}
|
141
|
-
# object returned by the method directly instead. For Usage see
|
142
|
-
# {Beaker::Result}.
|
143
|
-
def stderr
|
144
|
-
return nil if @result.nil?
|
145
|
-
@result.stderr
|
146
|
-
end
|
147
|
-
|
148
|
-
# @deprecated
|
149
|
-
# An proxy for the last {Beaker::Result#exit_code} returned by
|
150
|
-
# a method that makes remote calls. Use the {Beaker::Result}
|
151
|
-
# object returned by the method directly instead. For Usage see
|
152
|
-
# {Beaker::Result}.
|
153
|
-
def exit_code
|
154
|
-
return nil if @result.nil?
|
155
|
-
@result.exit_code
|
156
|
-
end
|
157
|
-
|
158
125
|
# Move a file from a remote to a local path
|
159
126
|
# @note If using {Beaker::Host} for the hosts *scp* is not
|
160
127
|
# required on the system as it uses Ruby's net/scp library. The
|
@@ -169,10 +136,10 @@ module Beaker
|
|
169
136
|
#
|
170
137
|
# @return [Result] Returns the result of the SCP operation
|
171
138
|
def scp_from host, from_path, to_path, opts = {}
|
172
|
-
block_on host do |
|
173
|
-
|
174
|
-
|
175
|
-
|
139
|
+
block_on host do |host|
|
140
|
+
result = host.do_scp_from(from_path, to_path, opts)
|
141
|
+
result.log logger
|
142
|
+
result
|
176
143
|
end
|
177
144
|
end
|
178
145
|
|
@@ -192,14 +159,14 @@ module Beaker
|
|
192
159
|
#
|
193
160
|
# @return [Result] Returns the result of the SCP operation
|
194
161
|
def scp_to host, from_path, to_path, opts = {}
|
195
|
-
block_on host do |
|
196
|
-
if host['platform']
|
162
|
+
block_on host do |host|
|
163
|
+
if host['platform'].include?('windows') && to_path.match('`cygpath')
|
197
164
|
result = on host, "echo #{to_path}"
|
198
165
|
to_path = result.raw_output.chomp
|
199
166
|
end
|
200
|
-
|
201
|
-
|
202
|
-
|
167
|
+
result = host.do_scp_to(from_path, to_path, opts)
|
168
|
+
result.log logger
|
169
|
+
result
|
203
170
|
end
|
204
171
|
end
|
205
172
|
|
@@ -214,13 +181,12 @@ module Beaker
|
|
214
181
|
#
|
215
182
|
# @return [Result] Returns the result of the rsync operation
|
216
183
|
def rsync_to host, from_path, to_path, opts = {}
|
217
|
-
block_on host do |
|
218
|
-
if host['platform']
|
184
|
+
block_on host do |host|
|
185
|
+
if host['platform'].include?('windows') && to_path.match('`cygpath')
|
219
186
|
result = host.echo "#{to_path}"
|
220
187
|
to_path = result.raw_output.chomp
|
221
188
|
end
|
222
|
-
|
223
|
-
@result
|
189
|
+
host.do_rsync_to(from_path, to_path, opts)
|
224
190
|
end
|
225
191
|
end
|
226
192
|
|
@@ -268,9 +234,8 @@ module Beaker
|
|
268
234
|
FileUtils.mkdir_p(targetdir)
|
269
235
|
scp_from(host, from_path, targetdir, opts)
|
270
236
|
# scp_from does succeed on a non-existant file, checking if the file/folder actually exists
|
271
|
-
if not File.
|
272
|
-
|
273
|
-
end
|
237
|
+
raise IOError, "No such file or directory - #{filename}" if not File.exist?(filename)
|
238
|
+
|
274
239
|
create_tarball(archive_root, archive_name)
|
275
240
|
end
|
276
241
|
|
@@ -281,28 +246,6 @@ module Beaker
|
|
281
246
|
end
|
282
247
|
private :create_tarball
|
283
248
|
|
284
|
-
|
285
|
-
# Deploy packaging configurations generated by
|
286
|
-
# https://github.com/puppetlabs/packaging to a host.
|
287
|
-
#
|
288
|
-
# @note To ensure the repo configs are available for deployment,
|
289
|
-
# you should run `rake pl:jenkins:deb_repo_configs` and
|
290
|
-
# `rake pl:jenkins:rpm_repo_configs` on your project checkout
|
291
|
-
#
|
292
|
-
# @param [Host] host
|
293
|
-
# @param [String] path The path to the generated repository config
|
294
|
-
# files. ex: /myproject/pkg/repo_configs
|
295
|
-
# @param [String] name A human-readable name for the repository
|
296
|
-
# @param [String] version The version of the project, as used by the
|
297
|
-
# packaging tools. This can be determined with
|
298
|
-
# `rake pl:print_build_params` from the packaging
|
299
|
-
# repo.
|
300
|
-
# @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
|
301
|
-
# @visibility private
|
302
|
-
def deploy_package_repo host, path, name, version
|
303
|
-
host.deploy_package_repo path, name, version
|
304
|
-
end
|
305
|
-
|
306
249
|
# Create a remote file out of a string
|
307
250
|
# @note This method uses Tempfile in Ruby's STDLIB as well as {#scp_to}.
|
308
251
|
#
|
@@ -318,17 +261,17 @@ module Beaker
|
|
318
261
|
# @return [Result] Returns the result of the underlying SCP operation.
|
319
262
|
def create_remote_file(hosts, file_path, file_content, opts = {})
|
320
263
|
Tempfile.open 'beaker' do |tempfile|
|
321
|
-
File.open(tempfile.path, 'w') {|file| file.puts file_content }
|
264
|
+
File.open(tempfile.path, 'w') { |file| file.puts file_content }
|
322
265
|
|
323
266
|
opts[:protocol] ||= 'scp'
|
324
267
|
case opts[:protocol]
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
268
|
+
when 'scp'
|
269
|
+
scp_to hosts, tempfile.path, file_path, opts
|
270
|
+
when 'rsync'
|
271
|
+
rsync_to hosts, tempfile.path, file_path, opts
|
272
|
+
else
|
273
|
+
logger.debug "Unsupported transfer protocol, returning nil"
|
274
|
+
nil
|
332
275
|
end
|
333
276
|
end
|
334
277
|
end
|
@@ -348,10 +291,9 @@ module Beaker
|
|
348
291
|
block_on hosts, opts do |host|
|
349
292
|
script_path = "beaker_powershell_script_#{Time.now.to_i}.ps1"
|
350
293
|
create_remote_file(host, script_path, powershell_script, opts)
|
351
|
-
native_path = script_path.
|
352
|
-
on host, powershell("", {"File" => native_path }), opts
|
294
|
+
native_path = script_path.tr('/', "\\")
|
295
|
+
on host, powershell("", { "File" => native_path }), opts
|
353
296
|
end
|
354
|
-
|
355
297
|
end
|
356
298
|
|
357
299
|
# Move a local script to a remote host and execute it
|
@@ -430,13 +372,11 @@ module Beaker
|
|
430
372
|
#
|
431
373
|
# @return nil
|
432
374
|
def add_system32_hosts_entry(host, opts = {})
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
raise "nothing to do for #{host.name} on #{host['platform']}"
|
439
|
-
end
|
375
|
+
raise "nothing to do for #{host.name} on #{host['platform']}" unless host.is_powershell?
|
376
|
+
|
377
|
+
hosts_file = 'C:\Windows\System32\Drivers\etc\hosts'
|
378
|
+
host_entry = "#{opts['ip']}`t`t#{opts['name']}"
|
379
|
+
on host, powershell("\$text = \\\"#{host_entry}\\\"; Add-Content -path '#{hosts_file}' -value \$text")
|
440
380
|
end
|
441
381
|
|
442
382
|
# Back up the given file in the current_dir to the new_dir
|
@@ -449,12 +389,11 @@ module Beaker
|
|
449
389
|
# @return [String, nil] The path to the file if the file exists, nil if it
|
450
390
|
# doesn't exist.
|
451
391
|
def backup_the_file host, current_dir, new_dir, filename = 'puppet.conf'
|
452
|
-
|
453
392
|
old_location = current_dir + '/' + filename
|
454
393
|
new_location = new_dir + '/' + filename + '.bak'
|
455
394
|
|
456
395
|
if host.file_exist? old_location
|
457
|
-
host.exec(
|
396
|
+
host.exec(Command.new("cp #{old_location} #{new_location}"))
|
458
397
|
return new_location
|
459
398
|
else
|
460
399
|
logger.warn "Could not backup file '#{old_location}': no such file"
|
@@ -471,7 +410,7 @@ module Beaker
|
|
471
410
|
def win_ads_path(file_path)
|
472
411
|
ads_path = {
|
473
412
|
path: file_path,
|
474
|
-
ads: nil
|
413
|
+
ads: nil,
|
475
414
|
}
|
476
415
|
|
477
416
|
split_path = file_path.split(':')
|
@@ -491,7 +430,7 @@ module Beaker
|
|
491
430
|
#
|
492
431
|
# @return [Boolean] Whether the file exists on the host (using `test -f`)
|
493
432
|
def file_exists_on(host, file_path)
|
494
|
-
if host[
|
433
|
+
if host[:platform].include?('windows')
|
495
434
|
command = %(Test-Path #{file_path})
|
496
435
|
|
497
436
|
if file_path.include?(':')
|
@@ -506,7 +445,7 @@ module Beaker
|
|
506
445
|
command = %(test -f "#{file_path}")
|
507
446
|
end
|
508
447
|
|
509
|
-
return on(host, command, { :accept_all_exit_codes => true}).exit_code.zero?
|
448
|
+
return on(host, command, { :accept_all_exit_codes => true }).exit_code.zero?
|
510
449
|
end
|
511
450
|
|
512
451
|
# Check whether a directory exists on the host
|
@@ -516,7 +455,7 @@ module Beaker
|
|
516
455
|
#
|
517
456
|
# @return [Boolean] Whether the directory exists on the host (using `test -d`)
|
518
457
|
def directory_exists_on(host, dir_path)
|
519
|
-
if host[
|
458
|
+
if host[:platform].include?('windows')
|
520
459
|
dir_path = "#{dir_path}\\" unless (dir_path[-1].chr == '\\')
|
521
460
|
|
522
461
|
command = Command.new(%{IF exist "#{dir_path}" ( exit 0 ) ELSE ( exit 1 )}, [], { :cmdexe => true })
|
@@ -535,7 +474,7 @@ module Beaker
|
|
535
474
|
# @return [Boolean] Whether the symlink exists on the host (using `test -L`)
|
536
475
|
def link_exists_on(host, link_path)
|
537
476
|
# Links are weird on windows, fall back to seeing if the file exists
|
538
|
-
return file_exists_on(host, link_path) if host[
|
477
|
+
return file_exists_on(host, link_path) if host[:platform].include?('windows')
|
539
478
|
|
540
479
|
return on(host, Command.new(%(test -L "#{link_path}"), accept_all_exit_codes: true)).exit_code.zero?
|
541
480
|
end
|
@@ -551,8 +490,8 @@ module Beaker
|
|
551
490
|
|
552
491
|
split_path = win_ads_path(file_path)
|
553
492
|
if file_exists_on(host, split_path[:path])
|
554
|
-
if host[
|
555
|
-
file_path.
|
493
|
+
if host[:platform].include?('windows')
|
494
|
+
file_path.tr!('/', '\\')
|
556
495
|
|
557
496
|
command = %{Get-Content -Raw -Path #{file_path}}
|
558
497
|
command += %{ -Stream #{split_path[:ads]}} if split_path[:ads]
|
@@ -580,11 +519,11 @@ module Beaker
|
|
580
519
|
on host, "curl --tlsv1 %s" % cmd, opts, &block
|
581
520
|
end
|
582
521
|
|
583
|
-
def curl_with_retries(
|
522
|
+
def curl_with_retries(_desc, host, url, desired_exit_codes, max_retries = 60, retry_interval = 1)
|
584
523
|
opts = {
|
585
524
|
:desired_exit_codes => desired_exit_codes,
|
586
525
|
:max_retries => max_retries,
|
587
|
-
:retry_interval => retry_interval
|
526
|
+
:retry_interval => retry_interval,
|
588
527
|
}
|
589
528
|
retry_on(host, "curl -m 1 #{url}", opts)
|
590
529
|
end
|
@@ -614,22 +553,22 @@ module Beaker
|
|
614
553
|
option_retry_interval = opts[:retry_interval].to_f
|
615
554
|
desired_exit_codes = option_exit_codes ? [option_exit_codes].flatten : [0]
|
616
555
|
desired_exit_codes = [0] if desired_exit_codes.empty?
|
617
|
-
max_retries = option_max_retries == 0 ? 60 : option_max_retries
|
556
|
+
max_retries = option_max_retries == 0 ? 60 : option_max_retries # nil & "" both return 0
|
618
557
|
retry_interval = option_retry_interval == 0 ? 1 : option_retry_interval
|
619
558
|
verbose = true.to_s == opts[:verbose]
|
620
559
|
|
621
560
|
log_prefix = host.log_prefix
|
622
561
|
logger.debug "\n#{log_prefix} #{Time.new.strftime('%H:%M:%S')}$ #{command}"
|
623
562
|
logger.debug " Trying command #{max_retries} times."
|
624
|
-
logger.debug ".", add_newline=false
|
563
|
+
logger.debug ".", add_newline = false
|
625
564
|
|
626
|
-
result = on host, command, {:accept_all_exit_codes => true, :silent => !verbose}, &block
|
565
|
+
result = on host, command, { :accept_all_exit_codes => true, :silent => !verbose }, &block
|
627
566
|
num_retries = 0
|
628
567
|
until desired_exit_codes.include?(result.exit_code)
|
629
568
|
sleep retry_interval
|
630
|
-
result = on host, command, {:accept_all_exit_codes => true, :silent => !verbose}, &block
|
569
|
+
result = on host, command, { :accept_all_exit_codes => true, :silent => !verbose }, &block
|
631
570
|
num_retries += 1
|
632
|
-
logger.debug ".", add_newline=false
|
571
|
+
logger.debug ".", add_newline = false
|
633
572
|
if (num_retries > max_retries)
|
634
573
|
logger.debug " Command \`#{command}\` failed."
|
635
574
|
fail("Command \`#{command}\` failed.")
|
@@ -641,34 +580,34 @@ module Beaker
|
|
641
580
|
|
642
581
|
# FIX: this should be moved into host/platform
|
643
582
|
# @visibility private
|
644
|
-
def run_cron_on(host, action, user, entry="", &block)
|
645
|
-
block_on host do |
|
583
|
+
def run_cron_on(host, action, user, entry = "", &block)
|
584
|
+
block_on host do |host|
|
646
585
|
platform = host['platform']
|
647
586
|
if platform.include?('solaris') || platform.include?('aix') then
|
648
587
|
case action
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
588
|
+
when :list then args = '-l'
|
589
|
+
when :remove then args = '-r'
|
590
|
+
when :add
|
591
|
+
on(host,
|
592
|
+
"echo '#{entry}' > /var/spool/cron/crontabs/#{user}",
|
593
|
+
&block)
|
655
594
|
end
|
656
595
|
|
657
596
|
else # default for GNU/Linux platforms
|
658
597
|
case action
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
598
|
+
when :list then args = '-l -u'
|
599
|
+
when :remove then args = '-r -u'
|
600
|
+
when :add
|
601
|
+
on(host,
|
602
|
+
"echo '#{entry}' > /tmp/#{user}.cron && " +
|
603
|
+
"crontab -u #{user} /tmp/#{user}.cron",
|
604
|
+
&block)
|
666
605
|
end
|
667
606
|
end
|
668
607
|
|
669
608
|
if args
|
670
609
|
case action
|
671
|
-
|
610
|
+
when :list, :remove then on(host, "crontab #{args} #{user}", &block)
|
672
611
|
end
|
673
612
|
end
|
674
613
|
end
|
@@ -4,12 +4,11 @@ module Beaker
|
|
4
4
|
# Methods that help you query the state of your tests, these
|
5
5
|
# methods do not require puppet to be installed to execute correctly
|
6
6
|
module TestHelpers
|
7
|
-
|
8
7
|
# Gets the currently executing test's name, which is set in a test
|
9
8
|
# using the {Beaker::DSL::Structure#test_name} method.
|
10
9
|
#
|
11
10
|
# @return [String] Test name, or nil if it hasn't been set
|
12
|
-
def current_test_name
|
11
|
+
def current_test_name
|
13
12
|
metadata[:case] && metadata[:case][:name] ? metadata[:case][:name] : nil
|
14
13
|
end
|
15
14
|
|
@@ -21,7 +20,7 @@ module Beaker
|
|
21
20
|
# canal
|
22
21
|
#
|
23
22
|
# @return [String] Test filename, or nil if it hasn't been set
|
24
|
-
def current_test_filename
|
23
|
+
def current_test_filename
|
25
24
|
metadata[:case] && metadata[:case][:file_name] ? metadata[:case][:file_name] : nil
|
26
25
|
end
|
27
26
|
|
@@ -29,7 +28,7 @@ module Beaker
|
|
29
28
|
# This is set using the {Beaker::DSL::Structure#step} method.
|
30
29
|
#
|
31
30
|
# @return [String] Step name, or nil if it hasn't been set
|
32
|
-
def current_step_name
|
31
|
+
def current_step_name
|
33
32
|
metadata[:step] && metadata[:step][:name] ? metadata[:step][:name] : nil
|
34
33
|
end
|
35
34
|
|
@@ -65,7 +64,6 @@ module Beaker
|
|
65
64
|
metadata[:step] ||= {}
|
66
65
|
metadata[:step][:name] = name
|
67
66
|
end
|
68
|
-
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
@@ -3,22 +3,21 @@ module Beaker
|
|
3
3
|
module Helpers
|
4
4
|
# Convenience methods for checking links and moving web content to hosts
|
5
5
|
module WebHelpers
|
6
|
-
|
7
6
|
# Blocks until the port is open on the host specified, returns false
|
8
7
|
# on failure
|
9
|
-
def port_open_within?(
|
10
|
-
repeat_for(
|
11
|
-
host.port_open?(
|
8
|
+
def port_open_within?(host, port = 8140, seconds = 120)
|
9
|
+
repeat_for(seconds) do
|
10
|
+
host.port_open?(port)
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
#Determine is a given URL is accessible
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
# Determine is a given URL is accessible
|
15
|
+
# @param [String] link The URL to examine
|
16
|
+
# @param [Integer] limit redirect limit, will follow redirects that many times
|
17
|
+
# @return [Boolean] true if the ultimate URL after following redirects (301&302) has a '200' HTTP response code, false otherwise
|
18
|
+
# @example
|
20
19
|
# extension = link_exists?("#{URL}.tar.gz") ? ".tar.gz" : ".tar"
|
21
|
-
def link_exists?(link, limit=10)
|
20
|
+
def link_exists?(link, limit = 10)
|
22
21
|
begin
|
23
22
|
require "net/http"
|
24
23
|
require "net/https"
|
@@ -28,7 +27,7 @@ module Beaker
|
|
28
27
|
http.use_ssl = (url.scheme == 'https')
|
29
28
|
http.verify_mode = (OpenSSL::SSL::VERIFY_NONE)
|
30
29
|
response = http.start { |http| http.head(url.request_uri) }
|
31
|
-
if ([
|
30
|
+
if (%w[301 302].include? response.code) && limit > 0
|
32
31
|
logger.debug("#{__method__} following #{response.code} to #{response['location']}")
|
33
32
|
link_exists?(response['location'], limit - 1)
|
34
33
|
else
|
@@ -52,28 +51,25 @@ module Beaker
|
|
52
51
|
# @!visibility private
|
53
52
|
def fetch_http_file(base_url, file_name, dst_dir)
|
54
53
|
require 'open-uri'
|
55
|
-
require 'open_uri_redirections'
|
56
54
|
FileUtils.makedirs(dst_dir)
|
57
55
|
base_url.chomp!('/')
|
58
56
|
src = "#{base_url}/#{file_name}"
|
59
57
|
dst = File.join(dst_dir, file_name)
|
60
|
-
if options[:cache_files_locally] && File.
|
58
|
+
if options[:cache_files_locally] && File.exist?(dst)
|
61
59
|
logger.notify "Already fetched #{dst}"
|
62
60
|
else
|
63
61
|
logger.notify "Fetching: #{src}"
|
64
62
|
logger.notify " and saving to #{dst}"
|
65
63
|
begin
|
66
|
-
open(src
|
64
|
+
URI.open(src) do |remote|
|
67
65
|
File.open(dst, "w") do |file|
|
68
66
|
FileUtils.copy_stream(remote, file)
|
69
67
|
end
|
70
68
|
end
|
71
69
|
rescue OpenURI::HTTPError => e
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
raise e
|
76
|
-
end
|
70
|
+
raise "Failed to fetch_remote_file '#{src}' (#{e.message})" if /404.*/.match?(e.message)
|
71
|
+
|
72
|
+
raise e
|
77
73
|
end
|
78
74
|
end
|
79
75
|
return dst
|
@@ -92,14 +88,12 @@ module Beaker
|
|
92
88
|
# @!visibility private
|
93
89
|
def fetch_http_dir(url, dst_dir)
|
94
90
|
logger.notify "fetch_http_dir (url: #{url}, dst_dir #{dst_dir})"
|
95
|
-
|
96
|
-
url += '/'
|
97
|
-
end
|
91
|
+
url += '/' if !url.end_with?('/')
|
98
92
|
url = URI.parse(url)
|
99
93
|
chunks = url.path.split('/')
|
100
94
|
dst = File.join(dst_dir, chunks.last)
|
101
|
-
#determine directory structure to cut
|
102
|
-
#only want to keep the last directory, thus cut total number of dirs - 2 (hostname + last dir name)
|
95
|
+
# determine directory structure to cut
|
96
|
+
# only want to keep the last directory, thus cut total number of dirs - 2 (hostname + last dir name)
|
103
97
|
cut = chunks.length - 2
|
104
98
|
wget_command = "wget -nv -P #{dst_dir} --reject \"index.html*\",\"*.gif\" --cut-dirs=#{cut} -np -nH --no-check-certificate -r #{url}"
|
105
99
|
|
@@ -111,12 +105,10 @@ module Beaker
|
|
111
105
|
stdout_and_stderr_str.each_line do |line|
|
112
106
|
logger.debug(line)
|
113
107
|
end
|
114
|
-
unless status.success?
|
115
|
-
|
116
|
-
end
|
108
|
+
raise "Failed to fetch_remote_dir '#{url}' (exit code #{$?})" unless status.success?
|
109
|
+
|
117
110
|
dst
|
118
111
|
end
|
119
|
-
|
120
112
|
end
|
121
113
|
end
|
122
114
|
end
|
data/lib/beaker/dsl/helpers.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "beaker/dsl/helpers/#{lib}_helpers"
|
1
|
+
%w[host test web hocon].each do |lib|
|
2
|
+
require "beaker/dsl/helpers/#{lib}_helpers"
|
4
3
|
end
|
5
4
|
|
6
5
|
module Beaker
|
7
6
|
module DSL
|
8
|
-
|
9
7
|
# Contains methods to help you manage and configure your SUTs.
|
10
8
|
|
11
9
|
# Extensions, available in separate modules, enable you to configure and interact with puppet, facter
|
data/lib/beaker/dsl/outcomes.rb
CHANGED
@@ -15,33 +15,31 @@ module Beaker
|
|
15
15
|
# designed to allow some degree of freedom from the individual third
|
16
16
|
# party test runners that could be used.
|
17
17
|
module Outcomes
|
18
|
-
|
19
18
|
# Raise this class if it is determined that a test case should not
|
20
19
|
# be executed because the feature in question is still a
|
21
20
|
# "Work in Progress"
|
22
|
-
class PendingTest <
|
21
|
+
class PendingTest < RuntimeError; end
|
23
22
|
|
24
23
|
# Raise this class if execution should be stopped because the test
|
25
24
|
# is not applicable within a given environment.
|
26
|
-
class SkipTest <
|
25
|
+
class SkipTest < RuntimeError; end
|
27
26
|
|
28
27
|
# Raise this class if some criteria has been met that proves a failure.
|
29
|
-
class FailTest <
|
28
|
+
class FailTest < RuntimeError; end
|
30
29
|
|
31
30
|
# Raise this class if execution should stop because enough criteria has
|
32
31
|
# shown itself to pass the test.
|
33
|
-
class PassTest <
|
34
|
-
|
32
|
+
class PassTest < RuntimeError; end
|
35
33
|
|
36
34
|
# Raises FailTest Exception and logs an error message
|
37
35
|
#
|
38
36
|
# @param [String] msg An optional message to log
|
39
37
|
# @raise [FailTest]
|
40
38
|
def fail_test msg = nil
|
41
|
-
message = formatted_message(
|
42
|
-
logger.warn(
|
39
|
+
message = formatted_message(msg, 'Failed')
|
40
|
+
logger.warn([message, logger.pretty_backtrace].join("\n"))
|
43
41
|
|
44
|
-
raise(
|
42
|
+
raise(FailTest, message)
|
45
43
|
end
|
46
44
|
|
47
45
|
# Raises PassTest Exception and logs a message
|
@@ -49,10 +47,10 @@ module Beaker
|
|
49
47
|
# @param [String] msg An optional message to log
|
50
48
|
# @raise [PassTest]
|
51
49
|
def pass_test msg = nil
|
52
|
-
message = formatted_message(
|
53
|
-
logger.notify(
|
50
|
+
message = formatted_message(msg, 'Passed')
|
51
|
+
logger.notify(message)
|
54
52
|
|
55
|
-
raise(
|
53
|
+
raise(PassTest, message)
|
56
54
|
end
|
57
55
|
|
58
56
|
# Raises PendingTest Exception and logs an error message
|
@@ -60,10 +58,10 @@ module Beaker
|
|
60
58
|
# @param [String] msg An optional message to log
|
61
59
|
# @raise [PendingTest]
|
62
60
|
def pending_test msg = nil
|
63
|
-
message = formatted_message(
|
64
|
-
logger.warn(
|
61
|
+
message = formatted_message(msg, 'is Pending')
|
62
|
+
logger.warn(message)
|
65
63
|
|
66
|
-
raise(
|
64
|
+
raise(PendingTest, message)
|
67
65
|
end
|
68
66
|
|
69
67
|
# Raises SkipTest Exception and logs a message
|
@@ -71,10 +69,10 @@ module Beaker
|
|
71
69
|
# @param [String] msg An optional message to log
|
72
70
|
# @raise [SkipTest]
|
73
71
|
def skip_test msg = nil
|
74
|
-
message = formatted_message(
|
75
|
-
logger.notify(
|
72
|
+
message = formatted_message(msg, 'was Skipped')
|
73
|
+
logger.notify(message)
|
76
74
|
|
77
|
-
raise(
|
75
|
+
raise(SkipTest, message)
|
78
76
|
end
|
79
77
|
|
80
78
|
# populate a TestCase's @exports[] with structured_data
|
@@ -93,7 +91,7 @@ module Beaker
|
|
93
91
|
#
|
94
92
|
# @return [String] A prettier string with helpful info
|
95
93
|
# @!visibility private
|
96
|
-
def formatted_message(message, default_str
|
94
|
+
def formatted_message(message, default_str)
|
97
95
|
msg = message ? "\n#{message}\n" : "\n#{self} #{default_str}.\n"
|
98
96
|
return msg
|
99
97
|
end
|