beaker-puppet 1.29.0 → 3.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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +3 -3
  4. data/.github/workflows/test.yml +28 -7
  5. data/.github_changelog_generator +3 -0
  6. data/.rubocop.yml +5 -0
  7. data/.rubocop_todo.yml +887 -0
  8. data/CHANGELOG.md +50 -0
  9. data/CODEOWNERS +1 -0
  10. data/Gemfile +5 -20
  11. data/README.md +4 -13
  12. data/Rakefile +64 -169
  13. data/acceptance/config/acceptance-options.rb +3 -3
  14. data/acceptance/config/gem/acceptance-options.rb +8 -8
  15. data/acceptance/config/git/acceptance-options.rb +8 -8
  16. data/acceptance/config/pkg/acceptance-options.rb +7 -7
  17. data/acceptance/pre_suite/gem/install.rb +6 -6
  18. data/acceptance/pre_suite/git/install.rb +22 -22
  19. data/acceptance/pre_suite/pkg/install.rb +3 -3
  20. data/acceptance/tests/backwards_compatible.rb +6 -7
  21. data/acceptance/tests/clone_git_repo_on_test.rb +12 -13
  22. data/acceptance/tests/create_tmpdir_on_test.rb +13 -9
  23. data/acceptance/tests/install_smoke_test.rb +5 -4
  24. data/acceptance/tests/stub_host.rb +11 -10
  25. data/acceptance/tests/web_helpers_test.rb +11 -10
  26. data/beaker-puppet.gemspec +17 -24
  27. data/bin/beaker-puppet +2 -4
  28. data/lib/beaker-puppet/helpers/facter_helpers.rb +9 -7
  29. data/lib/beaker-puppet/helpers/host_helpers.rb +10 -7
  30. data/lib/beaker-puppet/helpers/puppet_helpers.rb +145 -229
  31. data/lib/beaker-puppet/helpers/rake_helpers.rb +1 -1
  32. data/lib/beaker-puppet/helpers/tk_helpers.rb +22 -28
  33. data/lib/beaker-puppet/install_utils/aio_defaults.rb +39 -43
  34. data/lib/beaker-puppet/install_utils/ezbake_utils.rb +34 -42
  35. data/lib/beaker-puppet/install_utils/foss_defaults.rb +134 -138
  36. data/lib/beaker-puppet/install_utils/foss_utils.rb +269 -480
  37. data/lib/beaker-puppet/install_utils/module_utils.rb +58 -70
  38. data/lib/beaker-puppet/install_utils/puppet5.rb +30 -35
  39. data/lib/beaker-puppet/install_utils/puppet_utils.rb +53 -80
  40. data/lib/beaker-puppet/install_utils/windows_utils.rb +34 -36
  41. data/lib/beaker-puppet/version.rb +1 -1
  42. data/lib/beaker-puppet/wrappers.rb +13 -14
  43. data/lib/beaker-puppet.rb +4 -5
  44. data/release-prep.sh +11 -0
  45. data/setup/aio/010_Install_Puppet_Agent.rb +22 -9
  46. data/setup/common/000-delete-puppet-when-none.rb +2 -4
  47. data/setup/common/003_solaris_cert_fix.rb +74 -70
  48. data/setup/common/005_redhat_subscription_fix.rb +3 -2
  49. data/setup/common/011_Install_Puppet_Server.rb +7 -9
  50. data/setup/common/012_Finalize_Installs.rb +5 -5
  51. data/setup/common/025_StopFirewall.rb +1 -1
  52. data/setup/common/030_StopSssd.rb +2 -2
  53. data/setup/common/040_ValidateSignCert.rb +9 -18
  54. data/setup/common/045_EnsureMasterStarted.rb +2 -2
  55. data/setup/gem/010_GemInstall.rb +6 -5
  56. data/setup/git/000_EnvSetup.rb +48 -48
  57. data/setup/git/010_TestSetup.rb +13 -12
  58. data/setup/git/020_PuppetUserAndGroup.rb +3 -2
  59. data/setup/git/060_InstallModules.rb +14 -14
  60. data/setup/git/070_InstallCACerts.rb +82 -82
  61. data/spec/beaker-puppet/helpers/facter_helpers_spec.rb +22 -24
  62. data/spec/beaker-puppet/helpers/host_helpers_spec.rb +10 -6
  63. data/spec/beaker-puppet/helpers/puppet_helpers_spec.rb +463 -724
  64. data/spec/beaker-puppet/helpers/tk_helpers_spec.rb +20 -24
  65. data/spec/beaker-puppet/install_utils/ezbake_utils_spec.rb +86 -90
  66. data/spec/beaker-puppet/install_utils/foss_utils_spec.rb +471 -863
  67. data/spec/beaker-puppet/install_utils/module_utils_spec.rb +125 -116
  68. data/spec/beaker-puppet/install_utils/puppet5_spec.rb +159 -165
  69. data/spec/beaker-puppet/install_utils/puppet_utils_spec.rb +89 -97
  70. data/spec/beaker-puppet/install_utils/windows_utils_spec.rb +101 -89
  71. data/spec/beaker-puppet/wrappers_spec.rb +10 -10
  72. data/spec/helpers.rb +85 -91
  73. data/tasks/ci.rake +188 -188
  74. metadata +38 -62
  75. data/setup/common/020_InstallCumulusModules.rb +0 -13
  76. data/setup/common/021_InstallAristaModuleMasters.rb +0 -12
  77. data/setup/common/022_InstallAristaModuleAgents.rb +0 -13
@@ -1,8 +1,8 @@
1
- require "beaker-puppet/install_utils/windows_utils"
2
- [ 'aio', 'foss' ].each do |lib|
1
+ require 'beaker-puppet/install_utils/windows_utils'
2
+ %w[aio foss].each do |lib|
3
3
  require "beaker-puppet/install_utils/#{lib}_defaults"
4
4
  end
5
- require "beaker-puppet/install_utils/puppet_utils"
5
+ require 'beaker-puppet/install_utils/puppet_utils'
6
6
  module Beaker
7
7
  module DSL
8
8
  module InstallUtils
@@ -23,13 +23,13 @@ module Beaker
23
23
  include WindowsUtils
24
24
 
25
25
  # The default install path
26
- SourcePath = "/opt/puppet-git-repos"
26
+ SourcePath = '/opt/puppet-git-repos'
27
27
 
28
28
  # A regex to know if the uri passed is pointing to a git repo
29
- GitURI = %r{^(git|https?|file)://|^git@|^gitmirror@}
29
+ GitURI = %r{^(git|https?|file)://|^git@|^gitmirror@}
30
30
 
31
31
  # Github's ssh signature for cloning via ssh
32
- GitHubSig = 'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
32
+ GitHubSig = 'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
33
33
 
34
34
  # Merge given options with our default options in a consistent way
35
35
  # This will remove any nil values so that we always have a set default.
@@ -45,17 +45,17 @@ module Beaker
45
45
  opts[:nightly_win_download_url] ||= opts[:nightly_builds_url]
46
46
  opts[:nightly_mac_download_url] ||= opts[:nightly_builds_url]
47
47
 
48
- FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts.reject{|k,v| v.nil?})
48
+ FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts.reject { |k, v| v.nil? })
49
49
  end
50
50
 
51
51
  # lookup project-specific git environment variables
52
52
  # PROJECT_VAR or VAR otherwise return the default
53
53
  #
54
54
  # @!visibility private
55
- def lookup_in_env(env_variable_name, project_name=nil, default=nil)
56
- env_variable_name = "#{env_variable_name.upcase.gsub('-','_')}"
57
- project_specific_name = "#{project_name.upcase.gsub('-','_')}_#{env_variable_name}" if project_name
58
- project_name && ENV[project_specific_name] || ENV[env_variable_name] || default
55
+ def lookup_in_env(env_variable_name, project_name = nil, default = nil)
56
+ env_variable_name = "#{env_variable_name.upcase.gsub('-', '_')}"
57
+ project_specific_name = "#{project_name.upcase.gsub('-', '_')}_#{env_variable_name}" if project_name
58
+ project_name && ENV[project_specific_name] || ENV[env_variable_name] || default # rubocop:disable Style/FetchEnvVar
59
59
  end
60
60
 
61
61
  # @return [Boolean] Whether Puppet's internal builds are accessible from all the SUTs
@@ -76,7 +76,7 @@ module Beaker
76
76
  return true if host.host_hash[:template] == 'redhat-8-arm64' && host.hostname =~ /.puppet.net$/
77
77
 
78
78
  result = on(host, %(curl --location -fI "#{url}"), accept_all_exit_codes: true)
79
- return result.exit_code.zero?
79
+ result.exit_code.zero?
80
80
  end
81
81
 
82
82
  # @param [String] project_name
@@ -87,7 +87,7 @@ module Beaker
87
87
  # @return [String] Returns a git-usable url
88
88
  #
89
89
  # TODO: enable other protocols, clarify, http://git-scm.com/book/ch4-1.html
90
- def build_git_url(project_name, git_fork = nil, git_server = nil, git_protocol='https')
90
+ def build_git_url(project_name, git_fork = nil, git_server = nil, git_protocol = 'https')
91
91
  git_fork ||= lookup_in_env('FORK', project_name, 'puppetlabs')
92
92
  git_server ||= lookup_in_env('SERVER', project_name, 'github.com')
93
93
 
@@ -99,9 +99,9 @@ module Beaker
99
99
  end
100
100
 
101
101
  repo = (git_server == 'github.com') ? "#{git_fork}/#{project_name}.git" : "#{git_fork}-#{project_name}.git"
102
- return git_protocol == 'git@' ? "#{git_protocol}#{git_server}:#{repo}" : "#{git_protocol}#{git_server}/#{repo}"
102
+ (git_protocol == 'git@') ? "#{git_protocol}#{git_server}:#{repo}" : "#{git_protocol}#{git_server}/#{repo}"
103
103
  end
104
- alias_method :build_giturl, :build_git_url
104
+ alias build_giturl build_git_url
105
105
 
106
106
  # @param [String] uri A uri in the format of <git uri>#<revision>
107
107
  # the `git://`, `http://`, `https://`, and ssh
@@ -121,14 +121,14 @@ module Beaker
121
121
  # name, repository path, and revision
122
122
  # (defaults to HEAD)
123
123
  #
124
- def extract_repo_info_from uri
124
+ def extract_repo_info_from(uri)
125
125
  require 'pathname'
126
126
  project = {}
127
127
  repo, rev = uri.split('#', 2)
128
128
  project[:name] = Pathname.new(repo).basename('.git').to_s
129
129
  project[:path] = repo
130
130
  project[:rev] = rev || 'HEAD'
131
- return project
131
+ project
132
132
  end
133
133
 
134
134
  # Takes an array of package info hashes (like that returned from
@@ -136,8 +136,8 @@ module Beaker
136
136
  # packages so that puppet's dependencies will be installed first.
137
137
  #
138
138
  # @!visibility private
139
- def order_packages packages_array
140
- puppet = packages_array.select {|e| e[:name] == 'puppet' }
139
+ def order_packages(packages_array)
140
+ puppet = packages_array.select { |e| e[:name] == 'puppet' }
141
141
  puppet_depends_on = packages_array.select do |e|
142
142
  e[:name] == 'hiera' or e[:name] == 'facter'
143
143
  end
@@ -163,12 +163,12 @@ module Beaker
163
163
  # @note This requires the helper methods:
164
164
  # * {Beaker::DSL::Helpers#on}
165
165
  #
166
- def find_git_repo_versions host, path, repository
166
+ def find_git_repo_versions(host, path, repository)
167
167
  logger.notify("\n * Grab version for #{repository[:name]}")
168
168
 
169
169
  version = {}
170
170
  on host, "cd #{path}/#{repository[:name]} && " +
171
- "git describe || true" do
171
+ 'git describe || true' do
172
172
  version[repository[:name]] = stdout.chomp
173
173
  end
174
174
 
@@ -185,8 +185,8 @@ module Beaker
185
185
  # @note This requires the helper methods:
186
186
  # * {Beaker::DSL::Helpers#on}
187
187
  #
188
- def clone_git_repo_on host, path, repository, opts = {}
189
- opts = {:accept_all_exit_codes => true}.merge(opts)
188
+ def clone_git_repo_on(host, path, repository, opts = {})
189
+ opts = { accept_all_exit_codes: true }.merge(opts)
190
190
  name = repository[:name]
191
191
  repo = repository[:path]
192
192
  rev = repository[:rev]
@@ -194,14 +194,10 @@ module Beaker
194
194
  depth_branch = repository[:depth_branch]
195
195
  target = "#{path}/#{name}"
196
196
 
197
- if (depth_branch.nil?)
198
- depth_branch = rev
199
- end
197
+ depth_branch = rev if depth_branch.nil?
200
198
 
201
199
  clone_cmd = "git clone #{repo} #{target}"
202
- if (depth)
203
- clone_cmd = "git clone --branch #{depth_branch} --depth #{depth} #{repo} #{target}"
204
- end
200
+ clone_cmd = "git clone --branch #{depth_branch} --depth #{depth} #{repo} #{target}" if depth
205
201
 
206
202
  logger.notify("\n * Clone #{repo} if needed")
207
203
 
@@ -210,44 +206,44 @@ module Beaker
210
206
 
211
207
  logger.notify("\n * Update #{name} and check out revision #{rev}")
212
208
  commands = ["cd #{target}",
213
- "remote rm origin",
209
+ 'remote rm origin',
214
210
  "remote add origin #{repo}",
215
- "fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*",
216
- "clean -fdx",
217
- "checkout -f #{rev}"]
218
- on host, commands.join(" && git "), opts
211
+ 'fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*',
212
+ 'clean -fdx',
213
+ "checkout -f #{rev}",]
214
+ on host, commands.join(' && git '), opts
219
215
  end
220
216
 
221
217
  # @see #find_git_repo_versions
222
218
  # @note This assumes the target repository application
223
219
  # can be installed via an install.rb ruby script.
224
- def install_from_git_on host, path, repository, opts = {}
225
- opts = {:accept_all_exit_codes => true}.merge(opts)
220
+ def install_from_git_on(host, path, repository, opts = {})
221
+ opts = { accept_all_exit_codes: true }.merge(opts)
226
222
  clone_git_repo_on host, path, repository, opts
227
- name = repository[:name]
223
+ name = repository[:name]
228
224
  logger.notify("\n * Install #{name} on the system")
229
225
  # The solaris ruby IPS package has bindir set to /usr/ruby/1.8/bin.
230
226
  # However, this is not the path to which we want to deliver our
231
227
  # binaries. So if we are using solaris, we have to pass the bin and
232
228
  # sbin directories to the install.rb
233
- target = "#{path}/#{name}"
229
+ target = "#{path}/#{name}"
234
230
  install_opts = ''
235
231
  install_opts = '--bindir=/usr/bin --sbindir=/usr/sbin' if host['platform'].include? 'solaris'
236
232
 
237
233
  on host, "cd #{target} && " +
238
- "if [ -f install.rb ]; then " +
234
+ 'if [ -f install.rb ]; then ' +
239
235
  "ruby ./install.rb #{install_opts}; " +
240
- "else true; fi", opts
236
+ 'else true; fi', opts
241
237
  end
242
- alias_method :install_from_git, :install_from_git_on
238
+ alias install_from_git install_from_git_on
243
239
 
244
240
  # @deprecated Use {#install_puppet_on} instead.
245
241
  def install_puppet(opts = {})
246
- #send in the global hosts!
242
+ # send in the global hosts!
247
243
  install_puppet_on(hosts, opts)
248
244
  end
249
245
 
250
- #Install FOSS based on specified hosts using provided options
246
+ # Install FOSS based on specified hosts using provided options
251
247
  # @example will install puppet 3.6.1 from native puppetlabs provided packages wherever possible and will fail over to gem installation when impossible
252
248
  # install_puppet_on(hosts, {
253
249
  # :version => '3.6.1',
@@ -275,7 +271,7 @@ module Beaker
275
271
  # install_puppet_on(hosts)
276
272
  #
277
273
  # @note This will attempt to add a repository for apt.puppetlabs.com on
278
- # Debian, Ubuntu, or Cumulus machines, or yum.puppetlabs.com on EL or Fedora
274
+ # Debian or Ubuntu machines, or yum.puppetlabs.com on EL or Fedora
279
275
  # machines, then install the package 'puppet' or 'puppet-agent'.
280
276
  #
281
277
  # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
@@ -294,7 +290,7 @@ module Beaker
294
290
  opts = sanitize_opts(opts)
295
291
 
296
292
  # If version isn't specified assume the latest in the 3.x series
297
- if opts[:version] and not version_is_less(opts[:version], '4.0.0')
293
+ if opts[:version] and !version_is_less(opts[:version], '4.0.0')
298
294
  # backwards compatability
299
295
  opts[:puppet_agent_version] ||= opts[:version]
300
296
  install_puppet_agent_on(hosts, opts)
@@ -302,12 +298,12 @@ module Beaker
302
298
  # Use option specified in the method call, otherwise check whether the global
303
299
  # run_in_parallel option includes install
304
300
  run_in_parallel = run_in_parallel? opts, @options, 'install'
305
- block_on hosts, { :run_in_parallel => run_in_parallel } do |host|
301
+ block_on hosts, { run_in_parallel: run_in_parallel } do |host|
306
302
  if host['platform'] =~ /(el|fedora)-(\d+)/
307
- family = $1
308
- relver = $2
309
- install_puppet_from_rpm_on(host, opts.merge(:release => relver, :family => family))
310
- elsif host['platform'] =~ /(ubuntu|debian|cumulus|huaweios)/
303
+ family = ::Regexp.last_match(1)
304
+ relver = ::Regexp.last_match(2)
305
+ install_puppet_from_rpm_on(host, opts.merge(release: relver, family: family))
306
+ elsif host['platform'] =~ /(ubuntu|debian|huaweios)/
311
307
  install_puppet_from_deb_on(host, opts)
312
308
  elsif host['platform'] =~ /windows/
313
309
  relver = opts[:version]
@@ -321,12 +317,13 @@ module Beaker
321
317
  elsif host['platform'] =~ /archlinux/
322
318
  install_puppet_from_pacman_on(host, opts)
323
319
  else
324
- if opts[:default_action] == 'gem_install'
325
- opts[:version] ||= '~> 3.x'
326
- install_puppet_from_gem_on(host, opts)
327
- else
320
+ unless opts[:default_action] == 'gem_install'
328
321
  raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'"
329
322
  end
323
+
324
+ opts[:version] ||= '~> 3.x'
325
+ install_puppet_from_gem_on(host, opts)
326
+
330
327
  end
331
328
 
332
329
  host[:version] = opts[:version]
@@ -334,7 +331,7 @@ module Beaker
334
331
  # Certain install paths may not create the config dirs/files needed
335
332
  host.mkdir_p host['puppetpath'] unless host[:type] =~ /aio/
336
333
 
337
- if ((host['platform'] =~ /windows/) and not host.is_cygwin?)
334
+ if (host['platform'] =~ /windows/) and !host.is_cygwin?
338
335
  # Do nothing
339
336
  else
340
337
  on host, "echo '' >> #{host.puppet['hiera_config']}"
@@ -357,7 +354,7 @@ module Beaker
357
354
  # install_puppet_agent_on(hosts)
358
355
  #
359
356
  # @note This will attempt to add a repository for apt.puppetlabs.com on
360
- # Debian, Ubuntu, or Cumulus machines, or yum.puppetlabs.com on EL or Fedora
357
+ # Debian or Ubuntu machines, or yum.puppetlabs.com on EL or Fedora
361
358
  # machines, then install the package 'puppet-agent'.
362
359
  #
363
360
  # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
@@ -377,14 +374,14 @@ module Beaker
377
374
  # @raise [FailTest] When error occurs during the actual installation process
378
375
  def install_puppet_agent_on(hosts, opts = {})
379
376
  opts = sanitize_opts(opts)
380
- opts[:puppet_agent_version] ||= opts[:version] #backwards compatability with old parameter name
377
+ opts[:puppet_agent_version] ||= opts[:version] # backwards compatability with old parameter name
381
378
  opts[:puppet_collection] ||= puppet_collection_for(:puppet_agent, opts[:puppet_agent_version]) || 'pc1'
382
379
 
383
380
  # the collection names are case sensitive
384
381
  opts[:puppet_collection] = opts[:puppet_collection].downcase
385
382
 
386
383
  run_in_parallel = run_in_parallel? opts, @options, 'install'
387
- block_on hosts, { :run_in_parallel => run_in_parallel } do |host|
384
+ block_on hosts, { run_in_parallel: run_in_parallel } do |host|
388
385
  # AIO refers to FOSS agents that contain puppet 4+, that is, puppet-agent packages
389
386
  # in the 1.x series, or the 5.x series, or later. Previous versions are not supported,
390
387
  # so 'aio' is the only role that makes sense here.
@@ -392,7 +389,9 @@ module Beaker
392
389
  package_name = nil
393
390
 
394
391
  # If inside the Puppet VPN, install from development builds.
395
- if opts[:puppet_agent_version] && opts[:puppet_agent_version] != 'latest' && dev_builds_accessible_on?(host, opts[:dev_builds_url])
392
+ if opts[:puppet_agent_version] && opts[:puppet_agent_version] != 'latest' && dev_builds_accessible_on?(
393
+ host, opts[:dev_builds_url]
394
+ )
396
395
  install_puppet_agent_from_dev_builds_on(host, opts[:puppet_agent_version])
397
396
  else
398
397
  if opts[:puppet_agent_version] == 'latest'
@@ -407,16 +406,20 @@ module Beaker
407
406
  end
408
407
 
409
408
  case host['platform']
410
- when /el-|redhat|fedora|sles|centos|cisco_/
409
+ when /amazon|el-|redhat|fedora|sles|centos|cisco_/
411
410
  package_name = 'puppet-agent'
412
411
  package_name << "-#{opts[:puppet_agent_version]}" if opts[:puppet_agent_version]
413
- when /debian|ubuntu|cumulus|huaweios/
412
+ when /debian|ubuntu|huaweios/
414
413
  package_name = 'puppet-agent'
415
- package_name << "=#{opts[:puppet_agent_version]}-1#{host['platform'].codename}" if opts[:puppet_agent_version]
414
+ if opts[:puppet_agent_version]
415
+ package_name << "=#{opts[:puppet_agent_version]}-1#{host['platform'].codename}"
416
+ end
416
417
  when /windows/
417
418
  install_puppet_agent_from_msi_on(host, opts)
418
419
  when /osx/
419
420
  install_puppet_agent_from_dmg_on(host, opts)
421
+ when /freebsd/
422
+ install_puppet_from_freebsd_ports_on(host, opts)
420
423
  when /archlinux/
421
424
  install_puppet_from_pacman_on(host, opts)
422
425
  else
@@ -425,23 +428,23 @@ module Beaker
425
428
  install_puppet_from_gem_on(host, opts)
426
429
  on host, "echo '' >> #{host.puppet['hiera_config']}"
427
430
  else
428
- raise "install_puppet_agent_on() called for unsupported " +
431
+ raise 'install_puppet_agent_on() called for unsupported ' +
429
432
  "platform '#{host['platform']}' on '#{host.name}'"
430
433
  end
431
434
  end
432
435
 
433
436
  if package_name
434
- install_puppetlabs_release_repo( host, opts[:puppet_collection] , opts)
435
- host.install_package( package_name )
437
+ install_puppetlabs_release_repo(host, opts[:puppet_collection], opts)
438
+ host.install_package(package_name)
436
439
  end
437
440
  end
438
441
  end
439
442
  end
440
443
 
441
444
  # @deprecated Use {#configure_puppet_on} instead.
442
- def configure_puppet(opts={})
445
+ def configure_puppet(opts = {})
443
446
  hosts.each do |host|
444
- configure_puppet_on(host,opts)
447
+ configure_puppet_on(host, opts)
445
448
  end
446
449
  end
447
450
 
@@ -472,14 +475,14 @@ module Beaker
472
475
  # @return nil
473
476
  def configure_puppet_on(hosts, opts = {})
474
477
  puppet_conf_text = ''
475
- opts.each do |section,options|
478
+ opts.each do |section, options|
476
479
  puppet_conf_text << "[#{section}]\n"
477
- options.each do |option,value|
480
+ options.each do |option, value|
478
481
  puppet_conf_text << "#{option}=#{value}\n"
479
482
  end
480
483
  puppet_conf_text << "\n"
481
484
  end
482
- logger.debug( "setting config '#{puppet_conf_text}' on hosts #{hosts}" )
485
+ logger.debug("setting config '#{puppet_conf_text}' on hosts #{hosts}")
483
486
  block_on hosts, opts do |host|
484
487
  puppet_conf_path = host.puppet['config']
485
488
  create_remote_file(host, puppet_conf_path, puppet_conf_text)
@@ -499,30 +502,26 @@ module Beaker
499
502
  #
500
503
  # @return nil
501
504
  # @api private
502
- def install_puppet_from_rpm_on( hosts, opts )
505
+ def install_puppet_from_rpm_on(hosts, opts)
503
506
  block_on hosts do |host|
504
507
  if opts[:puppet_collection] && opts[:puppet_collection].match(/puppet\d*/)
505
- install_puppetlabs_release_repo(host,opts[:puppet_collection],opts)
508
+ install_puppetlabs_release_repo(host, opts[:puppet_collection], opts)
506
509
  elsif host[:type] == 'aio'
507
- install_puppetlabs_release_repo(host,'pc1',opts)
510
+ install_puppetlabs_release_repo(host, 'pc1', opts)
508
511
  else
509
- install_puppetlabs_release_repo(host,nil,opts)
512
+ install_puppetlabs_release_repo(host, nil, opts)
510
513
  end
511
514
 
512
- if opts[:facter_version]
513
- host.install_package("facter-#{opts[:facter_version]}")
514
- end
515
+ host.install_package("facter-#{opts[:facter_version]}") if opts[:facter_version]
515
516
 
516
- if opts[:hiera_version]
517
- host.install_package("hiera-#{opts[:hiera_version]}")
518
- end
517
+ host.install_package("hiera-#{opts[:hiera_version]}") if opts[:hiera_version]
519
518
 
520
519
  puppet_pkg = opts[:version] ? "puppet-#{opts[:version]}" : 'puppet'
521
520
  host.install_package("#{puppet_pkg}")
522
- configure_type_defaults_on( host )
521
+ configure_type_defaults_on(host)
523
522
  end
524
523
  end
525
- alias_method :install_puppet_from_rpm, :install_puppet_from_rpm_on
524
+ alias install_puppet_from_rpm install_puppet_from_rpm_on
526
525
 
527
526
  # Installs Puppet and dependencies from deb on provided host(s).
528
527
  #
@@ -535,17 +534,13 @@ module Beaker
535
534
  #
536
535
  # @return nil
537
536
  # @api private
538
- def install_puppet_from_deb_on( hosts, opts )
537
+ def install_puppet_from_deb_on(hosts, opts)
539
538
  block_on hosts do |host|
540
539
  install_puppetlabs_release_repo(host)
541
540
 
542
- if opts[:facter_version]
543
- host.install_package("facter=#{opts[:facter_version]}-1puppetlabs1")
544
- end
541
+ host.install_package("facter=#{opts[:facter_version]}-1puppetlabs1") if opts[:facter_version]
545
542
 
546
- if opts[:hiera_version]
547
- host.install_package("hiera=#{opts[:hiera_version]}-1puppetlabs1")
548
- end
543
+ host.install_package("hiera=#{opts[:hiera_version]}-1puppetlabs1") if opts[:hiera_version]
549
544
 
550
545
  if opts[:version]
551
546
  host.install_package("puppet-common=#{opts[:version]}-1puppetlabs1")
@@ -553,10 +548,10 @@ module Beaker
553
548
  else
554
549
  host.install_package('puppet')
555
550
  end
556
- configure_type_defaults_on( host )
551
+ configure_type_defaults_on(host)
557
552
  end
558
553
  end
559
- alias_method :install_puppet_from_deb, :install_puppet_from_deb_on
554
+ alias install_puppet_from_deb install_puppet_from_deb_on
560
555
 
561
556
  # Installs Puppet and dependencies from msi on provided host(s).
562
557
  #
@@ -570,15 +565,15 @@ module Beaker
570
565
  #
571
566
  # @note on windows, the +:ruby_arch+ host parameter can determine in addition
572
567
  # to other settings whether the 32 or 64bit install is used
573
- def install_puppet_from_msi_on( hosts, opts )
568
+ def install_puppet_from_msi_on(hosts, opts)
574
569
  block_on hosts do |host|
575
570
  version = opts[:version]
576
571
 
577
572
  if version && !version_is_less(version, '4.0.0')
578
573
  if opts[:puppet_agent_version].nil?
579
- raise "You must specify the version of puppet agent you " +
580
- "want to install if you want to install Puppet 4.0 " +
581
- "or greater on Windows"
574
+ raise 'You must specify the version of puppet agent you ' +
575
+ 'want to install if you want to install Puppet 4.0 ' +
576
+ 'or greater on Windows'
582
577
  end
583
578
 
584
579
  opts[:version] = opts[:puppet_agent_version]
@@ -589,10 +584,10 @@ module Beaker
589
584
  install_a_puppet_msi_on(host, opts)
590
585
 
591
586
  end
592
- configure_type_defaults_on( host )
587
+ configure_type_defaults_on(host)
593
588
  end
594
589
  end
595
- alias_method :install_puppet_from_msi, :install_puppet_from_msi_on
590
+ alias install_puppet_from_msi install_puppet_from_msi_on
596
591
 
597
592
  # @api private
598
593
  def compute_puppet_msi_name(host, opts)
@@ -601,12 +596,12 @@ module Beaker
601
596
  less_than_3_dot_7 = version && version_is_less(version, '3.7')
602
597
 
603
598
  # If there's no version declared, install the latest in the 3.x series
604
- if not version
605
- if !host.is_x86_64? || install_32
606
- host['dist'] = 'puppet-latest'
607
- else
608
- host['dist'] = 'puppet-x64-latest'
609
- end
599
+ if !version
600
+ host['dist'] = if !host.is_x86_64? || install_32
601
+ 'puppet-latest'
602
+ else
603
+ 'puppet-x64-latest'
604
+ end
610
605
 
611
606
  # Install Puppet 3.x with the x86 installer if:
612
607
  # - we are on puppet < 3.7, or
@@ -614,11 +609,11 @@ module Beaker
614
609
  # - we have install_32 set on host or globally
615
610
  # Install Puppet 3.x with the x64 installer if:
616
611
  # - we are otherwise trying to install Puppet 3.x on a x64 host
617
- elsif less_than_3_dot_7 or not host.is_x86_64? or install_32
612
+ elsif less_than_3_dot_7 or !host.is_x86_64? or install_32
618
613
  host['dist'] = "puppet-#{version}"
619
614
 
620
615
  elsif host.is_x86_64?
621
- host['dist'] = "puppet-#{version}-x64"
616
+ host['dist'] = "puppet-#{version}-x64"
622
617
 
623
618
  else
624
619
  raise "I don't understand how to install Puppet version: #{version}"
@@ -637,18 +632,17 @@ module Beaker
637
632
  # to other settings whether the 32 or 64bit install is used
638
633
  def install_puppet_agent_from_msi_on(hosts, opts)
639
634
  block_on hosts do |host|
640
-
641
- add_role(host, 'aio') #we are installing agent, so we want aio role
635
+ add_role(host, 'aio') # we are installing agent, so we want aio role
642
636
  is_config_32 = true == (host['ruby_arch'] == 'x86') || host['install_32'] || opts['install_32']
643
637
  should_install_64bit = host.is_x86_64? && !is_config_32
644
638
  arch = should_install_64bit ? 'x64' : 'x86'
645
639
 
646
640
  # If we don't specify a version install the latest MSI for puppet-agent
647
- if opts[:puppet_agent_version]
648
- host['dist'] = "puppet-agent-#{opts[:puppet_agent_version]}-#{arch}"
649
- else
650
- host['dist'] = "puppet-agent-#{arch}-latest"
651
- end
641
+ host['dist'] = if opts[:puppet_agent_version]
642
+ "puppet-agent-#{opts[:puppet_agent_version]}-#{arch}"
643
+ else
644
+ "puppet-agent-#{arch}-latest"
645
+ end
652
646
 
653
647
  install_a_puppet_msi_on(host, opts)
654
648
  end
@@ -666,9 +660,8 @@ module Beaker
666
660
  else
667
661
  link = "#{opts[:win_download_url]}/#{host['dist']}.msi"
668
662
  end
669
- if not link_exists?( link )
670
- raise "Puppet MSI at #{link} does not exist!"
671
- end
663
+ raise "Puppet MSI at #{link} does not exist!" unless link_exists?(link)
664
+
672
665
  link
673
666
  end
674
667
 
@@ -683,20 +676,21 @@ module Beaker
683
676
  proxy = opts[:package_proxy] ? "-x #{opts[:package_proxy]} " : ''
684
677
  on host, "curl #{proxy}--location --output \"#{msi_download_path}\" --remote-name #{link}"
685
678
 
686
- #Because the msi installer doesn't add Puppet to the environment path
687
- #Add both potential paths for simplicity
688
- #NOTE - this is unnecessary if the host has been correctly identified as 'foss' during set up
689
- puppetbin_path = "\"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin\":\"/cygdrive/c/Program Files/Puppet Labs/Puppet/bin\""
690
- on host, %Q{ echo 'export PATH=$PATH:#{puppetbin_path}' > /etc/bash.bashrc }
679
+ # Because the msi installer doesn't add Puppet to the environment path
680
+ # Add both potential paths for simplicity
681
+ # NOTE - this is unnecessary if the host has been correctly identified as 'foss' during set up
682
+ puppetbin_path = '"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin":"/cygdrive/c/Program Files/Puppet Labs/Puppet/bin"'
683
+ on host, %( echo 'export PATH=$PATH:#{puppetbin_path}' > /etc/bash.bashrc )
691
684
  else
692
685
  webclient_proxy = opts[:package_proxy] ? "$webclient.Proxy = New-Object System.Net.WebProxy('#{opts[:package_proxy]}',$true); " : ''
693
- on host, powershell("$webclient = New-Object System.Net.WebClient; #{webclient_proxy}$webclient.DownloadFile('#{link}','#{msi_download_path}')")
686
+ on host,
687
+ powershell("$webclient = New-Object System.Net.WebClient; #{webclient_proxy}$webclient.DownloadFile('#{link}','#{msi_download_path}')")
694
688
  end
695
689
 
696
- opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
690
+ opts = { debug: host[:pe_debug] || opts[:pe_debug] }
697
691
  install_msi_on(host, msi_download_path, {}, opts)
698
692
 
699
- configure_type_defaults_on( host )
693
+ configure_type_defaults_on(host)
700
694
 
701
695
  host.mkdir_p host['distmoduledir'] unless host.is_cygwin?
702
696
  end
@@ -711,21 +705,17 @@ module Beaker
711
705
  #
712
706
  # @return nil
713
707
  # @api private
714
- def install_puppet_from_freebsd_ports_on( hosts, opts )
715
- if (opts[:version])
708
+ def install_puppet_from_freebsd_ports_on(hosts, opts)
709
+ if opts[:version]
716
710
  logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
717
711
  end
718
712
 
719
713
  block_on hosts do |host|
720
- if host['platform'] =~ /freebsd-9/
721
- host.install_package("puppet")
722
- else
723
- host.install_package("sysutils/puppet")
724
- end
714
+ host.install_package('sysutils/puppet7')
715
+ configure_type_defaults_on(host)
725
716
  end
726
-
727
717
  end
728
- alias_method :install_puppet_from_freebsd_ports, :install_puppet_from_freebsd_ports_on
718
+ alias install_puppet_from_freebsd_ports install_puppet_from_freebsd_ports_on
729
719
 
730
720
  # Installs Puppet and dependencies from dmg on provided host(s).
731
721
  #
@@ -740,14 +730,14 @@ module Beaker
740
730
  #
741
731
  # @return nil
742
732
  # @api private
743
- def install_puppet_from_dmg_on( hosts, opts )
733
+ def install_puppet_from_dmg_on(hosts, opts)
744
734
  block_on hosts do |host|
745
735
  # install puppet-agent if puppet version > 4.0 OR not puppet version is provided
746
736
  if (opts[:version] && !version_is_less(opts[:version], '4.0.0')) || !opts[:version]
747
737
  if opts[:puppet_agent_version].nil?
748
- raise "You must specify the version of puppet-agent you " +
749
- "want to install if you want to install Puppet 4.0 " +
750
- "or greater on OSX"
738
+ raise 'You must specify the version of puppet-agent you ' +
739
+ 'want to install if you want to install Puppet 4.0 ' +
740
+ 'or greater on OSX'
751
741
  end
752
742
 
753
743
  install_puppet_agent_from_dmg_on(host, opts)
@@ -757,9 +747,9 @@ module Beaker
757
747
  facter_ver = opts[:facter_version] || 'latest'
758
748
  hiera_ver = opts[:hiera_version] || 'latest'
759
749
 
760
- if [puppet_ver, facter_ver, hiera_ver].include?(nil)
761
- raise "You need to specify versions for OSX host\n eg. install_puppet({:version => '3.6.2',:facter_version => '2.1.0',:hiera_version => '1.3.4',})"
762
- end
750
+ raise "You need to specify versions for OSX host\n eg. install_puppet({:version => '3.6.2',:facter_version => '2.1.0',:hiera_version => '1.3.4',})" if [
751
+ puppet_ver, facter_ver, hiera_ver,
752
+ ].include?(nil)
763
753
 
764
754
  on host, "curl --location --remote-name #{opts[:mac_download_url]}/puppet-#{puppet_ver}.dmg"
765
755
  on host, "curl --location --remote-name #{opts[:mac_download_url]}/facter-#{facter_ver}.dmg"
@@ -769,11 +759,11 @@ module Beaker
769
759
  host.install_package("facter-#{facter_ver}")
770
760
  host.install_package("hiera-#{hiera_ver}")
771
761
 
772
- configure_type_defaults_on( host )
762
+ configure_type_defaults_on(host)
773
763
  end
774
764
  end
775
765
  end
776
- alias_method :install_puppet_from_dmg, :install_puppet_from_dmg_on
766
+ alias install_puppet_from_dmg install_puppet_from_dmg_on
777
767
 
778
768
  # Installs puppet-agent and dependencies from dmg on provided host(s).
779
769
  #
@@ -790,8 +780,7 @@ module Beaker
790
780
  opts[:puppet_collection] ||= 'PC1'
791
781
  opts[:puppet_collection] = opts[:puppet_collection].upcase if opts[:puppet_collection].match(/pc1/i)
792
782
  block_on hosts do |host|
793
-
794
- add_role(host, 'aio') #we are installing agent, so we want aio role
783
+ add_role(host, 'aio') # we are installing agent, so we want aio role
795
784
 
796
785
  variant, version, arch, codename = host['platform'].to_array
797
786
 
@@ -809,9 +798,7 @@ module Beaker
809
798
  latest = get_latest_puppet_agent_build_from_url(download_url)
810
799
 
811
800
  agent_version = opts[:puppet_agent_version] || latest
812
- unless agent_version.length > 0
813
- raise "no puppet-agent version specified or found on at #{download_url}"
814
- end
801
+ raise "no puppet-agent version specified or found on at #{download_url}" unless agent_version.length > 0
815
802
 
816
803
  pkg_name = "puppet-agent-#{agent_version}*"
817
804
  dmg_name = "puppet-agent-#{agent_version}-1.osx#{version}.dmg"
@@ -819,7 +806,7 @@ module Beaker
819
806
 
820
807
  host.install_package(pkg_name)
821
808
 
822
- configure_type_defaults_on( host )
809
+ configure_type_defaults_on(host)
823
810
  end
824
811
  end
825
812
 
@@ -842,28 +829,27 @@ module Beaker
842
829
  # Redirect following
843
830
  while response.is_a?(Net::HTTPRedirection) && counter < 15
844
831
  response = Net::HTTP.get_response(URI.parse(Net::HTTP.get_response(URI(full_url))['location']))
845
- counter = counter + 1
832
+ counter += 1
846
833
  end
847
834
 
848
- raise "The URL for puppet-agent download, #{response.uri}, returned #{response.message} with #{response.code}" unless response.is_a?(Net::HTTPSuccess)
835
+ unless response.is_a?(Net::HTTPSuccess)
836
+ raise "The URL for puppet-agent download, #{response.uri}, returned #{response.message} with #{response.code}"
837
+ end
849
838
 
850
839
  document = Oga.parse_html(response.body)
851
840
  agents = document.xpath('//a[contains(@href, "puppet-agent")]')
852
841
 
853
842
  latest_match = agents.shift.attributes[0].value
854
- while (latest_match =~ /puppet-agent-\d(.*)/).nil?
855
- latest_match = agents.shift.attributes[0].value
856
- end
843
+ latest_match = agents.shift.attributes[0].value while (latest_match =~ /puppet-agent-\d(.*)/).nil?
857
844
 
858
- re = /puppet-agent-(.*)-/
845
+ re = /puppet-agent-(.*)-/
859
846
  latest_match = latest_match.match re
860
847
 
861
848
  if latest_match
862
- latest = latest_match[1]
849
+ latest_match[1]
863
850
  else
864
- latest = ''
851
+ ''
865
852
  end
866
- return latest
867
853
  end
868
854
 
869
855
  # Installs Puppet and dependencies from OpenBSD packages
@@ -875,7 +861,7 @@ module Beaker
875
861
  # @return nil
876
862
  # @api private
877
863
  def install_puppet_from_openbsd_packages_on(hosts, opts)
878
- if (opts[:version])
864
+ if opts[:version]
879
865
  logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
880
866
  end
881
867
 
@@ -895,7 +881,7 @@ module Beaker
895
881
  # @return nil
896
882
  # @api private
897
883
  def install_puppet_from_pacman_on(hosts, opts)
898
- if (opts[:version])
884
+ if opts[:version]
899
885
  # Arch is rolling release, only the latest package versions are supported
900
886
  logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
901
887
  end
@@ -919,7 +905,7 @@ module Beaker
919
905
  # @return nil
920
906
  # @raise [StandardError] if gem does not exist on target host
921
907
  # @api private
922
- def install_puppet_from_gem_on( hosts, opts )
908
+ def install_puppet_from_gem_on(hosts, opts)
923
909
  block_on hosts do |host|
924
910
  # There are a lot of special things to do for Solaris and Solaris 10.
925
911
  # This is easier than checking host['platform'] every time.
@@ -928,23 +914,19 @@ module Beaker
928
914
 
929
915
  # Hosts may be provisioned with csw but pkgutil won't be in the
930
916
  # PATH by default to avoid changing the behavior for Puppet's tests
931
- if is_solaris10
932
- on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil'
933
- end
917
+ on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil' if is_solaris10
934
918
 
935
919
  # Solaris doesn't necessarily have this, but gem needs it
936
- if is_solaris
937
- on host, 'mkdir -p /var/lib'
938
- end
920
+ on host, 'mkdir -p /var/lib' if is_solaris
939
921
 
940
- unless host.check_for_command( 'gem' )
922
+ unless host.check_for_command('gem')
941
923
  gempkg = case host['platform']
942
924
  when /solaris-11/ then 'ruby-18'
943
925
  when /ubuntu-14/ then 'ruby'
944
- when /solaris-10|ubuntu|debian|el-|cumulus|huaweios/ then 'rubygems'
945
- when /openbsd/ then 'ruby'
926
+ when /solaris-10|ubuntu|debian|el-|huaweios/ then 'rubygems'
927
+ when /openbsd/ then 'ruby'
946
928
  else
947
- raise "install_puppet() called with default_action " +
929
+ raise 'install_puppet() called with default_action ' +
948
930
  "'gem_install' but program `gem' is " +
949
931
  "not installed on #{host.name}"
950
932
  end
@@ -953,26 +935,20 @@ module Beaker
953
935
  end
954
936
 
955
937
  # Link 'gem' to /usr/bin instead of adding /opt/csw/bin to PATH.
956
- if is_solaris10
957
- on host, 'ln -s /opt/csw/bin/gem /usr/bin/gem'
958
- end
938
+ on host, 'ln -s /opt/csw/bin/gem /usr/bin/gem' if is_solaris10
959
939
 
960
- if host['platform'] =~ /debian|ubuntu|solaris|cumulus|huaweios/
961
- gem_env = YAML.load( on( host, 'gem environment' ).stdout )
962
- gem_paths_array = gem_env['RubyGems Environment'].find {|h| h['GEM PATHS'] != nil }['GEM PATHS']
940
+ if host['platform'] =~ /debian|ubuntu|solaris|huaweios/
941
+ gem_env = YAML.load(on(host, 'gem environment').stdout)
942
+ gem_paths_array = gem_env['RubyGems Environment'].find { |h| h['GEM PATHS'] != nil }['GEM PATHS']
963
943
  path_with_gem = 'export PATH=' + gem_paths_array.join(':') + ':${PATH}'
964
944
  on host, "echo '#{path_with_gem}' >> ~/.bashrc"
965
945
  end
966
946
 
967
947
  gemflags = '--no-document --no-format-executable'
968
948
 
969
- if opts[:facter_version]
970
- on host, "gem install facter -v'#{opts[:facter_version]}' #{gemflags}"
971
- end
949
+ on host, "gem install facter -v'#{opts[:facter_version]}' #{gemflags}" if opts[:facter_version]
972
950
 
973
- if opts[:hiera_version]
974
- on host, "gem install hiera -v'#{opts[:hiera_version]}' #{gemflags}"
975
- end
951
+ on host, "gem install hiera -v'#{opts[:hiera_version]}' #{gemflags}" if opts[:hiera_version]
976
952
 
977
953
  ver_cmd = opts[:version] ? "-v '#{opts[:version]}'" : ''
978
954
  on host, "gem install puppet #{ver_cmd} #{gemflags}"
@@ -980,12 +956,12 @@ module Beaker
980
956
  # Similar to the treatment of 'gem' above.
981
957
  # This avoids adding /opt/csw/bin to PATH.
982
958
  if is_solaris
983
- gem_env = YAML.load( on( host, 'gem environment' ).stdout )
959
+ gem_env = YAML.load(on(host, 'gem environment').stdout)
984
960
  # This is the section we want - this has the dir where gem executables go.
985
961
  env_sect = 'EXECUTABLE DIRECTORY'
986
962
  # Get the directory where 'gem' installs executables.
987
963
  # On Solaris 10 this is usually /opt/csw/bin
988
- gem_exec_dir = gem_env['RubyGems Environment'].find {|h| h[env_sect] != nil }[env_sect]
964
+ gem_exec_dir = gem_env['RubyGems Environment'].find { |h| !h[env_sect].nil? }[env_sect]
989
965
 
990
966
  on host, "ln -s #{gem_exec_dir}/hiera /usr/bin/hiera"
991
967
  on host, "ln -s #{gem_exec_dir}/facter /usr/bin/facter"
@@ -993,15 +969,15 @@ module Beaker
993
969
  end
994
970
 
995
971
  # A gem install might not necessarily create these
996
- ['confdir', 'logdir', 'codedir'].each do |key|
972
+ %w[confdir logdir codedir].each do |key|
997
973
  host.mkdir_p host.puppet[key] if host.puppet.has_key?(key)
998
974
  end
999
975
 
1000
- configure_type_defaults_on( host )
976
+ configure_type_defaults_on(host)
1001
977
  end
1002
978
  end
1003
- alias_method :install_puppet_from_gem, :install_puppet_from_gem_on
1004
- alias_method :install_puppet_agent_from_gem_on, :install_puppet_from_gem_on
979
+ alias install_puppet_from_gem install_puppet_from_gem_on
980
+ alias install_puppet_agent_from_gem_on install_puppet_from_gem_on
1005
981
 
1006
982
  # Install official puppetlabs release repository configuration on host(s).
1007
983
  #
@@ -1010,15 +986,15 @@ module Beaker
1010
986
  #
1011
987
  # @note This method only works on redhat-like and debian-like hosts.
1012
988
  #
1013
- def install_puppetlabs_release_repo_on( hosts, repo = nil, opts = options )
989
+ def install_puppetlabs_release_repo_on(hosts, repo = nil, opts = options)
1014
990
  block_on hosts do |host|
1015
991
  variant, version, arch, codename = host['platform'].to_array
1016
992
  repo_name = repo || opts[:puppet_collection] || 'puppet'
1017
993
  opts = sanitize_opts(opts)
1018
994
 
1019
995
  case variant
1020
- when /^(fedora|el|redhat|centos|sles|cisco_nexus|cisco_ios_xr)$/
1021
- variant_url_value = ((['redhat','centos'].include?($1)) ? 'el' : $1)
996
+ when /^(amazon|fedora|el|redhat|centos|sles|cisco_nexus|cisco_ios_xr)$/
997
+ variant_url_value = (%w[redhat centos].include?(::Regexp.last_match(1)) ? 'el' : ::Regexp.last_match(1))
1022
998
  if variant == 'cisco_nexus'
1023
999
  variant_url_value = 'cisco-wrlinux'
1024
1000
  version = '5'
@@ -1033,11 +1009,10 @@ module Beaker
1033
1009
  else
1034
1010
  opts[:release_yum_repo_url]
1035
1011
  end
1036
- remote = "%s/%s-release-%s-%s.noarch.rpm" %
1037
- [url, repo_name, variant_url_value, version]
1012
+ remote = format('%s/%s-release-%s-%s.noarch.rpm', url, repo_name, variant_url_value, version)
1038
1013
  else
1039
- remote = "%s/%s-release-%s-%s.noarch.rpm" %
1040
- [opts[:release_yum_repo_url], repo_name, variant_url_value, version]
1014
+ remote = format('%s/%s-release-%s-%s.noarch.rpm', opts[:release_yum_repo_url], repo_name,
1015
+ variant_url_value, version)
1041
1016
  end
1042
1017
 
1043
1018
  # sles 11 and later do not handle gpg keys well. We can't
@@ -1055,40 +1030,38 @@ module Beaker
1055
1030
 
1056
1031
  if variant == 'cisco_nexus'
1057
1032
  # cisco nexus requires using yum to install the repo
1058
- host.install_package( remote )
1033
+ host.install_package(remote)
1059
1034
  elsif variant == 'cisco_ios_xr'
1060
1035
  # cisco ios xr requires using yum to localinstall the repo
1061
1036
  on host, "yum -y localinstall #{remote}"
1062
1037
  else
1063
1038
  opts[:package_proxy] ||= false
1064
- host.install_package_with_rpm( remote, '--replacepkgs',
1065
- { :package_proxy => opts[:package_proxy] } )
1039
+ host.install_package_with_rpm(remote, '--replacepkgs',
1040
+ { package_proxy: opts[:package_proxy] })
1066
1041
  end
1067
1042
 
1068
- when /^(debian|ubuntu|cumulus|huaweios)$/
1043
+ when /^(debian|ubuntu|huaweios)$/
1069
1044
  if repo_name.match(/puppet\d*/)
1070
1045
  url = if repo_name.match(/-nightly$/)
1071
1046
  opts[:nightly_apt_repo_url]
1072
1047
  else
1073
1048
  opts[:release_apt_repo_url]
1074
1049
  end
1075
- remote = "%s/%s-release-%s.deb" %
1076
- [url, repo_name, codename]
1050
+ remote = format('%s/%s-release-%s.deb', url, repo_name, codename)
1077
1051
  else
1078
- remote = "%s/%s-release-%s.deb" %
1079
- [opts[:release_apt_repo_url], repo_name, codename]
1052
+ remote = format('%s/%s-release-%s.deb', opts[:release_apt_repo_url], repo_name, codename)
1080
1053
  end
1081
1054
 
1082
1055
  on host, "wget -O /tmp/puppet.deb #{remote}"
1083
- on host, "dpkg -i --force-all /tmp/puppet.deb"
1084
- on host, "apt-get update"
1056
+ on host, 'dpkg -i --force-all /tmp/puppet.deb'
1057
+ on host, 'apt-get update'
1085
1058
  else
1086
1059
  raise "No repository installation step for #{variant} yet..."
1087
1060
  end
1088
- configure_type_defaults_on( host )
1061
+ configure_type_defaults_on(host)
1089
1062
  end
1090
1063
  end
1091
- alias_method :install_puppetlabs_release_repo, :install_puppetlabs_release_repo_on
1064
+ alias install_puppetlabs_release_repo install_puppetlabs_release_repo_on
1092
1065
 
1093
1066
  # Installs the repo configs on a given host
1094
1067
  #
@@ -1100,12 +1073,12 @@ module Beaker
1100
1073
  #
1101
1074
  # @return nil
1102
1075
  def install_repo_configs(host, buildserver_url, package_name, build_version, copy_dir)
1103
- repo_filename = host.repo_filename( package_name, build_version )
1104
- repo_config_folder_url = "%s/%s/%s/repo_configs/%s/" %
1105
- [ buildserver_url, package_name, build_version, host.repo_type ]
1076
+ repo_filename = host.repo_filename(package_name, build_version)
1077
+ repo_config_folder_url = format('%s/%s/%s/repo_configs/%s/', buildserver_url, package_name, build_version,
1078
+ host.repo_type)
1106
1079
 
1107
- repo_config_url = "#{ repo_config_folder_url }/#{ repo_filename }"
1108
- install_repo_configs_from_url( host, repo_config_url, copy_dir )
1080
+ repo_config_url = "#{repo_config_folder_url}/#{repo_filename}"
1081
+ install_repo_configs_from_url(host, repo_config_url, copy_dir)
1109
1082
  end
1110
1083
 
1111
1084
  # Installs the repo configs on a given host
@@ -1117,35 +1090,35 @@ module Beaker
1117
1090
  # @return nil
1118
1091
  def install_repo_configs_from_url(host, repo_config_url, copy_dir = nil)
1119
1092
  copy_dir ||= Dir.mktmpdir
1120
- repoconfig_filename = File.basename( repo_config_url )
1121
- repoconfig_folder = File.dirname( repo_config_url )
1093
+ repoconfig_filename = File.basename(repo_config_url)
1094
+ repoconfig_folder = File.dirname(repo_config_url)
1122
1095
 
1123
1096
  repo = fetch_http_file(
1124
1097
  repoconfig_folder,
1125
1098
  repoconfig_filename,
1126
- copy_dir
1099
+ copy_dir,
1127
1100
  )
1128
1101
 
1129
1102
  if host['platform'].variant =~ /^(ubuntu|debian)$/
1130
1103
  # Bypass signing checks on this repo and its packages
1131
1104
  original_contents = File.read(repo)
1132
- logger.debug "INFO original repo contents:"
1105
+ logger.debug 'INFO original repo contents:'
1133
1106
  logger.debug original_contents
1134
- contents = original_contents.gsub(/^deb http/, "deb [trusted=yes] http")
1135
- logger.debug "INFO new repo contents:"
1107
+ contents = original_contents.gsub(/^deb http/, 'deb [trusted=yes] http')
1108
+ logger.debug 'INFO new repo contents:'
1136
1109
  logger.debug contents
1137
1110
 
1138
1111
  File.write(repo, contents)
1139
1112
  end
1140
1113
 
1141
- if host[:platform] =~ /cisco_nexus/
1142
- to_path = "#{host.package_config_dir}/#{File.basename(repo)}"
1143
- else
1144
- to_path = host.package_config_dir
1145
- end
1146
- scp_to( host, repo, to_path )
1114
+ to_path = if host[:platform] =~ /cisco_nexus/
1115
+ "#{host.package_config_dir}/#{File.basename(repo)}"
1116
+ else
1117
+ host.package_config_dir
1118
+ end
1119
+ scp_to(host, repo, to_path)
1147
1120
 
1148
- on( host, 'apt-get update' ) if host['platform'] =~ /ubuntu-|debian-|cumulus-|huaweios-/
1121
+ on(host, 'apt-get update') if host['platform'] =~ /ubuntu-|debian-|huaweios-/
1149
1122
  nil
1150
1123
  end
1151
1124
 
@@ -1171,13 +1144,14 @@ module Beaker
1171
1144
  #
1172
1145
  # @note This method only works on redhat-like and debian-like hosts.
1173
1146
  #
1174
- def install_puppetlabs_dev_repo ( host, package_name, build_version,
1175
- repo_configs_dir = nil,
1176
- opts = options )
1147
+ def install_puppetlabs_dev_repo(host, package_name, build_version,
1148
+ repo_configs_dir = nil,
1149
+ opts = options)
1177
1150
  variant, version, arch, codename = host['platform'].to_array
1178
- if variant !~ /^(fedora|el|redhat|centos|debian|ubuntu|cumulus|huaweios|cisco_nexus|cisco_ios_xr|sles)$/
1151
+ if variant !~ /^(fedora|el|redhat|centos|debian|ubuntu|huaweios|cisco_nexus|cisco_ios_xr|sles)$/
1179
1152
  raise "No repository installation step for #{variant} yet..."
1180
1153
  end
1154
+
1181
1155
  repo_configs_dir ||= 'tmp/repo_configs'
1182
1156
 
1183
1157
  platform_configs_dir = File.join(repo_configs_dir, variant)
@@ -1186,14 +1160,14 @@ module Beaker
1186
1160
  # some of the uses of dev_builds_url below can't include protocol info,
1187
1161
  # plus this opens up possibility of switching the behavior on provided
1188
1162
  # url type
1189
- _, protocol, hostname = opts[:dev_builds_url].partition /.*:\/\//
1163
+ _, protocol, hostname = opts[:dev_builds_url].partition %r{.*://}
1190
1164
  dev_builds_url = protocol + hostname
1191
1165
  dev_builds_url = opts[:dev_builds_url] if variant =~ /^(fedora|el|redhat|centos)$/
1192
1166
 
1193
- install_repo_configs( host, dev_builds_url, package_name,
1194
- build_version, platform_configs_dir )
1167
+ install_repo_configs(host, dev_builds_url, package_name,
1168
+ build_version, platform_configs_dir)
1195
1169
 
1196
- configure_type_defaults_on( host )
1170
+ configure_type_defaults_on(host)
1197
1171
  end
1198
1172
 
1199
1173
  # Installs packages from the local development repository on the given host
@@ -1206,8 +1180,8 @@ module Beaker
1206
1180
  # @note This method only works on redhat-like and debian-like hosts.
1207
1181
  # @note This method is paired to be run directly after {#install_puppetlabs_dev_repo}
1208
1182
  #
1209
- def install_packages_from_local_dev_repo( host, package_name )
1210
- if host['platform'] =~ /debian|ubuntu|cumulus|huaweios/
1183
+ def install_packages_from_local_dev_repo(host, package_name)
1184
+ if host['platform'] =~ /debian|ubuntu|huaweios/
1211
1185
  find_filename = '*.deb'
1212
1186
  find_command = 'dpkg -i'
1213
1187
  elsif host['platform'] =~ /fedora|el|redhat|centos/
@@ -1218,195 +1192,7 @@ module Beaker
1218
1192
  end
1219
1193
  find_command = "find /root/#{package_name} -type f -name '#{find_filename}' -exec #{find_command} {} \\;"
1220
1194
  on host, find_command
1221
- configure_type_defaults_on( host )
1222
- end
1223
-
1224
- # Install development repo of the puppet-agent on the given host(s). Downloaded from
1225
- # location of the form DEV_BUILDS_URL/puppet-agent/AGENT_VERSION/repos
1226
- #
1227
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
1228
- # or a role (String or Symbol) that identifies one or more hosts.
1229
- # @param [Hash{Symbol=>String}] opts An options hash
1230
- # @option opts [String] :puppet_agent_version The version of puppet-agent to install. This
1231
- # parameter is used by puppet with the +SUITE_VERSION+ environment
1232
- # variable to provide a `git describe` value to beaker to create a
1233
- # build server URL. Note that +puppet_agent_sha+ will still be used
1234
- # instead of this if a value is provided for that option
1235
- # @option opts [String] :puppet_agent_sha The sha of puppet-agent to install, defaults to provided
1236
- # puppet_agent_version
1237
- # @option opts [String] :copy_base_local Directory where puppet-agent artifact
1238
- # will be stored locally
1239
- # (default: 'tmp/repo_configs')
1240
- # @option opts [String] :copy_dir_external Directory where puppet-agent
1241
- # artifact will be pushed to on the external machine
1242
- # (default: '/root')
1243
- # @option opts [String] :puppet_collection Defaults to 'PC1'
1244
- # @option opts [String] :dev_builds_url Base URL to pull artifacts from
1245
- # @option opts [String] :copy_base_local Directory where puppet-agent artifact
1246
- # will be stored locally
1247
- # (default: 'tmp/repo_configs')
1248
- # @option opts [String] :copy_dir_external Directory where puppet-agent
1249
- # artifact will be pushed to on the external machine
1250
- # (default: '/root')
1251
- #
1252
- # @note on windows, the +:ruby_arch+ host parameter can determine in addition
1253
- # to other settings whether the 32 or 64bit install is used
1254
- #
1255
- # @example
1256
- # install_puppet_agent_dev_repo_on(host, { :puppet_agent_sha => 'd3377feaeac173aada3a2c2cedd141eb610960a7', :puppet_agent_version => '1.1.1.225.gd3377fe' })
1257
- #
1258
- # @return nil
1259
- def install_puppet_agent_dev_repo_on( hosts, global_opts )
1260
-
1261
- global_opts[:puppet_agent_version] ||= global_opts[:version] #backward compatability
1262
- if not global_opts[:puppet_agent_version]
1263
- raise "must provide :puppet_agent_version (puppet-agent version) for install_puppet_agent_dev_repo_on"
1264
- end
1265
-
1266
- block_on hosts do |host|
1267
- opts = global_opts.dup
1268
-
1269
- # TODO consolidate these values as they serve no purpose from beaker's side
1270
- # you could provide any values you could to one to the other
1271
- puppet_agent_version = opts[:puppet_agent_sha] || opts[:puppet_agent_version]
1272
-
1273
- opts = sanitize_opts(opts)
1274
- opts[:download_url] = "#{opts[:dev_builds_url]}/puppet-agent/#{ puppet_agent_version }/repos/"
1275
- opts[:copy_base_local] ||= File.join('tmp', 'repo_configs')
1276
- opts[:puppet_collection] ||= 'PC1'
1277
-
1278
- release_path = opts[:download_url]
1279
-
1280
- variant, version, arch, codename = host['platform'].to_array
1281
- add_role(host, 'aio') #we are installing agent, so we want aio role
1282
- copy_dir_local = File.join(opts[:copy_base_local], variant)
1283
- onhost_copy_base = opts[:copy_dir_external] || host.external_copy_base
1284
-
1285
- case variant
1286
- when /^(fedora|el|redhat|centos|debian|ubuntu|cumulus|huaweios|cisco_nexus|cisco_ios_xr)$/
1287
- if arch== 's390x' || host['hypervisor'] == 'ec2'
1288
- logger.trace("#install_puppet_agent_dev_repo_on: unsupported host #{host} for repo detected. using dev package")
1289
- else
1290
- install_puppetlabs_dev_repo( host, 'puppet-agent', puppet_agent_version, nil, opts )
1291
- host.install_package('puppet-agent')
1292
- logger.trace("#install_puppet_agent_dev_repo_on: install_puppetlabs_dev_repo finished")
1293
- next
1294
- end
1295
- when /^(eos|osx|windows|solaris|sles|aix)$/
1296
- # Download installer package file & run install manually.
1297
- # Done below, so that el hosts with s390x arch or on ec2 can use this
1298
- # workflow as well
1299
- else
1300
- raise "No repository installation step for #{variant} yet..."
1301
- end
1302
-
1303
- release_path_end, release_file = host.puppet_agent_dev_package_info(
1304
- opts[:puppet_collection], opts[:puppet_agent_version], opts )
1305
- release_path << release_path_end
1306
- logger.trace("#install_puppet_agent_dev_repo_on: dev_package_info, continuing...")
1307
-
1308
- if variant =~ /eos/
1309
- host.get_remote_file( "#{release_path}/#{release_file}" )
1310
- else
1311
- onhost_copied_file = File.join(onhost_copy_base, release_file)
1312
- fetch_http_file( release_path, release_file, copy_dir_local)
1313
- scp_to host, File.join(copy_dir_local, release_file), onhost_copy_base
1314
- end
1315
-
1316
- case variant
1317
- when /^eos/
1318
- host.install_from_file( release_file )
1319
- when /^(sles|aix|fedora|el|redhat|centos)$/
1320
- # NOTE: AIX does not support repo management. This block assumes
1321
- # that the desired rpm has been mirrored to the 'repos' location.
1322
- # NOTE: the AIX 7.1 package will only install on 7.2 with
1323
- # --ignoreos. This is a bug in package building on AIX 7.1's RPM
1324
- if variant == "aix" && version == "7.2"
1325
- aix_72_ignoreos_hack = "--ignoreos"
1326
- end
1327
- on host, "rpm -ivh #{aix_72_ignoreos_hack} #{onhost_copied_file}"
1328
- when /^windows$/
1329
- result = on host, "echo #{onhost_copied_file}"
1330
- onhost_copied_file = result.raw_output.chomp
1331
- msi_opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
1332
- install_msi_on(host, onhost_copied_file, {}, msi_opts)
1333
- when /^osx$/
1334
- host.install_package("puppet-agent-#{opts[:puppet_agent_version]}*")
1335
- when /^solaris$/
1336
- host.solaris_install_local_package( release_file, onhost_copy_base )
1337
- end
1338
- configure_type_defaults_on( host )
1339
- end
1340
- end
1341
- alias_method :install_puppetagent_dev_repo, :install_puppet_agent_dev_repo_on
1342
-
1343
- # Install shared repo of the puppet-agent on the given host(s). Downloaded from
1344
- # location of the form PE_PROMOTED_BUILDS_URL/PE_VER/puppet-agent/AGENT_VERSION/repo
1345
- #
1346
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
1347
- # or a role (String or Symbol) that identifies one or more hosts.
1348
- # @param [Hash{Symbol=>String}] opts An options hash
1349
- # @option opts [String] :puppet_agent_version The version of puppet-agent to install, defaults to 'latest'
1350
- # @option opts [String] :pe_ver The version of PE (will also use host['pe_ver']), defaults to '4.0'
1351
- # @option opts [String] :copy_base_local Directory where puppet-agent artifact
1352
- # will be stored locally
1353
- # (default: 'tmp/repo_configs')
1354
- # @option opts [String] :copy_dir_external Directory where puppet-agent
1355
- # artifact will be pushed to on the external machine
1356
- # (default: '/root')
1357
- # @option opts [String] :puppet_collection Defaults to 'PC1'
1358
- # @option opts [String] :pe_promoted_builds_url Base URL to pull artifacts from
1359
- #
1360
- # @note on windows, the +:ruby_arch+ host parameter can determine in addition
1361
- # to other settings whether the 32 or 64bit install is used
1362
- #
1363
- # @example
1364
- # install_puppet_agent_pe_promoted_repo_on(host, { :puppet_agent_version => '1.1.0.227', :pe_ver => '4.0.0-rc1'})
1365
- #
1366
- # @return nil
1367
- def install_puppet_agent_pe_promoted_repo_on( hosts, opts )
1368
- opts[:puppet_agent_version] ||= 'latest'
1369
-
1370
- block_on hosts do |host|
1371
- pe_ver = host[:pe_ver] || opts[:pe_ver] || '4.0.0-rc1'
1372
- opts = sanitize_opts(opts)
1373
- opts[:download_url] = "#{opts[:pe_promoted_builds_url]}/puppet-agent/#{ pe_ver }/#{ opts[:puppet_agent_version] }/repos"
1374
- opts[:copy_base_local] ||= File.join('tmp', 'repo_configs')
1375
- opts[:copy_dir_external] ||= host.external_copy_base
1376
- opts[:puppet_collection] ||= puppet_collection_for(:puppet_agent, opts[:puppet_agent_version])
1377
- add_role(host, 'aio') #we are installing agent, so we want aio role
1378
- release_path = opts[:download_url]
1379
- variant, version, arch, codename = host['platform'].to_array
1380
- copy_dir_local = File.join(opts[:copy_base_local], variant)
1381
- onhost_copy_base = opts[:copy_dir_external]
1382
-
1383
- release_path_end, release_file, download_file =
1384
- host.pe_puppet_agent_promoted_package_info(
1385
- opts[:puppet_collection], opts
1386
- )
1387
- release_path << release_path_end
1388
-
1389
- onhost_copied_download = File.join(onhost_copy_base, download_file)
1390
- onhost_copied_file = File.join(onhost_copy_base, release_file)
1391
- fetch_http_file( release_path, download_file, copy_dir_local)
1392
- scp_to host, File.join(copy_dir_local, download_file), onhost_copy_base
1393
-
1394
- if variant == 'windows'
1395
- result = on host, "echo #{onhost_copied_file}"
1396
- onhost_copied_file = result.raw_output.chomp
1397
- opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
1398
- # couldn't pull this out, because it's relying on
1399
- # {Beaker::DSL::InstallUtils::WindowsUtils} methods,
1400
- # which I didn't want to attack right now. TODO
1401
- install_msi_on(host, onhost_copied_file, {}, opts)
1402
- else
1403
- host.pe_puppet_agent_promoted_package_install(
1404
- onhost_copy_base, onhost_copied_download,
1405
- onhost_copied_file, download_file, opts
1406
- )
1407
- end
1408
- configure_type_defaults_on( host )
1409
- end
1195
+ configure_type_defaults_on(host)
1410
1196
  end
1411
1197
 
1412
1198
  # This method will install a pem file certificate on a windows host
@@ -1472,9 +1258,7 @@ module Beaker
1472
1258
  host[:type] = :aio
1473
1259
 
1474
1260
  if opts[:version] == 'latest'
1475
- if opts[:nightlies]
1476
- release_stream += '-nightly' unless release_stream.end_with? "-nightly"
1477
- end
1261
+ release_stream += '-nightly' if opts[:nightlies] && !(release_stream.end_with? '-nightly')
1478
1262
 
1479
1263
  # Since we have modified the collection, we don't want to pass `latest`
1480
1264
  # in to `install_package` as the version. That'll fail. Instead, if
@@ -1485,7 +1269,7 @@ module Beaker
1485
1269
 
1486
1270
  # We have to do some silly version munging if we're on a deb-based platform
1487
1271
  case host['platform']
1488
- when /debian|ubuntu|cumulus|huaweios/
1272
+ when /debian|ubuntu|huaweios/
1489
1273
  opts[:version] = "#{opts[:version]}-1#{host['platform'].codename}" if opts[:version]
1490
1274
  end
1491
1275
 
@@ -1502,49 +1286,55 @@ module Beaker
1502
1286
  #
1503
1287
  # @return nil
1504
1288
  # @api public
1505
- def remove_puppet_on( hosts )
1289
+ def remove_puppet_on(hosts)
1506
1290
  block_on hosts do |host|
1507
1291
  cmdline_args = ''
1508
1292
  # query packages
1509
1293
  case host[:platform]
1510
- when /cumulus|huaweios|ubuntu/
1511
- pkgs = on(host, "dpkg-query -l | awk '{print $2}' | grep -E '(^pe-|puppet)'", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1294
+ when /huaweios|ubuntu/
1295
+ pkgs = on(host, "dpkg-query -l | awk '{print $2}' | grep -E '(^pe-|puppet)'",
1296
+ acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
1512
1297
  when /aix|sles|el|redhat|centos|oracle|scientific/
1513
- pkgs = on(host, "rpm -qa | grep -E '(^pe-|puppet)'", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1298
+ pkgs = on(host, "rpm -qa | grep -E '(^pe-|puppet)'",
1299
+ acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
1514
1300
  when /solaris-10/
1515
1301
  cmdline_args = '-a noask'
1516
- pkgs = on(host, "pkginfo | egrep '(^pe-|puppet)' | cut -f2 -d ' '", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1302
+ pkgs = on(host, "pkginfo | egrep '(^pe-|puppet)' | cut -f2 -d ' '",
1303
+ acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
1517
1304
  when /solaris-11/
1518
- pkgs = on(host, "pkg list | egrep '(^pe-|puppet)' | awk '{print $1}'", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1305
+ pkgs = on(host, "pkg list | egrep '(^pe-|puppet)' | awk '{print $1}'",
1306
+ acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
1519
1307
  else
1520
- raise "remove_puppet_on() called for unsupported " +
1308
+ raise 'remove_puppet_on() called for unsupported ' +
1521
1309
  "platform '#{host['platform']}' on '#{host.name}'"
1522
1310
  end
1523
1311
 
1524
1312
  # uninstall packages
1525
1313
  host.uninstall_package(pkgs.join(' '), cmdline_args) if pkgs.length > 0
1526
1314
 
1527
- if host[:platform] =~ /solaris-11/ then
1315
+ if host[:platform] =~ /solaris-11/
1528
1316
  # FIXME: This leaves things in a state where Puppet Enterprise (3.x) cannot be cleanly installed
1529
1317
  # but is required to put things in a state that puppet-agent can be installed
1530
1318
  # extra magic for expunging left over publisher
1531
1319
  publishers = ['puppetlabs.com', 'com.puppetlabs']
1532
1320
  publishers.each do |publisher|
1533
- if on(host, "pkg publisher #{publisher}", :acceptable_exit_codes => [0,1]).exit_code == 0 then
1534
- # First, try to remove the publisher altogether
1535
- if on(host, "pkg unset-publisher #{publisher}", :acceptable_exit_codes => [0,1]).exit_code == 1 then
1536
- # If that doesn't work, we're in a non-global zone and the
1537
- # publisher is from a global zone. As such, just remove any
1538
- # references to the non-global zone uri.
1539
- on(host, "pkg set-publisher -G '*' #{publisher}", :acceptable_exit_codes => [0,1])
1540
- end
1541
- end
1321
+ # First, try to remove the publisher altogether
1322
+ next unless on(host, "pkg publisher #{publisher}",
1323
+ acceptable_exit_codes: [0, 1]).exit_code == 0 && (on(host, "pkg unset-publisher #{publisher}",
1324
+ acceptable_exit_codes: [0, 1]).exit_code == 1)
1325
+
1326
+ # If that doesn't work, we're in a non-global zone and the
1327
+ # publisher is from a global zone. As such, just remove any
1328
+ # references to the non-global zone uri.
1329
+ on(host, "pkg set-publisher -G '*' #{publisher}", acceptable_exit_codes: [0, 1])
1542
1330
  end
1543
1331
  end
1544
1332
 
1545
1333
  # delete any residual files
1546
- on(host, 'find / -name "*puppet*" -print | xargs rm -rf')
1547
-
1334
+ result = on(host, 'find / -name "*puppet*" -print | xargs rm -rf', accept_all_exit_codes: true)
1335
+ unless result.exit_code == 0
1336
+ logger.notify("Attempt to clean residual puppet files errored, but can maybe be ignored.\n #{result.stderr}")
1337
+ end
1548
1338
  end
1549
1339
  end
1550
1340
 
@@ -1562,40 +1352,39 @@ module Beaker
1562
1352
  # @return true
1563
1353
  def install_packages_on(hosts, package_hash, options = {})
1564
1354
  platform_patterns = {
1565
- :redhat => /fedora|el-|centos/,
1566
- :debian => /debian|ubuntu|cumulus/,
1567
- :debian_ruby18 => /debian|ubuntu-lucid|ubuntu-precise/,
1568
- :solaris_10 => /solaris-10/,
1569
- :solaris_11 => /solaris-11/,
1570
- :windows => /windows/,
1571
- :eos => /^eos-/,
1572
- :sles => /sles/,
1355
+ redhat: /fedora|el-|centos/,
1356
+ debian: /debian|ubuntu/,
1357
+ debian_ruby18: /debian|ubuntu-lucid|ubuntu-precise/,
1358
+ solaris_10: /solaris-10/,
1359
+ solaris_11: /solaris-11/,
1360
+ windows: /windows/,
1361
+ eos: /^eos-/,
1362
+ sles: /sles/,
1573
1363
  }.freeze
1574
1364
 
1575
1365
  check_if_exists = options[:check_if_exists]
1576
1366
  Array(hosts).each do |host|
1577
- package_hash.each do |platform_key,package_list|
1578
- if pattern = platform_patterns[platform_key]
1579
- if pattern.match(host['platform'])
1580
- package_list.each do |cmd_pkg|
1581
- if cmd_pkg.kind_of?(Array)
1582
- command, package = cmd_pkg
1583
- else
1584
- command = package = cmd_pkg
1585
- end
1586
- if !check_if_exists || !host.check_for_package(command)
1587
- host.logger.notify("Installing #{package}")
1588
- additional_switches = '--allow-unauthenticated' if platform_key == :debian
1589
- host.install_package(package, additional_switches)
1590
- end
1591
- end
1592
- end
1593
- else
1367
+ package_hash.each do |platform_key, package_list|
1368
+ unless pattern = platform_patterns[platform_key]
1594
1369
  raise("Unknown platform '#{platform_key}' in package_hash")
1595
1370
  end
1371
+ next unless pattern.match(host['platform'])
1372
+
1373
+ package_list.each do |cmd_pkg|
1374
+ if cmd_pkg.is_a?(Array)
1375
+ command, package = cmd_pkg
1376
+ else
1377
+ command = package = cmd_pkg
1378
+ end
1379
+ next unless !check_if_exists || !host.check_for_package(command)
1380
+
1381
+ host.logger.notify("Installing #{package}")
1382
+ additional_switches = '--allow-unauthenticated' if platform_key == :debian
1383
+ host.install_package(package, additional_switches)
1384
+ end
1596
1385
  end
1597
1386
  end
1598
- return true
1387
+ true
1599
1388
  end
1600
1389
 
1601
1390
  def ruby_command(host)
@@ -1603,7 +1392,7 @@ module Beaker
1603
1392
  end
1604
1393
 
1605
1394
  def get_command(command_name, host, type = 'aio')
1606
- if ['aio', 'git'].include?(type)
1395
+ if %w[aio git].include?(type)
1607
1396
  if host['platform'] =~ /windows/
1608
1397
  "env PATH=\"#{host['privatebindir']}:${PATH}\" cmd /c #{command_name}"
1609
1398
  else
@@ -1625,18 +1414,18 @@ module Beaker
1625
1414
  # Configures gem sources on hosts to use a mirror, if specified
1626
1415
  # This is a duplicate of the Gemfile logic.
1627
1416
  def configure_gem_mirror(hosts)
1628
- gem_source = ENV['GEM_SOURCE']
1417
+ gem_source = ENV.fetch('GEM_SOURCE', nil)
1629
1418
 
1630
1419
  # Newer versions of rubygems always default the source to https://rubygems.org
1631
1420
  # and versions >= 3.1 will try to prompt (and fail) if you add a source that is
1632
1421
  # too similar to rubygems.org to prevent typo squatting:
1633
1422
  # https://github.com/rubygems/rubygems/commit/aa967b85dd96bbfb350f104125f23d617e82a00a
1634
- if gem_source && gem_source !~ /rubygems\.org/
1635
- Array(hosts).each do |host|
1636
- gem = gem_command(host)
1637
- on host, "#{gem} source --clear-all"
1638
- on(host, "#{gem} source --add #{gem_source}")
1639
- end
1423
+ return unless gem_source && gem_source !~ /rubygems\.org/
1424
+
1425
+ Array(hosts).each do |host|
1426
+ gem = gem_command(host)
1427
+ on host, "#{gem} source --clear-all"
1428
+ on(host, "#{gem} source --add #{gem_source}")
1640
1429
  end
1641
1430
  end
1642
1431
  end