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
@@ -2,18 +2,16 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
module Options
|
5
|
-
|
6
5
|
describe Parser do
|
7
6
|
let(:parser) { described_class.new }
|
8
|
-
let(:opts_path) { File.join(
|
9
|
-
let(:hosts_path) { File.join(
|
7
|
+
let(:opts_path) { File.join(__dir__, "data", "opts.txt") }
|
8
|
+
let(:hosts_path) { File.join(__dir__, "data", "hosts.cfg") }
|
10
9
|
|
11
10
|
it "supports usage function" do
|
12
11
|
expect { parser.usage }.not_to raise_error
|
13
12
|
end
|
14
13
|
|
15
14
|
describe 'parse_git_repos' do
|
16
|
-
|
17
15
|
it "transforms arguments of <PROJECT_NAME>/<REF> to <GIT_BASE_URL>/<lowercased_project_name>#<REF>" do
|
18
16
|
opts = ["PUPPET/3.1"]
|
19
17
|
expect(parser.parse_git_repos(opts)).to be === ["#{parser.repo}/puppet.git#3.1"]
|
@@ -23,7 +21,7 @@ module Beaker
|
|
23
21
|
projects = [['puppet', 'my_branch', 'PUPPET/my_branch'],
|
24
22
|
['facter', 'my_branch', 'FACTER/my_branch'],
|
25
23
|
['hiera', 'my_branch', 'HIERA/my_branch'],
|
26
|
-
['hiera-puppet', 'my_branch', 'HIERA-PUPPET/my_branch']]
|
24
|
+
['hiera-puppet', 'my_branch', 'HIERA-PUPPET/my_branch'],]
|
27
25
|
projects.each do |project, ref, input|
|
28
26
|
expect(parser.parse_git_repos([input])).to be === ["#{parser.repo}/#{project}.git##{ref}"]
|
29
27
|
end
|
@@ -31,15 +29,14 @@ module Beaker
|
|
31
29
|
end
|
32
30
|
|
33
31
|
describe 'split_arg' do
|
34
|
-
|
35
32
|
it "can split comma separated list into an array" do
|
36
33
|
arg = "file1,file2,file3"
|
37
|
-
expect(parser.split_arg(arg)).to be === [
|
34
|
+
expect(parser.split_arg(arg)).to be === %w[file1 file2 file3]
|
38
35
|
end
|
39
36
|
|
40
37
|
it "can use an existing Array as an acceptable argument" do
|
41
|
-
arg = [
|
42
|
-
expect(parser.split_arg(arg)).to be === [
|
38
|
+
arg = %w[file1 file2 file3]
|
39
|
+
expect(parser.split_arg(arg)).to be === %w[file1 file2 file3]
|
43
40
|
end
|
44
41
|
|
45
42
|
it "can generate an array from a single value" do
|
@@ -49,7 +46,6 @@ module Beaker
|
|
49
46
|
end
|
50
47
|
|
51
48
|
context 'testing path traversing' do
|
52
|
-
|
53
49
|
let(:test_dir) { 'tmp/tests' }
|
54
50
|
let(:rb_test) { File.expand_path(test_dir + '/my_ruby_file.rb') }
|
55
51
|
let(:pl_test) { File.expand_path(test_dir + '/my_perl_file.pl') }
|
@@ -80,10 +76,11 @@ module Beaker
|
|
80
76
|
|
81
77
|
before do
|
82
78
|
files = [
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
79
|
+
'00_EnvSetup.rb', '035_StopFirewall.rb', '05_HieraSetup.rb',
|
80
|
+
'01_TestSetup.rb', '03_PuppetMasterSanity.rb',
|
81
|
+
'06_InstallModules.rb', '02_PuppetUserAndGroup.rb',
|
82
|
+
'04_ValidateSignCert.rb', '07_InstallCACerts.rb',
|
83
|
+
]
|
87
84
|
|
88
85
|
@lone_file = '08_foss.rb'
|
89
86
|
|
@@ -137,52 +134,60 @@ module Beaker
|
|
137
134
|
end
|
138
135
|
|
139
136
|
describe 'does prioritization correctly' do
|
140
|
-
let(:env) { @env || {:level => 'highest'} }
|
141
|
-
let(:argv) { @argv || {:level => 'second'} }
|
142
|
-
let(:host_file) { @host_file || {:level => 'third'} }
|
143
|
-
let(:opt_file)
|
137
|
+
let(:env) { @env || { :level => 'highest' } }
|
138
|
+
let(:argv) { @argv || { :level => 'second' } }
|
139
|
+
let(:host_file) { @host_file || { :level => 'third' } }
|
140
|
+
let(:opt_file) do
|
141
|
+
@opt_file || {
|
144
142
|
:level => 'fourth',
|
145
143
|
:ssh => {
|
146
|
-
|
147
|
-
|
148
|
-
}
|
149
|
-
|
150
|
-
|
151
|
-
let(:
|
144
|
+
:auth_methods => 'auth123',
|
145
|
+
:user_known_hosts_file => 'hosts123',
|
146
|
+
},
|
147
|
+
}
|
148
|
+
end
|
149
|
+
let(:subcommand_file) { @subcommand_file || { :level => 'fifth' } }
|
150
|
+
let(:homedir_file) do
|
151
|
+
@homedir_file || {
|
152
152
|
:level => 'sixth',
|
153
153
|
:ssh => {
|
154
|
-
|
155
|
-
}
|
156
|
-
|
157
|
-
|
154
|
+
:auth_methods => 'auth_home_123',
|
155
|
+
},
|
156
|
+
}
|
157
|
+
end
|
158
|
+
let(:project_file) do
|
159
|
+
@project_file || {
|
158
160
|
:level => 'seventh',
|
159
161
|
:ssh => {
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
162
|
+
:auth_methods => 'auth_project_123',
|
163
|
+
},
|
164
|
+
}
|
165
|
+
end
|
166
|
+
let(:presets) do
|
167
|
+
{
|
164
168
|
:level => 'lowest',
|
165
169
|
:ssh => {
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
}
|
173
|
-
|
170
|
+
:config => 'config123',
|
171
|
+
:verify_host_key => 'verify123',
|
172
|
+
:port => 'port123',
|
173
|
+
:forward_agent => 'forwardagent123',
|
174
|
+
:keys => 'keys123',
|
175
|
+
:keepalive => 'keepalive123',
|
176
|
+
},
|
177
|
+
}
|
178
|
+
end
|
174
179
|
|
175
180
|
before do
|
176
181
|
expect(parser).to receive(:normalize_args).and_return(true)
|
177
182
|
end
|
178
183
|
|
179
184
|
def mock_out_parsing
|
180
|
-
presets_obj = double
|
185
|
+
presets_obj = double
|
181
186
|
allow(presets_obj).to receive(:presets).and_return(presets)
|
182
187
|
allow(presets_obj).to receive(:env_vars).and_return(env)
|
183
188
|
parser.instance_variable_set(:@presets, presets_obj)
|
184
189
|
|
185
|
-
command_line_parser_obj = double
|
190
|
+
command_line_parser_obj = double
|
186
191
|
allow(command_line_parser_obj).to receive(:parse).and_return(argv)
|
187
192
|
parser.instance_variable_set(:@command_line_parser, command_line_parser_obj)
|
188
193
|
|
@@ -190,7 +195,7 @@ module Beaker
|
|
190
195
|
allow(parser).to receive(:parse_hosts_options).and_return(host_file)
|
191
196
|
|
192
197
|
allow(SubcommandOptionsParser).to receive(:parse_options_file).with(".beaker.yml").and_return(project_file)
|
193
|
-
allow(SubcommandOptionsParser).to receive(:parse_subcommand_options).with(anything, "#{ENV
|
198
|
+
allow(SubcommandOptionsParser).to receive(:parse_subcommand_options).with(anything, "#{ENV.fetch('HOME', nil)}/.beaker/subcommand_options.yaml").and_return(homedir_file)
|
194
199
|
allow(SubcommandOptionsParser).to receive(:parse_subcommand_options).with(anything, Pathname(".beaker/subcommand_options.yaml")).and_return(subcommand_file)
|
195
200
|
end
|
196
201
|
|
@@ -290,7 +295,7 @@ module Beaker
|
|
290
295
|
mock_out_parsing
|
291
296
|
|
292
297
|
project_file[:options_file] = 'my_options_file.rb'
|
293
|
-
allow(OptionsFileParser).to receive(:parse_options_file).with('my_options_file.rb').and_return(ssh: {config: true})
|
298
|
+
allow(OptionsFileParser).to receive(:parse_options_file).with('my_options_file.rb').and_return(ssh: { config: true })
|
294
299
|
|
295
300
|
output = parser.parse_args([])
|
296
301
|
attribution = parser.attribution
|
@@ -307,7 +312,6 @@ module Beaker
|
|
307
312
|
expect(output[:level]).to eq('seventh')
|
308
313
|
expect(attribution[:level]).to eq('project')
|
309
314
|
end
|
310
|
-
|
311
315
|
end
|
312
316
|
|
313
317
|
it "can correctly combine arguments from different sources" do
|
@@ -315,7 +319,7 @@ module Beaker
|
|
315
319
|
type = 'git'
|
316
320
|
log_level = 'debug'
|
317
321
|
|
318
|
-
old_build_url = ENV
|
322
|
+
old_build_url = ENV.fetch("BUILD_URL", nil)
|
319
323
|
ENV["BUILD_URL"] = build_url
|
320
324
|
|
321
325
|
args = ["-h", hosts_path, "--log-level", log_level, "--type", type, "--install", "PUPPET/1.0,HIERA/hello"]
|
@@ -338,20 +342,19 @@ module Beaker
|
|
338
342
|
end
|
339
343
|
|
340
344
|
describe '#parse_hosts_options' do
|
341
|
-
|
342
345
|
context 'Hosts file exists' do
|
343
346
|
before do
|
344
347
|
allow(File).to receive(:exist?).and_return(true)
|
345
348
|
end
|
346
349
|
|
347
350
|
it 'returns the parser\'s output' do
|
348
|
-
parser.instance_variable_set(
|
351
|
+
parser.instance_variable_set(:@options, {})
|
349
352
|
test_value = 'blaqwetjijl,emikfuj1235'
|
350
|
-
allow(
|
351
|
-
:parse_hosts_file
|
352
|
-
).and_return(
|
353
|
-
val1,
|
354
|
-
expect(
|
353
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
354
|
+
:parse_hosts_file,
|
355
|
+
).and_return(test_value)
|
356
|
+
val1, = parser.parse_hosts_options
|
357
|
+
expect(val1).to be === test_value
|
355
358
|
end
|
356
359
|
end
|
357
360
|
|
@@ -362,54 +365,58 @@ module Beaker
|
|
362
365
|
end
|
363
366
|
|
364
367
|
it 'calls beaker-hostgenerator to get hosts information' do
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
).
|
368
|
+
old_beaker_hypervisor = ENV.delete('BEAKER_HYPERVISOR')
|
369
|
+
|
370
|
+
parser.instance_variable_set(:@options, {
|
371
|
+
:hosts_file => 'notafile.yml',
|
372
|
+
})
|
373
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
374
|
+
:parse_hosts_file,
|
375
|
+
).and_raise(Errno::ENOENT)
|
371
376
|
|
372
377
|
mock_beaker_hostgenerator_cli = Object.new
|
373
378
|
cli_execute_return = 'job150865'
|
374
|
-
expect(
|
375
|
-
:execute
|
376
|
-
).and_return(
|
377
|
-
expect(
|
378
|
-
:new
|
379
|
+
expect(mock_beaker_hostgenerator_cli).to receive(
|
380
|
+
:execute,
|
381
|
+
).and_return(cli_execute_return)
|
382
|
+
expect(BeakerHostGenerator::CLI).to receive(
|
383
|
+
:new,
|
379
384
|
).with(
|
380
|
-
[
|
381
|
-
).and_return(
|
382
|
-
allow(
|
383
|
-
:parse_hosts_string
|
384
|
-
).with(
|
385
|
+
['notafile.yml'],
|
386
|
+
).and_return(mock_beaker_hostgenerator_cli)
|
387
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
388
|
+
:parse_hosts_string,
|
389
|
+
).with(cli_execute_return)
|
385
390
|
parser.parse_hosts_options
|
391
|
+
ensure
|
392
|
+
ENV['BEAKER_HYPERVISOR'] = old_beaker_hypervisor if old_beaker_hypervisor
|
386
393
|
end
|
387
394
|
|
388
395
|
it 'calls beaker-hostgenerator to get hosts information with a default hypervisor' do
|
389
|
-
old_beaker_hypervisor = ENV
|
396
|
+
old_beaker_hypervisor = ENV.fetch('BEAKER_HYPERVISOR', nil)
|
390
397
|
begin
|
391
398
|
ENV['BEAKER_HYPERVISOR'] = 'docker'
|
392
399
|
|
393
|
-
parser.instance_variable_set(
|
394
|
-
|
395
|
-
|
396
|
-
allow(
|
397
|
-
:parse_hosts_file
|
398
|
-
).and_raise(
|
400
|
+
parser.instance_variable_set(:@options, {
|
401
|
+
:hosts_file => 'notafile.yml',
|
402
|
+
})
|
403
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
404
|
+
:parse_hosts_file,
|
405
|
+
).and_raise(Errno::ENOENT)
|
399
406
|
|
400
407
|
mock_beaker_hostgenerator_cli = Object.new
|
401
408
|
cli_execute_return = 'job150865'
|
402
|
-
expect(
|
403
|
-
:execute
|
404
|
-
).and_return(
|
405
|
-
expect(
|
406
|
-
:new
|
409
|
+
expect(mock_beaker_hostgenerator_cli).to receive(
|
410
|
+
:execute,
|
411
|
+
).and_return(cli_execute_return)
|
412
|
+
expect(BeakerHostGenerator::CLI).to receive(
|
413
|
+
:new,
|
407
414
|
).with(
|
408
|
-
[
|
409
|
-
).and_return(
|
410
|
-
allow(
|
411
|
-
:parse_hosts_string
|
412
|
-
).with(
|
415
|
+
['notafile.yml', '--hypervisor', 'docker'],
|
416
|
+
).and_return(mock_beaker_hostgenerator_cli)
|
417
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
418
|
+
:parse_hosts_string,
|
419
|
+
).with(cli_execute_return)
|
413
420
|
parser.parse_hosts_options
|
414
421
|
ensure
|
415
422
|
ENV['BEAKER_HYPERVISOR'] = old_beaker_hypervisor
|
@@ -418,73 +425,70 @@ module Beaker
|
|
418
425
|
|
419
426
|
it 'sets the :hosts_file_generated flag to signal others when needed' do
|
420
427
|
options_test = {
|
421
|
-
:hosts_file => 'not_a_file.yml'
|
428
|
+
:hosts_file => 'not_a_file.yml',
|
422
429
|
}
|
423
|
-
parser.instance_variable_set(
|
424
|
-
allow(
|
425
|
-
:parse_hosts_file
|
426
|
-
).and_raise(
|
430
|
+
parser.instance_variable_set(:@options, options_test)
|
431
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
432
|
+
:parse_hosts_file,
|
433
|
+
).and_raise(Errno::ENOENT)
|
427
434
|
|
428
435
|
mock_beaker_hostgenerator_cli = Object.new
|
429
|
-
allow(
|
430
|
-
allow(
|
431
|
-
:new
|
432
|
-
).and_return(
|
433
|
-
allow(
|
436
|
+
allow(mock_beaker_hostgenerator_cli).to receive(:execute)
|
437
|
+
allow(BeakerHostGenerator::CLI).to receive(
|
438
|
+
:new,
|
439
|
+
).and_return(mock_beaker_hostgenerator_cli)
|
440
|
+
allow(Beaker::Options::HostsFileParser).to receive(:parse_hosts_string)
|
434
441
|
parser.parse_hosts_options
|
435
442
|
|
436
|
-
expect(
|
443
|
+
expect(options_test[:hosts_file_generated]).to be true
|
437
444
|
end
|
438
445
|
|
439
446
|
it 'beaker-hostgenerator failures trigger nice prints & a rethrow' do
|
440
447
|
options_test = {
|
441
|
-
:hosts_file => 'not_a_file.yml'
|
448
|
+
:hosts_file => 'not_a_file.yml',
|
442
449
|
}
|
443
|
-
parser.instance_variable_set(
|
444
|
-
allow(
|
445
|
-
:parse_hosts_file
|
446
|
-
).and_raise(
|
450
|
+
parser.instance_variable_set(:@options, options_test)
|
451
|
+
allow(Beaker::Options::HostsFileParser).to receive(
|
452
|
+
:parse_hosts_file,
|
453
|
+
).and_raise(Errno::ENOENT)
|
447
454
|
|
448
455
|
mock_beaker_hostgenerator_cli = Object.new
|
449
|
-
expect(
|
450
|
-
:new
|
451
|
-
).and_return(
|
452
|
-
expect(
|
453
|
-
:execute
|
454
|
-
).and_raise(
|
455
|
-
expect(
|
456
|
-
expect(
|
457
|
-
/does not exist
|
456
|
+
expect(BeakerHostGenerator::CLI).to receive(
|
457
|
+
:new,
|
458
|
+
).and_return(mock_beaker_hostgenerator_cli)
|
459
|
+
expect(mock_beaker_hostgenerator_cli).to receive(
|
460
|
+
:execute,
|
461
|
+
).and_raise(BeakerHostGenerator::Exceptions::InvalidNodeSpecError)
|
462
|
+
expect(Beaker::Options::HostsFileParser).not_to receive(:parse_hosts_string)
|
463
|
+
expect($stdout).to receive(:puts).with(
|
464
|
+
/does not exist/,
|
458
465
|
).ordered
|
459
|
-
expect(
|
460
|
-
/Exiting with an Error
|
466
|
+
expect($stderr).to receive(:puts).with(
|
467
|
+
/Exiting with an Error/,
|
461
468
|
).ordered
|
462
469
|
|
463
|
-
expect
|
470
|
+
expect do
|
464
471
|
parser.parse_hosts_options
|
465
|
-
|
472
|
+
end.to raise_error(BeakerHostGenerator::Exceptions::InvalidNodeSpecError)
|
466
473
|
end
|
467
474
|
|
468
475
|
it 'can be passed a nil hosts file and get the default hash back' do
|
469
|
-
parser.instance_variable_set(
|
476
|
+
parser.instance_variable_set(:@options, {})
|
470
477
|
|
471
478
|
host_options = parser.parse_hosts_options
|
472
479
|
expect(host_options[:HOSTS]).to be === {}
|
473
|
-
|
474
480
|
end
|
475
481
|
end
|
476
|
-
|
477
482
|
end
|
478
483
|
|
479
484
|
context "set_default_host!" do
|
480
|
-
|
481
|
-
let(:
|
482
|
-
let(:
|
483
|
-
let(:node2) { {:node2 => {:roles => roles[1]}} }
|
485
|
+
let(:roles) { @roles || [%w[master agent database], ["agent"]] }
|
486
|
+
let(:node1) { { :node1 => { :roles => roles[0] } } }
|
487
|
+
let(:node2) { { :node2 => { :roles => roles[1] } } }
|
484
488
|
let(:hosts) { node1.merge(node2) }
|
485
489
|
|
486
490
|
it "does nothing if the default host is already set" do
|
487
|
-
@roles = [["master"], [
|
491
|
+
@roles = [["master"], %w[agent default]]
|
488
492
|
parser.set_default_host!(hosts)
|
489
493
|
expect(hosts[:node1][:roles].include?('default')).to be === false
|
490
494
|
expect(hosts[:node2][:roles].include?('default')).to be === true
|
@@ -498,42 +502,41 @@ module Beaker
|
|
498
502
|
end
|
499
503
|
|
500
504
|
it "makes a single node default" do
|
501
|
-
@roles = [[
|
505
|
+
@roles = [%w[master database dashboard agent]]
|
502
506
|
parser.set_default_host!(node1)
|
503
507
|
expect(hosts[:node1][:roles].include?('default')).to be === true
|
504
508
|
end
|
505
509
|
|
506
510
|
it "makes a single non-master node default" do
|
507
|
-
@roles = [[
|
511
|
+
@roles = [%w[database dashboard agent]]
|
508
512
|
parser.set_default_host!(node1)
|
509
513
|
expect(hosts[:node1][:roles].include?('default')).to be === true
|
510
514
|
end
|
511
515
|
|
512
516
|
it "raises an error if two nodes are defined as default" do
|
513
|
-
@roles = [[
|
517
|
+
@roles = [%w[master default], ["default"]]
|
514
518
|
expect { parser.set_default_host!(hosts) }.to raise_error(ArgumentError)
|
515
519
|
end
|
516
|
-
|
517
520
|
end
|
518
521
|
|
519
522
|
describe "normalize_args" do
|
520
523
|
let(:hosts) do
|
521
524
|
Beaker::Options::OptionsHash.new.merge({
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
},
|
525
|
+
'HOSTS' => {
|
526
|
+
:master => {
|
527
|
+
:roles => %w[master agent arbitrary_role],
|
528
|
+
:platform => 'el-7-x86_64',
|
529
|
+
:user => 'root',
|
530
|
+
},
|
531
|
+
:agent => {
|
532
|
+
:roles => %w[agent default other_abitrary_role],
|
533
|
+
:platform => 'el-7-x86_64',
|
534
|
+
:user => 'root',
|
533
535
|
},
|
534
|
-
|
535
|
-
|
536
|
-
|
536
|
+
},
|
537
|
+
'fail_mode' => 'slow',
|
538
|
+
'preserve_hosts' => 'always',
|
539
|
+
'host_tags' => {},
|
537
540
|
})
|
538
541
|
end
|
539
542
|
|
@@ -547,7 +550,6 @@ module Beaker
|
|
547
550
|
end
|
548
551
|
|
549
552
|
shared_examples_for('a platform supporting only agents') do |platform, _type|
|
550
|
-
|
551
553
|
it "restricts #{platform} hosts to agent" do
|
552
554
|
args = []
|
553
555
|
args << '--hosts' << fake_hosts_file_for_platform(hosts, platform)
|
@@ -561,16 +563,15 @@ module Beaker
|
|
561
563
|
end
|
562
564
|
|
563
565
|
context "ssh user" do
|
564
|
-
|
565
566
|
it 'uses the ssh[:user] if it is provided' do
|
566
|
-
hosts['HOSTS'][:master][:ssh] = {:user => 'hello'}
|
567
|
+
hosts['HOSTS'][:master][:ssh] = { :user => 'hello' }
|
567
568
|
parser.instance_variable_set(:@options, hosts)
|
568
569
|
parser.normalize_args
|
569
570
|
expect(hosts['HOSTS'][:master][:user]).to be == 'hello'
|
570
571
|
end
|
571
572
|
|
572
573
|
it 'uses default user if there is an ssh hash, but no ssh[:user]' do
|
573
|
-
hosts['HOSTS'][:master][:ssh] = {:hello => 'hello'}
|
574
|
+
hosts['HOSTS'][:master][:ssh] = { :hello => 'hello' }
|
574
575
|
parser.instance_variable_set(:@options, hosts)
|
575
576
|
parser.normalize_args
|
576
577
|
expect(hosts['HOSTS'][:master][:user]).to be == 'root'
|
@@ -582,20 +583,19 @@ module Beaker
|
|
582
583
|
expect(hosts['HOSTS'][:master][:user]).to be == 'root'
|
583
584
|
end
|
584
585
|
end
|
585
|
-
|
586
586
|
end
|
587
587
|
|
588
588
|
describe '#normalize_tags!' do
|
589
|
-
let(:test_tag_and
|
590
|
-
let(:test_tag_or
|
591
|
-
let(:test_tag_exclude
|
592
|
-
let(:options
|
589
|
+
let(:test_tag_and) { @test_tag_and || [] }
|
590
|
+
let(:test_tag_or) { @test_tag_or || [] }
|
591
|
+
let(:test_tag_exclude) { @test_tag_exclude || [] }
|
592
|
+
let(:options) do
|
593
593
|
opts = Beaker::Options::OptionsHash.new
|
594
594
|
opts[:test_tag_and] = test_tag_and
|
595
595
|
opts[:test_tag_or] = test_tag_or
|
596
596
|
opts[:test_tag_exclude] = test_tag_exclude
|
597
597
|
opts
|
598
|
-
|
598
|
+
end
|
599
599
|
|
600
600
|
it 'does not error if no tags overlap' do
|
601
601
|
@test_tag_and = 'can,tommies,potatoes,plant'
|
@@ -613,9 +613,9 @@ module Beaker
|
|
613
613
|
parser.instance_variable_set(:@options, options)
|
614
614
|
|
615
615
|
parser.normalize_test_tags!
|
616
|
-
expect(options[:test_tag_and]
|
617
|
-
expect(options[:test_tag_or]
|
618
|
-
expect(options[:test_tag_exclude]).to be === [
|
616
|
+
expect(options[:test_tag_and]).to be === %w[can tommies potatoes plant]
|
617
|
+
expect(options[:test_tag_or]).to be === %w[johnny wordsmith zebra]
|
618
|
+
expect(options[:test_tag_exclude]).to be === %w[joey long_running pants]
|
619
619
|
end
|
620
620
|
|
621
621
|
it 'returns empty arrays for empty strings' do
|
@@ -625,8 +625,8 @@ module Beaker
|
|
625
625
|
parser.instance_variable_set(:@options, options)
|
626
626
|
|
627
627
|
parser.normalize_test_tags!
|
628
|
-
expect(options[:test_tag_and]
|
629
|
-
expect(options[:test_tag_or]
|
628
|
+
expect(options[:test_tag_and]).to be === []
|
629
|
+
expect(options[:test_tag_or]).to be === []
|
630
630
|
expect(options[:test_tag_exclude]).to be === []
|
631
631
|
end
|
632
632
|
|
@@ -637,9 +637,9 @@ module Beaker
|
|
637
637
|
parser.instance_variable_set(:@options, options)
|
638
638
|
|
639
639
|
parser.normalize_test_tags!
|
640
|
-
expect(options[:test_tag_and]
|
641
|
-
expect(options[:test_tag_or]
|
642
|
-
expect(options[:test_tag_exclude]).to be === [
|
640
|
+
expect(options[:test_tag_and]).to be === %w[jerry_and_tom parka]
|
641
|
+
expect(options[:test_tag_or]).to be === %w[clearly_they neva]
|
642
|
+
expect(options[:test_tag_exclude]).to be === %w[leet_speak poland]
|
643
643
|
end
|
644
644
|
end
|
645
645
|
|
@@ -665,11 +665,11 @@ module Beaker
|
|
665
665
|
describe '#get_hypervisors' do
|
666
666
|
it 'returns a unique list' do
|
667
667
|
hosts_dupe = {
|
668
|
-
|
669
|
-
|
670
|
-
|
668
|
+
'vm1' => { hypervisor: 'hi' },
|
669
|
+
'vm2' => { hypervisor: 'hi' },
|
670
|
+
'vm3' => { hypervisor: 'bye' },
|
671
671
|
}
|
672
|
-
hosts_single = {'vm1' => {hypervisor: 'hi'}}
|
672
|
+
hosts_single = { 'vm1' => { hypervisor: 'hi' } }
|
673
673
|
|
674
674
|
expect(parser.get_hypervisors(hosts_dupe)).to eq(%w(hi bye))
|
675
675
|
expect(parser.get_hypervisors(hosts_single)).to eq(%w(hi))
|
@@ -679,11 +679,11 @@ module Beaker
|
|
679
679
|
describe '#get_roles' do
|
680
680
|
it 'returns a unique list' do
|
681
681
|
roles_dupe = {
|
682
|
-
|
683
|
-
|
684
|
-
|
682
|
+
'vm1' => { roles: ['master'] },
|
683
|
+
'vm2' => { roles: %w(database dashboard) },
|
684
|
+
'vm3' => { roles: ['bye'] },
|
685
685
|
}
|
686
|
-
roles_single = {'vm1' => {roles: ['hi']}}
|
686
|
+
roles_single = { 'vm1' => { roles: ['hi'] } }
|
687
687
|
|
688
688
|
expect(parser.get_roles(roles_dupe)).to eq([['master'], %w(database dashboard), ['bye']])
|
689
689
|
expect(parser.get_roles(roles_single)).to eq([['hi']])
|
@@ -2,26 +2,25 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
module Options
|
5
|
-
|
6
5
|
describe Presets do
|
7
|
-
let(:presets)
|
6
|
+
let(:presets) { described_class.new }
|
8
7
|
|
9
8
|
it "returns an env_vars OptionsHash" do
|
10
9
|
expect(presets.env_vars).to be_instance_of(Beaker::Options::OptionsHash)
|
11
10
|
end
|
12
11
|
|
13
12
|
it "pulls in env vars of the form ':q_*' and adds them to the :answers of the OptionsHash" do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
ENV['q_puppet_cloud_install'] = 'n'
|
14
|
+
env = presets.env_vars
|
15
|
+
expect(env[:answers][:q_puppet_cloud_install]).to be === 'n'
|
16
|
+
expect(env[:answers]['q_puppet_cloud_install']).to be === 'n'
|
17
|
+
ENV.delete('q_puppet_cloud_install')
|
19
18
|
end
|
20
19
|
|
21
20
|
it "correctly parses the run_in_parallel array" do
|
22
21
|
ENV['BEAKER_RUN_IN_PARALLEL'] = "install,configure"
|
23
22
|
env = presets.env_vars
|
24
|
-
expect(env[:run_in_parallel]).to eq([
|
23
|
+
expect(env[:run_in_parallel]).to eq(%w[install configure])
|
25
24
|
end
|
26
25
|
|
27
26
|
it "removes all empty/nil entries in env_vars" do
|
@@ -37,7 +36,6 @@ module Beaker
|
|
37
36
|
expect(presets.presets).to have_key(:host_tags)
|
38
37
|
expect(presets.presets[:host_tags]).to eq({})
|
39
38
|
end
|
40
|
-
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|