beaker 4.40.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +17 -28
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +6 -5
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -7
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +16 -28
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +6 -7
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +172 -161
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +48 -57
  167. data/spec/beaker/host/mac/user_spec.rb +54 -63
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +7 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. 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(File.expand_path(File.dirname(__FILE__)), "data", "opts.txt") }
9
- let(:hosts_path) { File.join(File.expand_path(File.dirname(__FILE__)), "data", "hosts.cfg") }
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 === ["file1", "file2", "file3"]
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 = ["file1", "file2", "file3"]
42
- expect(parser.split_arg(arg)).to be === ["file1", "file2", "file3"]
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
- '00_EnvSetup.rb', '035_StopFirewall.rb', '05_HieraSetup.rb',
84
- '01_TestSetup.rb', '03_PuppetMasterSanity.rb',
85
- '06_InstallModules.rb', '02_PuppetUserAndGroup.rb',
86
- '04_ValidateSignCert.rb', '07_InstallCACerts.rb']
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) { @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
- :auth_methods => 'auth123',
147
- :user_known_hosts_file => 'hosts123'
148
- }
149
- }}
150
- let(:subcommand_file) {@subcommand_file || {:level => 'fifth'}}
151
- let(:homedir_file) {@homedir_file || {
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
- :auth_methods => 'auth_home_123'
155
- }
156
- }}
157
- let(:project_file) {@project_file || {
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
- :auth_methods => 'auth_project_123'
161
- }
162
- }}
163
- let(:presets) { {
162
+ :auth_methods => 'auth_project_123',
163
+ },
164
+ }
165
+ end
166
+ let(:presets) do
167
+ {
164
168
  :level => 'lowest',
165
169
  :ssh => {
166
- :config => 'config123',
167
- :verify_host_key => 'verify123',
168
- :port => 'port123',
169
- :forward_agent => 'forwardagent123',
170
- :keys => 'keys123',
171
- :keepalive => 'keepalive123'
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['HOME']}/.beaker/subcommand_options.yaml").and_return(homedir_file)
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["BUILD_URL"]
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( :@options, {} )
351
+ parser.instance_variable_set(:@options, {})
349
352
  test_value = 'blaqwetjijl,emikfuj1235'
350
- allow( Beaker::Options::HostsFileParser ).to receive(
351
- :parse_hosts_file
352
- ).and_return( test_value )
353
- val1, _ = parser.parse_hosts_options
354
- expect( val1 ).to be === test_value
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
- parser.instance_variable_set( :@options, {
366
- :hosts_file => 'notafile.yml'
367
- } )
368
- allow( Beaker::Options::HostsFileParser ).to receive(
369
- :parse_hosts_file
370
- ).and_raise( Errno::ENOENT )
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( mock_beaker_hostgenerator_cli ).to receive(
375
- :execute
376
- ).and_return( cli_execute_return )
377
- expect( BeakerHostGenerator::CLI ).to receive(
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
- [ 'notafile.yml' ]
381
- ).and_return( mock_beaker_hostgenerator_cli )
382
- allow( Beaker::Options::HostsFileParser ).to receive(
383
- :parse_hosts_string
384
- ).with( cli_execute_return )
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['BEAKER_HYPERVISOR']
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( :@options, {
394
- :hosts_file => 'notafile.yml'
395
- } )
396
- allow( Beaker::Options::HostsFileParser ).to receive(
397
- :parse_hosts_file
398
- ).and_raise( Errno::ENOENT )
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( mock_beaker_hostgenerator_cli ).to receive(
403
- :execute
404
- ).and_return( cli_execute_return )
405
- expect( BeakerHostGenerator::CLI ).to receive(
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
- [ 'notafile.yml', '--hypervisor', 'docker' ]
409
- ).and_return( mock_beaker_hostgenerator_cli )
410
- allow( Beaker::Options::HostsFileParser ).to receive(
411
- :parse_hosts_string
412
- ).with( cli_execute_return )
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( :@options, options_test )
424
- allow( Beaker::Options::HostsFileParser ).to receive(
425
- :parse_hosts_file
426
- ).and_raise( Errno::ENOENT )
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( mock_beaker_hostgenerator_cli ).to receive( :execute )
430
- allow( BeakerHostGenerator::CLI ).to receive(
431
- :new
432
- ).and_return( mock_beaker_hostgenerator_cli )
433
- allow( Beaker::Options::HostsFileParser ).to receive( :parse_hosts_string )
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( options_test[:hosts_file_generated] ).to be true
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( :@options, options_test )
444
- allow( Beaker::Options::HostsFileParser ).to receive(
445
- :parse_hosts_file
446
- ).and_raise( Errno::ENOENT )
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( BeakerHostGenerator::CLI ).to receive(
450
- :new
451
- ).and_return( mock_beaker_hostgenerator_cli )
452
- expect( mock_beaker_hostgenerator_cli ).to receive(
453
- :execute
454
- ).and_raise( BeakerHostGenerator::Exceptions::InvalidNodeSpecError )
455
- expect( Beaker::Options::HostsFileParser ).not_to receive( :parse_hosts_string )
456
- expect( $stdout ).to receive( :puts ).with(
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( $stderr ).to receive( :puts ).with(
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
- }.to raise_error( BeakerHostGenerator::Exceptions::InvalidNodeSpecError )
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( :@options, {} )
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(:roles) { @roles || [["master", "agent", "database"], ["agent"]] }
482
- let(:node1) { {:node1 => {:roles => roles[0]}} }
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"], ["agent", "default"]]
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 = [["master", "database", "dashboard", "agent"]]
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 = [["database", "dashboard", "agent"]]
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 = [["master", "default"], ["default"]]
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
- 'HOSTS' => {
523
- :master => {
524
- :roles => ["master", "agent", "arbitrary_role"],
525
- :platform => 'el-7-x86_64',
526
- :user => 'root',
527
- },
528
- :agent => {
529
- :roles => ["agent", "default", "other_abitrary_role"],
530
- :platform => 'el-7-x86_64',
531
- :user => 'root',
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
- 'fail_mode' => 'slow',
535
- 'preserve_hosts' => 'always',
536
- 'host_tags' => {}
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 ) { @test_tag_and || [] }
590
- let(:test_tag_or ) { @test_tag_or || [] }
591
- let(:test_tag_exclude ) { @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] ).to be === ['can', 'tommies', 'potatoes', 'plant']
617
- expect(options[:test_tag_or] ).to be === ['johnny', 'wordsmith', 'zebra']
618
- expect(options[:test_tag_exclude]).to be === ['joey', 'long_running', 'pants']
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] ).to be === []
629
- expect(options[:test_tag_or] ).to be === []
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] ).to be === ['jerry_and_tom', 'parka']
641
- expect(options[:test_tag_or] ).to be === ['clearly_they', 'neva']
642
- expect(options[:test_tag_exclude]).to be === ['leet_speak', 'poland']
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
- 'vm1' => {hypervisor: 'hi'},
669
- 'vm2' => {hypervisor: 'hi'},
670
- 'vm3' => {hypervisor: 'bye'}
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
- 'vm1' => {roles: ['master']},
683
- 'vm2' => {roles: %w(database dashboard)},
684
- 'vm3' => {roles: ['bye']}
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) { described_class.new }
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
- ENV['q_puppet_cloud_install'] = 'n'
15
- env = presets.env_vars
16
- expect(env[:answers][:q_puppet_cloud_install]).to be === 'n'
17
- expect(env[:answers]['q_puppet_cloud_install']).to be === 'n'
18
- ENV.delete('q_puppet_cloud_install')
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(['install', 'configure'])
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