beaker 4.41.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 (218) 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 -52
  8. data/Gemfile +12 -7
  9. data/HISTORY.md +605 -0
  10. data/Rakefile +99 -111
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Rakefile +1 -1
  16. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  17. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  18. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  19. data/acceptance/lib/helpers/test_helper.rb +6 -5
  20. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  21. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  22. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  23. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  41. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  42. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  43. data/acceptance/tests/base/host/file_test.rb +2 -2
  44. data/acceptance/tests/base/host/group_test.rb +0 -1
  45. data/acceptance/tests/base/host/host_test.rb +66 -63
  46. data/acceptance/tests/base/host/packages.rb +1 -2
  47. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  48. data/acceptance/tests/base/host/user_test.rb +0 -1
  49. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  50. data/acceptance/tests/base/test_suite/export.rb +6 -9
  51. data/acceptance/tests/install/from_file.rb +2 -4
  52. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  53. data/acceptance/tests/subcommands/destroy.rb +19 -21
  54. data/acceptance/tests/subcommands/exec.rb +0 -1
  55. data/acceptance/tests/subcommands/init.rb +2 -3
  56. data/acceptance/tests/subcommands/provision.rb +0 -1
  57. data/beaker.gemspec +4 -7
  58. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  59. data/docs/how_to/debug_beaker_tests.md +12 -12
  60. data/docs/how_to/hosts/eos.md +2 -12
  61. data/docs/how_to/install_puppet.md +0 -18
  62. data/docs/how_to/the_beaker_dsl.md +0 -2
  63. data/lib/beaker/cli.rb +59 -68
  64. data/lib/beaker/command.rb +20 -28
  65. data/lib/beaker/command_factory.rb +3 -2
  66. data/lib/beaker/dsl/assertions.rb +6 -18
  67. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  68. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  69. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  70. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  71. data/lib/beaker/dsl/helpers.rb +2 -4
  72. data/lib/beaker/dsl/outcomes.rb +13 -15
  73. data/lib/beaker/dsl/patterns.rb +1 -3
  74. data/lib/beaker/dsl/roles.rb +17 -20
  75. data/lib/beaker/dsl/structure.rb +53 -65
  76. data/lib/beaker/dsl/test_tagging.rb +7 -10
  77. data/lib/beaker/dsl/wrappers.rb +15 -16
  78. data/lib/beaker/dsl.rb +2 -3
  79. data/lib/beaker/host/aix/exec.rb +1 -1
  80. data/lib/beaker/host/aix/file.rb +0 -1
  81. data/lib/beaker/host/aix/group.rb +1 -1
  82. data/lib/beaker/host/aix/user.rb +1 -1
  83. data/lib/beaker/host/aix.rb +3 -4
  84. data/lib/beaker/host/cisco.rb +27 -39
  85. data/lib/beaker/host/eos.rb +4 -30
  86. data/lib/beaker/host/freebsd/exec.rb +1 -1
  87. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  88. data/lib/beaker/host/freebsd.rb +9 -12
  89. data/lib/beaker/host/mac/exec.rb +4 -4
  90. data/lib/beaker/host/mac/group.rb +7 -7
  91. data/lib/beaker/host/mac/pkg.rb +3 -106
  92. data/lib/beaker/host/mac/user.rb +2 -2
  93. data/lib/beaker/host/mac.rb +8 -9
  94. data/lib/beaker/host/pswindows/exec.rb +66 -70
  95. data/lib/beaker/host/pswindows/file.rb +3 -5
  96. data/lib/beaker/host/pswindows/group.rb +3 -3
  97. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  98. data/lib/beaker/host/pswindows/user.rb +3 -3
  99. data/lib/beaker/host/pswindows.rb +4 -3
  100. data/lib/beaker/host/unix/exec.rb +81 -83
  101. data/lib/beaker/host/unix/file.rb +40 -45
  102. data/lib/beaker/host/unix/group.rb +1 -1
  103. data/lib/beaker/host/unix/pkg.rb +138 -401
  104. data/lib/beaker/host/unix/user.rb +2 -2
  105. data/lib/beaker/host/unix.rb +8 -11
  106. data/lib/beaker/host/windows/exec.rb +17 -17
  107. data/lib/beaker/host/windows/file.rb +3 -3
  108. data/lib/beaker/host/windows/group.rb +3 -3
  109. data/lib/beaker/host/windows/pkg.rb +3 -54
  110. data/lib/beaker/host/windows/user.rb +3 -3
  111. data/lib/beaker/host/windows.rb +12 -12
  112. data/lib/beaker/host.rb +76 -133
  113. data/lib/beaker/host_prebuilt_steps.rb +88 -196
  114. data/lib/beaker/hypervisor/noop.rb +2 -4
  115. data/lib/beaker/hypervisor.rb +44 -61
  116. data/lib/beaker/local_connection.rb +2 -4
  117. data/lib/beaker/logger.rb +68 -76
  118. data/lib/beaker/logger_junit.rb +21 -25
  119. data/lib/beaker/network_manager.rb +39 -42
  120. data/lib/beaker/options/command_line_parser.rb +12 -23
  121. data/lib/beaker/options/hosts_file_parser.rb +16 -25
  122. data/lib/beaker/options/options_file_parser.rb +3 -6
  123. data/lib/beaker/options/options_hash.rb +2 -7
  124. data/lib/beaker/options/parser.rb +86 -102
  125. data/lib/beaker/options/presets.rb +114 -123
  126. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  127. data/lib/beaker/options/validator.rb +26 -31
  128. data/lib/beaker/perf.rb +25 -30
  129. data/lib/beaker/platform.rb +26 -37
  130. data/lib/beaker/result.rb +7 -6
  131. data/lib/beaker/shared/error_handler.rb +8 -10
  132. data/lib/beaker/shared/fog_credentials.rb +5 -9
  133. data/lib/beaker/shared/host_manager.rb +36 -41
  134. data/lib/beaker/shared/options_resolver.rb +3 -7
  135. data/lib/beaker/shared/repetition.rb +2 -4
  136. data/lib/beaker/shared/semvar.rb +37 -41
  137. data/lib/beaker/shared/timed.rb +0 -3
  138. data/lib/beaker/shared.rb +1 -1
  139. data/lib/beaker/ssh_connection.rb +38 -47
  140. data/lib/beaker/subcommand.rb +17 -24
  141. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  142. data/lib/beaker/tasks/quick_start.rb +4 -9
  143. data/lib/beaker/tasks/rake_task.rb +25 -27
  144. data/lib/beaker/tasks/test.rb +4 -4
  145. data/lib/beaker/test_case.rb +16 -28
  146. data/lib/beaker/test_suite.rb +35 -39
  147. data/lib/beaker/test_suite_result.rb +45 -47
  148. data/lib/beaker/version.rb +1 -1
  149. data/lib/beaker.rb +6 -7
  150. data/spec/beaker/cli_spec.rb +121 -142
  151. data/spec/beaker/command_spec.rb +55 -59
  152. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  153. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  154. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  155. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  156. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  157. data/spec/beaker/dsl/roles_spec.rb +125 -130
  158. data/spec/beaker/dsl/structure_spec.rb +172 -161
  159. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  160. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  161. data/spec/beaker/host/aix_spec.rb +14 -14
  162. data/spec/beaker/host/cisco_spec.rb +84 -94
  163. data/spec/beaker/host/eos_spec.rb +15 -36
  164. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  165. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  166. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  167. data/spec/beaker/host/mac/group_spec.rb +48 -57
  168. data/spec/beaker/host/mac/user_spec.rb +54 -63
  169. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  170. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  171. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  172. data/spec/beaker/host/pswindows_spec.rb +13 -13
  173. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  174. data/spec/beaker/host/unix/file_spec.rb +66 -71
  175. data/spec/beaker/host/unix/pkg_spec.rb +150 -411
  176. data/spec/beaker/host/unix_spec.rb +11 -207
  177. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  178. data/spec/beaker/host/windows/file_spec.rb +18 -19
  179. data/spec/beaker/host/windows/group_spec.rb +10 -12
  180. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  181. data/spec/beaker/host/windows/user_spec.rb +17 -23
  182. data/spec/beaker/host/windows_spec.rb +39 -39
  183. data/spec/beaker/host_prebuilt_steps_spec.rb +168 -349
  184. data/spec/beaker/host_spec.rb +204 -284
  185. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  186. data/spec/beaker/localhost_connection_spec.rb +10 -11
  187. data/spec/beaker/logger_junit_spec.rb +19 -30
  188. data/spec/beaker/logger_spec.rb +153 -136
  189. data/spec/beaker/network_manager_spec.rb +23 -23
  190. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  191. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  192. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  193. data/spec/beaker/options/options_hash_spec.rb +4 -6
  194. data/spec/beaker/options/parser_spec.rb +167 -167
  195. data/spec/beaker/options/presets_spec.rb +7 -9
  196. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  197. data/spec/beaker/options/validator_spec.rb +10 -11
  198. data/spec/beaker/perf_spec.rb +18 -21
  199. data/spec/beaker/platform_spec.rb +25 -50
  200. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  201. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  202. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  203. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  204. data/spec/beaker/shared/repetition_spec.rb +17 -24
  205. data/spec/beaker/shared/semvar_spec.rb +21 -26
  206. data/spec/beaker/ssh_connection_spec.rb +76 -83
  207. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  208. data/spec/beaker/subcommand_spec.rb +75 -77
  209. data/spec/beaker/test_case_spec.rb +25 -50
  210. data/spec/beaker/test_suite_spec.rb +147 -154
  211. data/spec/helpers.rb +39 -45
  212. data/spec/matchers.rb +8 -7
  213. data/spec/mocks.rb +1 -6
  214. data/spec/spec_helper.rb +0 -1
  215. metadata +8 -24
  216. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  217. data/acceptance/tests/base/external_resources_test.rb +0 -31
  218. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -2,18 +2,18 @@ require 'yaml'
2
2
 
3
3
  module Beaker
4
4
  module Options
5
- #An Object that parses, merges and normalizes all supported Beaker options and arguments
5
+ # An Object that parses, merges and normalizes all supported Beaker options and arguments
6
6
  class Parser
7
7
  GITREPO = 'git://github.com/puppetlabs'
8
- #These options can have the form of arg1,arg2 or [arg] or just arg,
9
- #should default to []
10
- LONG_OPTS = [:helper, :load_path, :tests, :pre_suite, :post_suite, :install, :pre_cleanup, :modules]
11
- #These options expand out into an array of .rb files
12
- RB_FILE_OPTS = [:tests, :pre_suite, :post_suite, :pre_cleanup]
8
+ # These options can have the form of arg1,arg2 or [arg] or just arg,
9
+ # should default to []
10
+ LONG_OPTS = %i[helper load_path tests pre_suite post_suite install pre_cleanup modules]
11
+ # These options expand out into an array of .rb files
12
+ RB_FILE_OPTS = %i[tests pre_suite post_suite pre_cleanup]
13
13
 
14
14
  PARSE_ERROR = Psych::SyntaxError
15
15
 
16
- #The OptionsHash of all parsed options
16
+ # The OptionsHash of all parsed options
17
17
  attr_accessor :options
18
18
  attr_reader :attribution
19
19
 
@@ -68,10 +68,10 @@ module Beaker
68
68
  path_files = []
69
69
  if File.file?(root)
70
70
  path_files << root
71
- elsif File.directory?(root) #expand and explore
71
+ elsif File.directory?(root) # expand and explore
72
72
  path_files = Dir.glob(File.join(root, '**/*.rb'))
73
- .select { |f| File.file?(f) }
74
- .sort_by { |file| [file.count('/'), file] }
73
+ .select { |f| File.file?(f) }
74
+ .sort_by { |file| [file.count('/'), file] }
75
75
  end
76
76
 
77
77
  @validator.validate_files(path_files, root)
@@ -91,51 +91,51 @@ module Beaker
91
91
  # @return nil
92
92
  # @api public
93
93
  def resolve_symlinks!
94
- if @options[:hosts_file] && !@options[:hosts_file_generated]
95
- @options[:hosts_file] = File.realpath(@options[:hosts_file])
96
- end
94
+ return unless @options[:hosts_file] && !@options[:hosts_file_generated]
95
+
96
+ @options[:hosts_file] = File.realpath(@options[:hosts_file])
97
97
  end
98
98
 
99
- #Converts array of paths into array of fully qualified git repo URLS with expanded keywords
99
+ # Converts array of paths into array of fully qualified git repo URLS with expanded keywords
100
100
  #
101
- #Supports the following keywords
101
+ # Supports the following keywords
102
102
  # PUPPET
103
103
  # FACTER
104
104
  # HIERA
105
105
  # HIERA-PUPPET
106
- #@example
106
+ # @example
107
107
  # opts = ["PUPPET/3.1"]
108
108
  # parse_git_repos(opts) == ["#{GITREPO}/puppet.git#3.1"]
109
- #@param [Array] git_opts An array of paths
110
- #@return [Array] An array of fully qualified git repo URLs with expanded keywords
109
+ # @param [Array] git_opts An array of paths
110
+ # @return [Array] An array of fully qualified git repo URLs with expanded keywords
111
111
  def parse_git_repos(git_opts)
112
- git_opts.map! { |opt|
112
+ git_opts.map! do |opt|
113
113
  case opt
114
- when /^PUPPET\//
115
- opt = "#{repo}/puppet.git##{opt.split('/', 2)[1]}"
116
- when /^FACTER\//
117
- opt = "#{repo}/facter.git##{opt.split('/', 2)[1]}"
118
- when /^HIERA\//
119
- opt = "#{repo}/hiera.git##{opt.split('/', 2)[1]}"
120
- when /^HIERA-PUPPET\//
121
- opt = "#{repo}/hiera-puppet.git##{opt.split('/', 2)[1]}"
114
+ when /^PUPPET\//
115
+ opt = "#{repo}/puppet.git##{opt.split('/', 2)[1]}"
116
+ when /^FACTER\//
117
+ opt = "#{repo}/facter.git##{opt.split('/', 2)[1]}"
118
+ when /^HIERA\//
119
+ opt = "#{repo}/hiera.git##{opt.split('/', 2)[1]}"
120
+ when /^HIERA-PUPPET\//
121
+ opt = "#{repo}/hiera-puppet.git##{opt.split('/', 2)[1]}"
122
122
  end
123
123
  opt
124
- }
124
+ end
125
125
  git_opts
126
126
  end
127
127
 
128
- #Add the 'default' role to the host determined to be the default. If a host already has the role default then
129
- #do nothing. If more than a single host has the role 'default', raise error.
130
- #Default host determined to be 1) the only host in a single host configuration, 2) the host with the role 'master'
131
- #defined.
132
- #@param [Hash] hosts A hash of hosts, each identified by a String name. Each named host will have an Array of roles
128
+ # Add the 'default' role to the host determined to be the default. If a host already has the role default then
129
+ # do nothing. If more than a single host has the role 'default', raise error.
130
+ # Default host determined to be 1) the only host in a single host configuration, 2) the host with the role 'master'
131
+ # defined.
132
+ # @param [Hash] hosts A hash of hosts, each identified by a String name. Each named host will have an Array of roles
133
133
  def set_default_host!(hosts)
134
134
  default = []
135
135
  master = []
136
136
  default_host_name = nil
137
137
 
138
- #look through the hosts and find any hosts with role 'default' and any hosts with role 'master'
138
+ # look through the hosts and find any hosts with role 'default' and any hosts with role 'master'
139
139
  hosts.each_key do |name|
140
140
  host = hosts[name]
141
141
  if host[:roles].include?('default')
@@ -147,20 +147,20 @@ module Beaker
147
147
 
148
148
  # default_set? will throw an error if length > 1
149
149
  # and return false if no default is set.
150
- if !@validator.default_set?(default)
151
- #no default set, let's make one
152
- if not master.empty? and master.length == 1
153
- default_host_name = master[0]
154
- elsif hosts.length == 1
155
- default_host_name = hosts.keys[0]
156
- end
157
- if default_host_name
158
- hosts[default_host_name][:roles] << 'default'
159
- end
150
+ return if @validator.default_set?(default)
151
+
152
+ # no default set, let's make one
153
+ if not master.empty? and master.length == 1
154
+ default_host_name = master[0]
155
+ elsif hosts.length == 1
156
+ default_host_name = hosts.keys[0]
160
157
  end
158
+ return unless default_host_name
159
+
160
+ hosts[default_host_name][:roles] << 'default'
161
161
  end
162
162
 
163
- #Constructor for Parser
163
+ # Constructor for Parser
164
164
  #
165
165
  def initialize
166
166
  @command_line_parser = Beaker::Options::CommandLineParser.new
@@ -177,16 +177,16 @@ module Beaker
177
177
  def tag_sources(options_hash, source)
178
178
  hash = Beaker::Options::OptionsHash.new
179
179
  options_hash.each do |key, value|
180
- if value.is_a?(Hash)
181
- hash[key] = tag_sources(value, source)
182
- else
183
- hash[key] = source
184
- end
180
+ hash[key] = if value.is_a?(Hash)
181
+ tag_sources(value, source)
182
+ else
183
+ source
184
+ end
185
185
  end
186
186
  hash
187
187
  end
188
188
 
189
- # Update the @option hash with a value and the @attribution hash with a source
189
+ #  Update the @option hash with a value and the @attribution hash with a source
190
190
  #
191
191
  # @param [String] key The key to update in both hashes
192
192
  # @param [Object] value The value to set in the @options hash
@@ -212,7 +212,7 @@ module Beaker
212
212
  # @param [Array] args ARGV or a provided arguments array
213
213
  # @raise [ArgumentError] Raises error on bad input
214
214
  def parse_args(args = ARGV)
215
- @options = @presets.presets
215
+ @options = @presets.presets
216
216
  @attribution = @attribution.merge(tag_sources(@presets.presets, "preset"))
217
217
  cmd_line_options = @command_line_parser.parse(args)
218
218
  cmd_line_options[:command_line] = ([$0] + args).join(' ')
@@ -224,7 +224,7 @@ module Beaker
224
224
  subcommand_options_file = Beaker::Subcommands::SubcommandUtil::SUBCOMMAND_OPTIONS
225
225
  {
226
226
  "project" => ".beaker.yml",
227
- "homedir" => "#{ENV['HOME']}/#{subcommand_options_file}",
227
+ "homedir" => "#{ENV.fetch('HOME', nil)}/#{subcommand_options_file}",
228
228
  "subcommand" => subcommand_options_file,
229
229
  }.each_pair do |src, path|
230
230
  opts = if src == "project"
@@ -236,7 +236,7 @@ module Beaker
236
236
  @options.merge!(opts)
237
237
  end
238
238
 
239
- file_options = Beaker::Options::OptionsFileParser.parse_options_file(cmd_line_options[:options_file] || options[:options_file])
239
+ file_options = Beaker::Options::OptionsFileParser.parse_options_file(cmd_line_options[:options_file] || options[:options_file])
240
240
  @attribution = @attribution.merge(tag_sources(file_options, "options_file"))
241
241
 
242
242
  # merge together command line and file_options
@@ -252,17 +252,17 @@ module Beaker
252
252
 
253
253
  # merge in host file vars
254
254
  # overwrite options (default, file options, command line) with host file options
255
- @options = @options.merge(hosts_options)
255
+ @options = @options.merge(hosts_options)
256
256
  @attribution = @attribution.merge(tag_sources(hosts_options, "host_file"))
257
257
 
258
258
  # re-merge the command line options
259
259
  # overwrite options (default, file options, hosts file ) with command line arguments
260
- @options = @options.merge(cmd_line_options)
260
+ @options = @options.merge(cmd_line_options)
261
261
  @attribution = @attribution.merge(tag_sources(cmd_line_options, "cmd"))
262
262
 
263
263
  # merge in env vars
264
264
  # overwrite options (default, file options, command line, hosts file) with env
265
- env_vars = @presets.env_vars
265
+ env_vars = @presets.env_vars
266
266
 
267
267
  @options = @options.merge(env_vars)
268
268
  @attribution = @attribution.merge(tag_sources(env_vars, "env"))
@@ -282,7 +282,7 @@ module Beaker
282
282
  # be read by the HostsFileParser
283
283
  def parse_hosts_options
284
284
  if @options[:hosts_file].nil? || File.exist?(@options[:hosts_file])
285
- #read the hosts file that contains the node configuration and hypervisor info
285
+ # read the hosts file that contains the node configuration and hypervisor info
286
286
  return Beaker::Options::HostsFileParser.parse_hosts_file(@options[:hosts_file])
287
287
  end
288
288
 
@@ -291,14 +291,13 @@ module Beaker
291
291
  $stdout.puts dne_message
292
292
  require 'beaker-hostgenerator'
293
293
 
294
- host_generator_options = [ @options[:hosts_file] ]
295
- host_generator_options += [ '--hypervisor', ENV['BEAKER_HYPERVISOR'] ] if ENV['BEAKER_HYPERVISOR']
294
+ host_generator_options = [@options[:hosts_file]]
295
+ host_generator_options += ['--hypervisor', ENV['BEAKER_HYPERVISOR']] if ENV['BEAKER_HYPERVISOR']
296
296
 
297
297
  hosts_file_content = begin
298
298
  bhg_cli = BeakerHostGenerator::CLI.new(host_generator_options)
299
299
  bhg_cli.execute
300
- rescue BeakerHostGenerator::Exceptions::Error,
301
- BeakerHostGenerator::Exceptions::InvalidNodeSpecError => e
300
+ rescue BeakerHostGenerator::Exceptions::Error => e
302
301
  error_message = "\nbeaker-hostgenerator was not able to use this value as input."
303
302
  error_message << "\nExiting with an Error.\n\n"
304
303
  $stderr.puts error_message
@@ -306,12 +305,12 @@ module Beaker
306
305
  end
307
306
 
308
307
  @options[:hosts_file_generated] = true
309
- Beaker::Options::HostsFileParser.parse_hosts_string( hosts_file_content )
308
+ Beaker::Options::HostsFileParser.parse_hosts_string(hosts_file_content)
310
309
  end
311
310
 
312
- #Validate all merged options values for correctness
311
+ # Validate all merged options values for correctness
313
312
  #
314
- #Currently checks:
313
+ # Currently checks:
315
314
  # - each host has a valid platform
316
315
  # - if a keyfile is provided then use it
317
316
  # - paths provided to --test, --pre-suite, --post-suite provided lists of .rb files for testing
@@ -323,30 +322,23 @@ module Beaker
323
322
  # - sets the default host based upon machine definitions
324
323
  # - if an ssh user has been defined make it the host user
325
324
  #
326
- #@raise [ArgumentError] Raise if argument/options values are invalid
325
+ # @raise [ArgumentError] Raise if argument/options values are invalid
327
326
  def normalize_args
328
-
329
327
  @options['HOSTS'].each_key do |name|
330
328
  @validator.validate_platform(@options['HOSTS'][name], name)
331
329
  @options['HOSTS'][name]['platform'] = Platform.new(@options['HOSTS'][name]['platform'])
332
330
  end
333
331
 
334
- #use the keyfile if present
335
- if @options.has_key?(:keyfile)
336
- @options[:ssh][:keys] = [@options[:keyfile]]
337
- end
332
+ # use the keyfile if present
333
+ @options[:ssh][:keys] = [@options[:keyfile]] if @options.has_key?(:keyfile)
338
334
 
339
- #split out arguments - these arguments can have the form of arg1,arg2 or [arg] or just arg
340
- #will end up being normalized into an array
335
+ # split out arguments - these arguments can have the form of arg1,arg2 or [arg] or just arg
336
+ # will end up being normalized into an array
341
337
  LONG_OPTS.each do |opt|
342
338
  if @options.has_key?(opt)
343
339
  update_option(opt, split_arg(@options[opt]), 'runtime')
344
- if RB_FILE_OPTS.include?(opt) && (not @options[opt] == [])
345
- update_option(opt, file_list(@options[opt]), 'runtime')
346
- end
347
- if opt == :install
348
- update_option(:install, parse_git_repos(@options[:install]), 'runtime')
349
- end
340
+ update_option(opt, file_list(@options[opt]), 'runtime') if RB_FILE_OPTS.include?(opt) && (not @options[opt] == [])
341
+ update_option(:install, parse_git_repos(@options[:install]), 'runtime') if opt == :install
350
342
  else
351
343
  update_option(opt, [], 'runtime')
352
344
  end
@@ -355,13 +347,13 @@ module Beaker
355
347
  @validator.validate_fail_mode(@options[:fail_mode])
356
348
  @validator.validate_preserve_hosts(@options[:preserve_hosts])
357
349
 
358
- #check for config files necessary for different hypervisors
350
+ # check for config files necessary for different hypervisors
359
351
  hypervisors = get_hypervisors(@options[:HOSTS])
360
352
  hypervisors.each do |visor|
361
353
  check_hypervisor_config(visor)
362
354
  end
363
355
 
364
- #check that roles of hosts make sense
356
+ # check that roles of hosts make sense
365
357
  # - must be one and only one master
366
358
  master = 0
367
359
  roles = get_roles(@options[:HOSTS])
@@ -372,17 +364,13 @@ module Beaker
372
364
 
373
365
  @validator.validate_master_count(master)
374
366
 
375
- #check that windows/el-4 boxes are only agents (solaris can be a master in foss cases)
367
+ # check that windows/el-4 boxes are only agents (solaris can be a master in foss cases)
376
368
  @options[:HOSTS].each_key do |name|
377
369
  host = @options[:HOSTS][name]
378
- if /windows|el-4/.match?(host[:platform])
379
- test_host_roles(name, host)
380
- end
370
+ test_host_roles(name, host) if /windows|el-4/.match?(host[:platform])
381
371
 
382
- #check to see if a custom user account has been provided, if so use it
383
- if host[:ssh] && host[:ssh][:user]
384
- host[:user] = host[:ssh][:user]
385
- end
372
+ # check to see if a custom user account has been provided, if so use it
373
+ host[:user] = host[:ssh][:user] if host[:ssh] && host[:ssh][:user]
386
374
 
387
375
  # merge host tags for this host with the global/preset host tags
388
376
  host[:host_tags] = @options[:host_tags].merge(host[:host_tags] || {})
@@ -392,13 +380,12 @@ module Beaker
392
380
  @validator.validate_test_tags(
393
381
  @options[:test_tag_and],
394
382
  @options[:test_tag_or],
395
- @options[:test_tag_exclude]
383
+ @options[:test_tag_exclude],
396
384
  )
397
385
  resolve_symlinks!
398
386
 
399
- #set the default role
387
+ # set the default role
400
388
  set_default_host!(@options[:HOSTS])
401
-
402
389
  end
403
390
 
404
391
  # Get an array containing lists of roles by parsing each host in hosts.
@@ -429,13 +416,11 @@ module Beaker
429
416
  # @return [nil] no return
430
417
  # @raise [ArgumentError] Raises error if config file does not exist or is not valid YAML
431
418
  def check_hypervisor_config(visor)
432
- if ['blimpy'].include?(visor)
433
- @validator.check_yaml_file(@options[:ec2_yaml], "required by #{visor}")
434
- end
419
+ @validator.check_yaml_file(@options[:ec2_yaml], "required by #{visor}") if ['blimpy'].include?(visor)
435
420
 
436
- if %w(aix solaris vcloud).include?(visor)
437
- @validator.check_yaml_file(@options[:dot_fog], "required by #{visor}")
438
- end
421
+ return unless %w(aix solaris vcloud).include?(visor)
422
+
423
+ @validator.check_yaml_file(@options[:dot_fog], "required by #{visor}")
439
424
  end
440
425
 
441
426
  # Normalize include and exclude tags. This modifies @options.
@@ -460,11 +445,10 @@ module Beaker
460
445
  def test_host_roles(host_name, host_hash)
461
446
  exclude_roles = %w(master database dashboard)
462
447
  host_roles = host_hash[:roles]
463
- unless (host_roles & exclude_roles).empty?
464
- @validator.parser_error "#{host_hash[:platform]} box '#{host_name}' may not have roles: #{exclude_roles.join(', ')}."
465
- end
466
- end
448
+ return if (host_roles & exclude_roles).empty?
467
449
 
450
+ @validator.parser_error "#{host_hash[:platform]} box '#{host_name}' may not have roles: #{exclude_roles.join(', ')}."
451
+ end
468
452
  end
469
453
  end
470
454
  end