beaker 4.39.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 +16 -0
  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 +4 -3
  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 -8
  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 -27
  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 +15 -27
  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 +5 -6
  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 +28 -34
  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 +169 -158
  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 +47 -56
  167. data/spec/beaker/host/mac/user_spec.rb +53 -62
  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 +12 -37
  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
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'beaker-hostgenerator'
4
4
  require 'beaker'
5
5
  HOSTS_PRESERVED = 'log/latest/hosts_preserved.yml'
6
6
 
7
- task :default => [ 'test:spec' ]
7
+ task :default => ['test:spec']
8
8
 
9
9
  task :test do
10
10
  Rake::Task['test:spec'].invoke
@@ -14,9 +14,7 @@ task :spec do
14
14
  Rake::Task['test:spec'].invoke
15
15
  end
16
16
 
17
-
18
- task :acceptance => ['test:base', 'test:puppetgit', 'test:hypervisor']
19
-
17
+ task :acceptance => ['test:base', 'test:hypervisor']
20
18
 
21
19
  task :yard do
22
20
  Rake::Task['docs:gen'].invoke
@@ -28,9 +26,9 @@ end
28
26
 
29
27
  module HarnessOptions
30
28
  defaults = {
31
- :tests => ['tests'],
32
- :log_level => 'debug',
33
- :preserve_hosts => 'onfail',
29
+ :tests => ['tests'],
30
+ :log_level => 'debug',
31
+ :preserve_hosts => 'onfail',
34
32
  }
35
33
 
36
34
  DEFAULTS = defaults
@@ -60,31 +58,28 @@ module HarnessOptions
60
58
  final_options.merge!(intermediary_options)
61
59
  final_options.merge!(local_overrides)
62
60
  end
63
-
64
61
  end
65
62
 
66
63
  def hosts_file_env
67
- ENV['BEAKER_HOSTS']
64
+ ENV.fetch('BEAKER_HOSTS', nil)
68
65
  end
69
66
 
70
- def hosts_opt(use_preserved_hosts=false)
67
+ def hosts_opt(use_preserved_hosts = false)
71
68
  if use_preserved_hosts
72
69
  "--hosts=#{HOSTS_PRESERVED}"
70
+ elsif hosts_file_env
71
+ "--hosts=#{hosts_file_env}"
73
72
  else
74
- if hosts_file_env
75
- "--hosts=#{hosts_file_env}"
76
- else
77
- "--hosts=tmp/#{HOSTS_FILE}"
78
- end
73
+ "--hosts=tmp/#{HOSTS_FILE}"
79
74
  end
80
75
  end
81
76
 
82
77
  def agent_target
83
- ENV['TEST_TARGET'] || 'redhat7-64af'
78
+ ENV['TEST_TARGET'] || 'centos7-64af'
84
79
  end
85
80
 
86
81
  def master_target
87
- ENV['MASTER_TEST_TARGET'] || 'redhat7-64default.mdcal'
82
+ ENV['MASTER_TEST_TARGET'] || 'centos7-64default.mdcal'
88
83
  end
89
84
 
90
85
  def test_targets
@@ -94,11 +89,10 @@ end
94
89
  HOSTS_FILE = "#{test_targets}-#{SecureRandom.uuid}.yaml"
95
90
 
96
91
  def beaker_test(mode = :base, options = {})
97
-
98
92
  preserved_hosts_mode = options[:hosts] == HOSTS_PRESERVED
99
93
  final_options = HarnessOptions.final_options(mode, options)
100
94
 
101
- options_opt = ""
95
+ options_opt = ""
102
96
  # preserved hosts can not be used with an options file (BKR-670)
103
97
  # one can still use OPTIONS
104
98
 
@@ -106,94 +100,88 @@ def beaker_test(mode = :base, options = {})
106
100
  options_file = 'merged_options.rb'
107
101
  options_opt = "--options-file=#{options_file}"
108
102
  File.open(options_file, 'w') do |merged|
109
- merged.puts <<-EOS
110
- # Copy this file to local_options.rb and adjust as needed if you wish to run
111
- # with some local overrides.
103
+ merged.puts <<~EOS
104
+ # Copy this file to local_options.rb and adjust as needed if you wish to run
105
+ # with some local overrides.
112
106
  EOS
113
107
  merged.puts(final_options)
114
108
  end
115
109
  end
116
110
 
117
- tests = ENV['TESTS'] || ENV['TEST']
111
+ tests = ENV['TESTS'] || ENV.fetch('TEST', nil)
118
112
  tests_opt = ""
119
113
  tests_opt = "--tests=#{tests}" if tests
120
114
 
121
115
  overriding_options = ENV['OPTIONS'].to_s
122
116
 
123
- args = [options_opt, hosts_opt(preserved_hosts_mode), tests_opt,
124
- *overriding_options.split(' ')].compact
117
+ args = [options_opt, hosts_opt(preserved_hosts_mode), tests_opt, *overriding_options.split(' ')].compact
125
118
 
126
119
  sh("beaker", *args)
127
120
  end
128
121
 
129
-
130
122
  namespace :test do
131
- USAGE = <<-EOS
132
- You may set BEAKER_HOSTS=config/nodes/foo.yaml or include it in an acceptance-options.rb for Beaker,
133
- or specify TEST_TARGET in a form beaker-hostgenerator accepts, e.g. ubuntu1504-64a.
134
- You may override the default master test target by specifying MASTER_TEST_TARGET.
135
- You may set TESTS=path/to/test,and/more/tests.
136
- You may set additional Beaker OPTIONS='--more --options'
137
- If there is a Beaker options hash in a ./acceptance/local_options.rb, it will be included.
138
- Commandline options set through the above environment variables will override settings in this file.
123
+ USAGE = <<~EOS
124
+ You may set BEAKER_HOSTS=config/nodes/foo.yaml or include it in an acceptance-options.rb for Beaker,
125
+ or specify TEST_TARGET in a form beaker-hostgenerator accepts, e.g. ubuntu1504-64a.
126
+ You may override the default master test target by specifying MASTER_TEST_TARGET.
127
+ You may set TESTS=path/to/test,and/more/tests.
128
+ You may set additional Beaker OPTIONS='--more --options'
129
+ If there is a Beaker options hash in a ./acceptance/local_options.rb, it will be included.
130
+ Commandline options set through the above environment variables will override settings in this file.
139
131
  EOS
140
132
 
141
133
  desc 'Run specs and check for deprecation warnings'
142
134
  task :spec do
143
- original_dir = Dir.pwd
144
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) )
145
- exit_status = 1
146
- output = ''
147
- Open3.popen3("bundle exec rspec") {|_stdin, stdout, _stderr, wait_thr|
148
- while(line = stdout.gets)
149
- puts line
150
- end
151
- output = stdout.to_s
152
- if not wait_thr.value.success?
153
- fail "Failed to 'bundle exec rspec' (exit status: #{wait_thr.value})"
135
+ Dir.chdir(__dir__) do
136
+ exit_status = 1
137
+ output = ''
138
+ Open3.popen3("bundle exec rspec") do |_stdin, stdout, _stderr, wait_thr|
139
+ while (line = stdout.gets)
140
+ puts line
141
+ end
142
+ output = stdout.to_s
143
+ fail "Failed to 'bundle exec rspec' (exit status: #{wait_thr.value})" if not wait_thr.value.success?
144
+
145
+ exit_status = wait_thr.value
154
146
  end
155
- exit_status = wait_thr.value
156
- }
157
- if exit_status != /0/
158
- #check for deprecation warnings
159
- if output.include?('Deprecation Warnings')
160
- fail "DEPRECATION WARNINGS in spec generation, please fix!"
147
+ if exit_status != /0/
148
+ # check for deprecation warnings
149
+ fail "DEPRECATION WARNINGS in spec generation, please fix!" if output.include?('Deprecation Warnings')
161
150
  end
162
151
  end
163
- Dir.chdir( original_dir )
164
152
  end
165
153
 
166
- desc <<-EOS
167
- Run the base beaker acceptance tests
168
- #{USAGE}
154
+ desc <<~EOS
155
+ Run the base beaker acceptance tests
156
+ #{USAGE}
169
157
  EOS
170
- task :base => 'gen_hosts' do
158
+ task :base => 'gen_hosts' do
171
159
  beaker_test(:base)
172
160
  end
173
161
 
174
- desc <<-EOS
175
- Run the subcommand beaker acceptance tests
176
- #{USAGE}
162
+ desc <<~EOS
163
+ Run the subcommand beaker acceptance tests
164
+ #{USAGE}
177
165
  EOS
178
166
  task :subcommands => 'gen_hosts' do
179
167
  beaker_test(:subcommands)
180
168
  end
181
169
 
182
- desc <<-EOS
183
- Run the hypervisor beaker acceptance tests
184
- #{USAGE}
170
+ desc <<~EOS
171
+ Run the hypervisor beaker acceptance tests
172
+ #{USAGE}
185
173
  EOS
186
- task :hypervisor => 'gen_hosts' do
174
+ task :hypervisor => 'gen_hosts' do
187
175
  beaker_test(:hypervisor)
188
176
  end
189
177
 
190
-
191
178
  desc 'Generate Beaker Host Config File'
192
179
  task :gen_hosts do
193
- if hosts_file_env
194
- next
195
- end
196
- cli = BeakerHostGenerator::CLI.new([test_targets])
180
+ next if hosts_file_env
181
+
182
+ arguments = [test_targets]
183
+ arguments += ['--hypervisor', ENV['BEAKER_HYPERVISOR']] if ENV['BEAKER_HYPERVISOR']
184
+ cli = BeakerHostGenerator::CLI.new(arguments)
197
185
  FileUtils.mkdir_p('tmp') # -p ignores when dir already exists
198
186
  File.open("tmp/#{HOSTS_FILE}", 'w') do |fh|
199
187
  fh.print(cli.execute)
@@ -201,7 +189,6 @@ Run the hypervisor beaker acceptance tests
201
189
  end
202
190
  end
203
191
 
204
-
205
192
  ###########################################################
206
193
  #
207
194
  # History Tasks
@@ -210,16 +197,12 @@ end
210
197
  namespace :history do
211
198
  desc 'Generate HISTORY.md'
212
199
  task :gen do
213
- original_dir = Dir.pwd
214
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) )
215
- output = `bundle exec ruby history.rb .`
216
- puts output
217
- if !output.include?('success')
218
- raise "History generation failed"
200
+ Dir.chdir(__dir__) do
201
+ output = `bundle exec ruby history.rb .`
202
+ puts output
203
+ raise "History generation failed" if !output.include?('success')
219
204
  end
220
- Dir.chdir( original_dir )
221
205
  end
222
-
223
206
  end
224
207
 
225
208
  ###########################################################
@@ -231,62 +214,53 @@ DOCS_DIR = 'yard_docs'
231
214
  DOCS_DAEMON = "yard server --reload --daemon --docroot #{DOCS_DIR}"
232
215
  FOREGROUND_SERVER = "bundle exec yard server --reload --verbose lib/beaker --docroot #{DOCS_DIR}"
233
216
 
234
- def running?( cmdline )
217
+ def running?(cmdline)
235
218
  ps = `ps -ef`
236
- found = ps.lines.grep( /#{Regexp.quote( cmdline )}/ )
237
- if found.length > 1
238
- raise StandardError, "Found multiple YARD Servers. Don't know what to do."
239
- end
219
+ found = ps.lines.grep(/#{Regexp.quote(cmdline)}/)
220
+ raise StandardError, "Found multiple YARD Servers. Don't know what to do." if found.length > 1
240
221
 
241
222
  yes = found.empty? ? false : true
242
223
  return yes, found.first
243
224
  end
244
225
 
245
- def pid_from( output )
226
+ def pid_from(output)
246
227
  output.squeeze(' ').strip.split(' ')[1]
247
228
  end
248
229
 
249
230
  desc 'Start the documentation server in the foreground'
250
231
  task :docs => 'docs:clear' do
251
- original_dir = Dir.pwd
252
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) )
253
- sh FOREGROUND_SERVER
254
- Dir.chdir( original_dir )
232
+ Dir.chdir(__dir__) do
233
+ sh FOREGROUND_SERVER
234
+ end
255
235
  end
256
236
 
257
237
  namespace :docs do
258
-
259
238
  desc 'Clear the generated documentation cache'
260
239
  task :clear do
261
- original_dir = Dir.pwd
262
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) )
263
- sh "rm -rf #{DOCS_DIR}"
264
- Dir.chdir( original_dir )
240
+ Dir.chdir(__dir__) do
241
+ sh "rm -rf #{DOCS_DIR}"
242
+ end
265
243
  end
266
244
 
267
245
  desc 'Generate static documentation'
268
246
  task :gen => 'docs:clear' do
269
- original_dir = Dir.pwd
270
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) )
271
- output = `bundle exec yard doc -o #{DOCS_DIR}`
272
- puts output
273
- if /\[warn\]|\[error\]/.match?(output)
274
- fail "Errors/Warnings during yard documentation generation"
247
+ Dir.chdir(__dir__) do
248
+ output = `bundle exec yard doc -o #{DOCS_DIR}`
249
+ puts output
250
+ fail "Errors/Warnings during yard documentation generation" if /\[warn\]|\[error\]/.match?(output)
275
251
  end
276
- Dir.chdir( original_dir )
277
252
  end
278
253
 
279
254
  desc 'Run the documentation server in the background, alias `bg`'
280
255
  task :background => 'docs:clear' do
281
- yes, output = running?( DOCS_DAEMON )
256
+ yes, output = running?(DOCS_DAEMON)
282
257
  if yes
283
258
  puts "Not starting a new YARD Server..."
284
- puts "Found one running with pid #{pid_from( output )}."
259
+ puts "Found one running with pid #{pid_from(output)}."
285
260
  else
286
- original_dir = Dir.pwd
287
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) )
288
- sh "bundle exec #{DOCS_DAEMON}"
289
- Dir.chdir( original_dir )
261
+ Dir.chdir(__dir__) do
262
+ sh "bundle exec #{DOCS_DAEMON}"
263
+ end
290
264
  end
291
265
  end
292
266
 
@@ -294,9 +268,9 @@ namespace :docs do
294
268
 
295
269
  desc 'Check the status of the documentation server'
296
270
  task :status do
297
- yes, output = running?( DOCS_DAEMON )
271
+ yes, output = running?(DOCS_DAEMON)
298
272
  if yes
299
- pid = pid_from( output )
273
+ pid = pid_from(output)
300
274
  puts "Found a YARD Server running with pid #{pid}"
301
275
  else
302
276
  puts "Could not find a running YARD Server."
@@ -305,16 +279,16 @@ namespace :docs do
305
279
 
306
280
  desc "Stop a running YARD Server"
307
281
  task :stop do
308
- yes, output = running?( DOCS_DAEMON )
282
+ yes, output = running?(DOCS_DAEMON)
309
283
  if yes
310
- pid = pid_from( output )
284
+ pid = pid_from(output)
311
285
  puts "Found a YARD Server running with pid #{pid}"
312
286
  `kill #{pid}`
313
287
  puts "Stopping..."
314
- yes, _output = running?( DOCS_DAEMON )
288
+ yes, _output = running?(DOCS_DAEMON)
315
289
  if yes
316
290
  `kill -9 #{pid}`
317
- yes, _output = running?( DOCS_DAEMON )
291
+ yes, _output = running?(DOCS_DAEMON)
318
292
  if yes
319
293
  puts "Could not Stop Server!"
320
294
  else
@@ -343,3 +317,17 @@ begin
343
317
  rescue LoadError
344
318
  # Optional group in bundler
345
319
  end
320
+
321
+ begin
322
+ require 'rubocop/rake_task'
323
+ rescue LoadError
324
+ # RuboCop is an optional group
325
+ else
326
+ RuboCop::RakeTask.new(:rubocop) do |task|
327
+ # These make the rubocop experience maybe slightly less terrible
328
+ task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
329
+
330
+ # Use Rubocop's Github Actions formatter if possible
331
+ task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
332
+ end
333
+ end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  :load_path => File.join('acceptance', 'lib'),
3
3
  :ssh => {
4
- :keys => ["id_rsa_acceptance", "#{ENV['HOME']}/.ssh/id_rsa-acceptance"],
4
+ :keys => ["id_rsa_acceptance", "#{ENV.fetch('HOME', nil)}/.ssh/id_rsa-acceptance"],
5
5
  },
6
6
  }
@@ -1,3 +1,3 @@
1
1
  {
2
- :tests => 'acceptance/tests/base'
3
- }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
2
+ :tests => 'acceptance/tests/base',
3
+ }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
@@ -1,3 +1,3 @@
1
1
  {
2
- :tests => 'acceptance/tests/hypervisor'
3
- }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
2
+ :tests => 'acceptance/tests/hypervisor',
3
+ }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
@@ -1,4 +1,4 @@
1
1
  {
2
- :pre_suite => 'acceptance/pre_suite/subcommands/',
3
- :tests => 'acceptance/tests/subcommands/'
2
+ :pre_suite => 'acceptance/pre_suite/subcommands/',
3
+ :tests => 'acceptance/tests/subcommands/',
4
4
  }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
@@ -9,7 +9,7 @@ task :validate do
9
9
  Dir['manifests/**/*.pp'].each do |manifest|
10
10
  sh "puppet parser validate --noop #{manifest}"
11
11
  end
12
- Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
12
+ Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
13
13
  sh "ruby -c #{ruby_file}" unless ruby_file.include?('spec/fixtures')
14
14
  end
15
15
  Dir['templates/**/*.erb'].each do |template|
@@ -1,11 +1,10 @@
1
1
  require 'spec_helper_acceptance'
2
2
 
3
3
  describe "my tests" do
4
-
5
4
  # an example using the beaker DSL
6
5
  # use http://www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL
7
6
  it "says hello!" do
8
- result = shell( 'echo hello' )
7
+ result = shell('echo hello')
9
8
  expect(result.stdout).to match(/hello/)
10
9
  end
11
10
 
@@ -16,10 +15,10 @@ describe "my tests" do
16
15
  end
17
16
 
18
17
  it "can create and confirm a file" do
19
- shell( 'rm -f demo.txt' )
18
+ shell('rm -f demo.txt')
20
19
  create_remote_file(default, 'demo.txt', 'foo\nfoo\nfoo\n')
21
- shell( 'grep foo demo.txt' )
22
- shell( 'grep bar demo.txt', :acceptable_exit_codes => [1] )
20
+ shell('grep foo demo.txt')
21
+ shell('grep bar demo.txt', :acceptable_exit_codes => [1])
23
22
  end
24
23
 
25
24
  it "is able to apply manifests" do
@@ -29,9 +28,9 @@ describe "my tests" do
29
28
  ensure => absent,}"
30
29
  manifest_3 = "user {'root':
31
30
  ensure => present,}"
32
- apply_manifest( manifest_1, :expect_changes => true )
33
- apply_manifest( manifest_2, :expect_changes => true )
34
- apply_manifest( manifest_3 )
31
+ apply_manifest(manifest_1, :expect_changes => true)
32
+ apply_manifest(manifest_2, :expect_changes => true)
33
+ apply_manifest(manifest_3)
35
34
  end
36
35
 
37
36
  describe service('sshd') do
@@ -47,9 +46,8 @@ describe "my tests" do
47
46
  end
48
47
 
49
48
  context "can use both serverspec and Beaker DSL" do
50
-
51
49
  it "can create a file" do
52
- shell( 'rm -f /tmp/demo.txt' )
50
+ shell('rm -f /tmp/demo.txt')
53
51
  manifest = "file {'demofile':
54
52
  path => '/tmp/demo.txt',
55
53
  ensure => present,
@@ -64,6 +62,4 @@ describe "my tests" do
64
62
  it { is_expected.to contain 'this is my file.' }
65
63
  end
66
64
  end
67
-
68
-
69
65
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  describe 'demo' do
3
-
4
3
  context 'with defaults for all parameters' do
5
4
  it { is_expected.to contain_class('demo') }
6
5
  end
@@ -3,7 +3,7 @@ require 'beaker-rspec'
3
3
  unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
4
4
  # This will install the latest available package on el and deb based
5
5
  # systems fail on windows and osx, and install via gem on other *nixes
6
- foss_opts = {:default_action => 'gem_install'}
6
+ foss_opts = { :default_action => 'gem_install' }
7
7
 
8
8
  if default.is_pe?; then
9
9
  install_pe;
@@ -12,16 +12,14 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
12
12
  end
13
13
 
14
14
  hosts.each do |host|
15
- unless host.is_pe?
16
- on host, "/bin/echo '' > #{host.puppet('hiera_config')}"
17
- end
15
+ on host, "/bin/echo '' > #{host.puppet('hiera_config')}" unless host.is_pe?
18
16
  on host, "mkdir -p #{host['distmoduledir']}"
19
17
  end
20
18
  end
21
19
 
22
20
  RSpec.configure do |c|
23
21
  # Project root
24
- proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
22
+ proj_root = File.expand_path(File.join(__dir__, '..'))
25
23
 
26
24
  # Readable test descriptions
27
25
  c.formatter = :documentation
@@ -11,7 +11,7 @@ end
11
11
  # Returns the absolute path where file fixtures are located.
12
12
  def fixture_path
13
13
  @fixture_path ||=
14
- File.expand_path(File.join(__FILE__, '..', '..', '..', 'fixtures', 'files'))
14
+ File.expand_path(File.join(__dir__, '..', '..', 'fixtures', 'files'))
15
15
  end
16
16
 
17
17
  # Returns the contents of a named fixture file, to be found in `fixture_path`.
@@ -27,7 +27,7 @@ def create_remote_file_from_fixture(fixture, host, remote_path, filename)
27
27
  full_filename = File.join(remote_path, filename)
28
28
  contents = fixture_contents fixture
29
29
  create_remote_file host, full_filename, contents
30
- [ full_filename, contents ]
30
+ [full_filename, contents]
31
31
  end
32
32
 
33
33
  # Create a file locally, in the `local_path`, with file name `filename`,
@@ -43,7 +43,7 @@ def create_local_file_from_fixture(fixture, local_path, filename, perms = nil)
43
43
  end
44
44
  FileUtils.chmod perms, full_filename if perms
45
45
 
46
- [ full_filename, contents ]
46
+ [full_filename, contents]
47
47
  end
48
48
 
49
49
  # Provide debugging information for tests which are known to fail intermittently
@@ -68,6 +68,7 @@ end
68
68
  def fails_intermittently(issue_link, args = {})
69
69
  raise ArgumentError, "provide a Jira ticket link" unless issue_link
70
70
  raise ArgumentError, "a block is required" unless block_given?
71
+
71
72
  yield
72
73
  rescue MiniTest::Assertion, StandardError, SignalException # we have a test failure!
73
74
  STDERR.puts "\n\nIntermittent test failure! See: #{issue_link}"
@@ -1,13 +1,12 @@
1
- ruby_version, ruby_source = ENV['RUBY_VER'], "job parameter"
1
+ ruby_version, ruby_source = ENV.fetch('RUBY_VER', nil), "job parameter"
2
2
  unless ruby_version
3
3
  ruby_version = "2.4.1"
4
4
  ruby_source = "default"
5
5
  end
6
6
  test_name "Install and configure Ruby #{ruby_version} (from #{ruby_source}) on the SUT" do
7
-
8
7
  step 'Ensure that the default system is an el-based system' do
9
8
  # The pre-suite currently only supports el systems, and we should
10
- #fail early if the default platform is not a supported platform
9
+ # fail early if the default platform is not a supported platform
11
10
  assert(default.platform.variant == 'el',
12
11
  "Expected the platform variant to be 'el', not #{default.platform.variant}")
13
12
  end
@@ -1,7 +1,6 @@
1
1
  test_name 'Install beaker and checkout branch if necessary' do
2
-
3
2
  step 'Download the beaker git repo' do
4
- on default, 'git clone https://github.com/puppetlabs/beaker.git /opt/beaker/'
3
+ on default, 'git clone https://github.com/puppetlabs/beaker.git /opt/beaker/'
5
4
  end
6
5
 
7
6
  step 'Detect if checking out branch for testing and checkout' do
@@ -1,17 +1,17 @@
1
- $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib'))
1
+ $LOAD_PATH << File.expand_path(File.join(__dir__, '..', '..', '..', '..', 'lib'))
2
2
 
3
3
  require 'helpers/test_helper'
4
4
 
5
5
  test_name "dsl::helpers::host_helpers test configuration validation" do
6
6
  step "Validate hosts configuration" do
7
7
  assert (hosts.size > 1),
8
- "dsl::helpers::host_helpers acceptance tests require at least two hosts"
8
+ "dsl::helpers::host_helpers acceptance tests require at least two hosts"
9
9
 
10
10
  agents = select_hosts(:roles => "agent")
11
11
  assert (agents.size > 1),
12
- "dsl::helpers::host_helpers acceptance tests require at least two hosts with the :agent role"
12
+ "dsl::helpers::host_helpers acceptance tests require at least two hosts with the :agent role"
13
13
 
14
14
  assert default,
15
- "dsl::helpers::host_helpers acceptance tests require a default host"
15
+ "dsl::helpers::host_helpers acceptance tests require a default host"
16
16
  end
17
17
  end
@@ -1,7 +1,6 @@
1
1
  require 'hocon/config_value_factory'
2
2
 
3
3
  test_name 'Hocon Helpers Test' do
4
-
5
4
  hocon_filename = 'hocon.conf'
6
5
  step 'setup : create hocon file to play with' do
7
6
  hocon_content = <<-END
@@ -91,4 +90,4 @@ test_name 'Hocon Helpers Test' do
91
90
  end
92
91
  end
93
92
  end
94
- end
93
+ end
@@ -1,9 +1,7 @@
1
1
  require "helpers/test_helper"
2
2
 
3
3
  test_name "dsl::helpers::host_helpers #add_system32_hosts_entry" do
4
-
5
4
  confine_block :to, :platform => /windows/ do
6
-
7
5
  step "#add_system32_hosts_entry fails when run on a non-powershell platform" do
8
6
  # NOTE: would expect this to be better documented.
9
7
  if default.is_powershell?
@@ -36,7 +34,6 @@ test_name "dsl::helpers::host_helpers #add_system32_hosts_entry" do
36
34
  end
37
35
 
38
36
  confine_block :except, :platform => /windows/ do
39
-
40
37
  step "#add_system32_hosts_entry CURRENTLY fails with RuntimeError when run on a non-windows platform" do
41
38
  # NOTE: would expect this to behave the same way it does on a windows
42
39
  # non-powershell platform (raises Beaker::Host::CommandFailure), or
@@ -1,7 +1,6 @@
1
1
  require "helpers/test_helper"
2
2
 
3
3
  test_name "dsl::helpers::host_helpers #archive_file_from" do
4
-
5
4
  step "archiveroot parameter defaults to `archive/sut-files`" do
6
5
  # Create a remote file to archive
7
6
  filepath = default.tmpfile('archive-file-test')
@@ -20,6 +19,9 @@ test_name "dsl::helpers::host_helpers #archive_file_from" do
20
19
  end
21
20
 
22
21
  step "fails archive_file_from when from_path is non-existant" do
22
+ # beaker-docker can't deal with closing the connection
23
+ confine :except, :hypervisor => 'docker'
24
+
23
25
  filepath = "foo-filepath-should-not-exist"
24
26
  assert_raises IOError do
25
27
  archive_file_from(default, filepath)