beaker 4.41.2 → 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 +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
@@ -17,7 +17,7 @@ module Beaker
|
|
17
17
|
module Assertions
|
18
18
|
include Minitest::Assertions
|
19
19
|
|
20
|
-
#Why do we need this accessor?
|
20
|
+
# Why do we need this accessor?
|
21
21
|
# https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb#L8-L12
|
22
22
|
# Protocol: Nearly everything here boils up to +assert+, which
|
23
23
|
# expects to be able to increment an instance accessor named
|
@@ -25,6 +25,7 @@ module Beaker
|
|
25
25
|
# provided by the thing including Assertions. See Minitest::Runnable
|
26
26
|
# for an example.
|
27
27
|
attr_writer :assertions
|
28
|
+
|
28
29
|
def assertions
|
29
30
|
@assertions || 0
|
30
31
|
end
|
@@ -71,7 +72,7 @@ module Beaker
|
|
71
72
|
# annotated with stream markers.
|
72
73
|
# @param [String] msg An explanatory message about why the test
|
73
74
|
# failure is relevant.
|
74
|
-
def assert_output(exp_out, msg='Output lines did not match')
|
75
|
+
def assert_output(exp_out, msg = 'Output lines did not match')
|
75
76
|
# Remove the minimal consistent indentation from the input;
|
76
77
|
# useful for clean HEREDOCs.
|
77
78
|
indentation = exp_out.lines.map { |line| line[/^ */].length }.min
|
@@ -82,7 +83,7 @@ module Beaker
|
|
82
83
|
line !~ /^((STD)?ERR|2)> /
|
83
84
|
end
|
84
85
|
our_out, our_err, our_output = [
|
85
|
-
out.join, err.join, cleaned_exp
|
86
|
+
out.join, err.join, cleaned_exp,
|
86
87
|
].map do |str|
|
87
88
|
str.gsub(/^((STD)?(ERR|OUT)|[12])> /, '')
|
88
89
|
end
|
@@ -90,23 +91,10 @@ module Beaker
|
|
90
91
|
# Exercise assertions about output
|
91
92
|
assert_equal our_output, (result.nil? ? '' : result.output), msg
|
92
93
|
assert_equal our_out, (result.nil? ? '' : result.stdout),
|
93
|
-
|
94
|
+
'The contents of STDOUT did not match expectations'
|
94
95
|
assert_equal our_err, (result.nil? ? '' : result.stderr),
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
# Assert that the provided string does not match the provided regular expression, can pass optional message
|
99
|
-
# @deprecated This is placed her for backwards compatability for tests that used Test::Unit::Assertions,
|
100
|
-
# http://apidock.com/ruby/Test/Unit/Assertions/assert_no_match
|
101
|
-
#
|
102
|
-
def assert_no_match(regexp, string, msg=nil)
|
103
|
-
assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.")
|
104
|
-
msg = message(msg) { "<#{mu_pp(regexp)}> expected to not match\n<#{mu_pp(string)}>" }
|
105
|
-
assert(regexp !~ string, msg)
|
96
|
+
'The contents of STDERR did not match expectations'
|
106
97
|
end
|
107
|
-
|
108
|
-
alias_method :assert_not_match, :assert_no_match
|
109
|
-
|
110
98
|
end
|
111
99
|
end
|
112
100
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'hocon/parser/config_document_factory'
|
3
2
|
require 'hocon/config_value_factory'
|
4
3
|
|
@@ -11,7 +10,6 @@ module Beaker
|
|
11
10
|
# - {https://github.com/puppetlabs/beaker/tree/master/docs/how_to/use_hocon_helpers.md Beaker docs}.
|
12
11
|
# - Beaker acceptance tests in +acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb+
|
13
12
|
module HoconHelpers
|
14
|
-
|
15
13
|
# Reads the given hocon file from a SUT
|
16
14
|
#
|
17
15
|
# @param [Host] host Host to get hocon file from.
|
@@ -20,9 +18,8 @@ module Beaker
|
|
20
18
|
# @raise ArgumentError if arguments are missing or incorrect
|
21
19
|
# @return [Hocon::ConfigValueFactory] parsed hocon file
|
22
20
|
def hocon_file_read_on(host, filename)
|
23
|
-
if filename.nil? || filename.empty?
|
24
|
-
|
25
|
-
end
|
21
|
+
raise ArgumentError, '#hocon_file_edit_on requires a filename' if filename.nil? || filename.empty?
|
22
|
+
|
26
23
|
file_contents = on(host, "cat #{filename}").stdout
|
27
24
|
Hocon::Parser::ConfigDocumentFactory.parse_string(file_contents)
|
28
25
|
end
|
@@ -59,7 +56,7 @@ module Beaker
|
|
59
56
|
msg << ' a hocon file to edit. No block was provided.'
|
60
57
|
raise ArgumentError, msg
|
61
58
|
end
|
62
|
-
block_on hosts, {} do |
|
59
|
+
block_on hosts, {} do |host|
|
63
60
|
doc = hocon_file_read_on(host, filename)
|
64
61
|
yield host, doc
|
65
62
|
end
|
@@ -86,7 +83,6 @@ module Beaker
|
|
86
83
|
create_remote_file(host, filename, content_doc.render)
|
87
84
|
end
|
88
85
|
end
|
89
|
-
|
90
86
|
end
|
91
87
|
end
|
92
88
|
end
|
@@ -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
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 |
|
162
|
+
block_on host do |host|
|
196
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 |
|
184
|
+
block_on host do |host|
|
218
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.exist?(filename)
|
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
|
@@ -349,9 +292,8 @@ module Beaker
|
|
349
292
|
script_path = "beaker_powershell_script_#{Time.now.to_i}.ps1"
|
350
293
|
create_remote_file(host, script_path, powershell_script, opts)
|
351
294
|
native_path = script_path.tr('/', "\\")
|
352
|
-
on host, powershell("", {"File" => native_path }), opts
|
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(':')
|
@@ -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
|
@@ -584,7 +523,7 @@ module Beaker
|
|
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
|
@@ -62,34 +61,19 @@ module Beaker
|
|
62
61
|
logger.notify "Fetching: #{src}"
|
63
62
|
logger.notify " and saving to #{dst}"
|
64
63
|
begin
|
65
|
-
|
64
|
+
URI.open(src) do |remote|
|
66
65
|
File.open(dst, "w") do |file|
|
67
66
|
FileUtils.copy_stream(remote, file)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
rescue OpenURI::HTTPError => e
|
71
|
-
if /404.*/.match?(e.message)
|
72
|
-
raise "Failed to fetch_remote_file '#{src}' (#{e.message})"
|
73
|
-
else
|
74
|
-
raise e
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
return dst
|
79
|
-
end
|
70
|
+
raise "Failed to fetch_remote_file '#{src}' (#{e.message})" if /404.*/.match?(e.message)
|
80
71
|
|
81
|
-
|
82
|
-
if RUBY_VERSION.to_f < 2.5
|
83
|
-
URI.send(:open, src) do |remote|
|
84
|
-
yield remote
|
85
|
-
end
|
86
|
-
else
|
87
|
-
URI.open(src) do |remote|
|
88
|
-
yield remote
|
72
|
+
raise e
|
89
73
|
end
|
90
74
|
end
|
75
|
+
return dst
|
91
76
|
end
|
92
|
-
private :uri_open
|
93
77
|
|
94
78
|
# Recursively fetch the contents of the given http url, ignoring
|
95
79
|
# `index.html` and `*.gif` files.
|
@@ -104,14 +88,12 @@ module Beaker
|
|
104
88
|
# @!visibility private
|
105
89
|
def fetch_http_dir(url, dst_dir)
|
106
90
|
logger.notify "fetch_http_dir (url: #{url}, dst_dir #{dst_dir})"
|
107
|
-
if !url.end_with?('/')
|
108
|
-
url += '/'
|
109
|
-
end
|
91
|
+
url += '/' if !url.end_with?('/')
|
110
92
|
url = URI.parse(url)
|
111
93
|
chunks = url.path.split('/')
|
112
94
|
dst = File.join(dst_dir, chunks.last)
|
113
|
-
#determine directory structure to cut
|
114
|
-
#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)
|
115
97
|
cut = chunks.length - 2
|
116
98
|
wget_command = "wget -nv -P #{dst_dir} --reject \"index.html*\",\"*.gif\" --cut-dirs=#{cut} -np -nH --no-check-certificate -r #{url}"
|
117
99
|
|
@@ -123,12 +105,10 @@ module Beaker
|
|
123
105
|
stdout_and_stderr_str.each_line do |line|
|
124
106
|
logger.debug(line)
|
125
107
|
end
|
126
|
-
unless status.success?
|
127
|
-
|
128
|
-
end
|
108
|
+
raise "Failed to fetch_remote_dir '#{url}' (exit code #{$?})" unless status.success?
|
109
|
+
|
129
110
|
dst
|
130
111
|
end
|
131
|
-
|
132
112
|
end
|
133
113
|
end
|
134
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
|