beaker 3.18.0 → 3.19.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 (45) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +0 -23
  3. data/beaker.gemspec +1 -0
  4. data/lib/beaker/dsl/helpers.rb +3 -4
  5. data/lib/beaker/dsl/install_utils.rb +2 -7
  6. data/lib/beaker/dsl/wrappers.rb +0 -87
  7. data/lib/beaker/host/unix/pkg.rb +56 -17
  8. data/lib/beaker/hypervisor/docker.rb +26 -1
  9. data/lib/beaker/options/parser.rb +12 -5
  10. data/lib/beaker/options/subcommand_options_file_parser.rb +11 -4
  11. data/lib/beaker/ssh_connection.rb +6 -6
  12. data/lib/beaker/subcommand.rb +6 -0
  13. data/lib/beaker/version.rb +1 -1
  14. data/spec/beaker/host/unix/pkg_spec.rb +130 -0
  15. data/spec/beaker/hypervisor/docker_spec.rb +28 -1
  16. data/spec/beaker/options/parser_spec.rb +38 -18
  17. data/spec/beaker/options/subcommand_options_parser_spec.rb +28 -5
  18. data/spec/beaker/ssh_connection_spec.rb +17 -17
  19. metadata +16 -28
  20. data/acceptance/config/puppetgem/acceptance-options.rb +0 -9
  21. data/acceptance/config/puppetgit/acceptance-options.rb +0 -9
  22. data/acceptance/config/puppetpkg/acceptance-options.rb +0 -8
  23. data/acceptance/pre_suite/puppet_gem/install.rb +0 -8
  24. data/acceptance/pre_suite/puppet_git/install.rb +0 -98
  25. data/acceptance/pre_suite/puppet_pkg/install.rb +0 -9
  26. data/acceptance/tests/puppet/README.md +0 -3
  27. data/acceptance/tests/puppet/install_smoke_test.rb +0 -21
  28. data/acceptance/tests/puppet/stub_host.rb +0 -47
  29. data/acceptance/tests/puppet/web_helpers_test.rb +0 -55
  30. data/acceptance/tests/puppet/with_puppet_running_on.rb +0 -26
  31. data/lib/beaker/dsl/helpers/puppet_helpers.rb +0 -865
  32. data/lib/beaker/dsl/helpers/tk_helpers.rb +0 -89
  33. data/lib/beaker/dsl/install_utils/aio_defaults.rb +0 -93
  34. data/lib/beaker/dsl/install_utils/ezbake_utils.rb +0 -256
  35. data/lib/beaker/dsl/install_utils/foss_defaults.rb +0 -211
  36. data/lib/beaker/dsl/install_utils/foss_utils.rb +0 -1307
  37. data/lib/beaker/dsl/install_utils/module_utils.rb +0 -244
  38. data/lib/beaker/dsl/install_utils/puppet_utils.rb +0 -157
  39. data/lib/beaker/options/homedir_options_file_parser.rb +0 -0
  40. data/spec/beaker/dsl/helpers/facter_helpers_spec.rb +0 -59
  41. data/spec/beaker/dsl/helpers/puppet_helpers_spec.rb +0 -1179
  42. data/spec/beaker/dsl/helpers/tk_helpers_spec.rb +0 -83
  43. data/spec/beaker/dsl/install_utils/foss_utils_spec.rb +0 -1307
  44. data/spec/beaker/dsl/install_utils/module_utils_spec.rb +0 -261
  45. data/spec/beaker/dsl/install_utils/puppet_utils_spec.rb +0 -136
@@ -1,1307 +0,0 @@
1
- [ 'aio_defaults', 'foss_defaults', 'puppet_utils', 'windows_utils' ].each do |lib|
2
- require "beaker/dsl/install_utils/#{lib}"
3
- end
4
- module Beaker
5
- module DSL
6
- module InstallUtils
7
- #
8
- # This module contains methods to install FOSS puppet from various sources
9
- #
10
- # To mix this is into a class you need the following:
11
- # * a method *hosts* that yields any hosts implementing
12
- # {Beaker::Host}'s interface to act upon.
13
- # * a method *options* that provides an options hash, see {Beaker::Options::OptionsHash}
14
- # * the module {Beaker::DSL::Roles} that provides access to the various hosts implementing
15
- # {Beaker::Host}'s interface to act upon
16
- # * the module {Beaker::DSL::Wrappers} the provides convenience methods for {Beaker::DSL::Command} creation
17
- module FOSSUtils
18
- include AIODefaults
19
- include FOSSDefaults
20
- include PuppetUtils
21
- include WindowsUtils
22
-
23
- # The default install path
24
- SourcePath = "/opt/puppet-git-repos"
25
-
26
- # A regex to know if the uri passed is pointing to a git repo
27
- GitURI = %r{^(git|https?|file)://|^git@|^gitmirror@}
28
-
29
- # Github's ssh signature for cloning via ssh
30
- GitHubSig = 'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
31
-
32
- # lookup project-specific git environment variables
33
- # PROJECT_VAR or VAR otherwise return the default
34
- #
35
- # @!visibility private
36
- def lookup_in_env(env_variable_name, project_name=nil, default=nil)
37
- env_variable_name = "#{env_variable_name.upcase.gsub('-','_')}"
38
- project_specific_name = "#{project_name.upcase.gsub('-','_')}_#{env_variable_name}" if project_name
39
- project_name && ENV[project_specific_name] || ENV[env_variable_name] || default
40
- end
41
-
42
- # @param [String] project_name
43
- # @param [String] git_fork When not provided will use PROJECT_FORK environment variable
44
- # @param [String] git_server When not provided will use PROJECT_SERVER environment variable
45
- # @param [String] git_protocol 'git','ssh','https'
46
- #
47
- # @return [String] Returns a git-usable url
48
- #
49
- # TODO: enable other protocols, clarify, http://git-scm.com/book/ch4-1.html
50
- def build_git_url(project_name, git_fork = nil, git_server = nil, git_protocol='https')
51
- git_fork ||= lookup_in_env('FORK', project_name, 'puppetlabs')
52
- git_server ||= lookup_in_env('SERVER', project_name, 'github.com')
53
-
54
- case git_protocol
55
- when /(ssh|git)/
56
- git_protocol = 'git@'
57
- when /https/
58
- git_protocol = 'https://'
59
- end
60
-
61
- repo = (git_server == 'github.com') ? "#{git_fork}/#{project_name}.git" : "#{git_fork}-#{project_name}.git"
62
- return git_protocol == 'git@' ? "#{git_protocol}#{git_server}:#{repo}" : "#{git_protocol}#{git_server}/#{repo}"
63
- end
64
- alias_method :build_giturl, :build_git_url
65
-
66
- # @param [String] uri A uri in the format of <git uri>#<revision>
67
- # the `git://`, `http://`, `https://`, and ssh
68
- # (if cloning as the remote git user) protocols
69
- # are valid for <git uri>
70
- #
71
- # @example Usage
72
- # project = extract_repo_info_from 'git@github.com:puppetlabs/SuperSecretSauce#what_is_justin_doing'
73
- #
74
- # puts project[:name]
75
- # #=> 'SuperSecretSauce'
76
- #
77
- # puts project[:rev]
78
- # #=> 'what_is_justin_doing'
79
- #
80
- # @return [Hash{Symbol=>String}] Returns a hash containing the project
81
- # name, repository path, and revision
82
- # (defaults to HEAD)
83
- #
84
- def extract_repo_info_from uri
85
- require 'pathname'
86
- project = {}
87
- repo, rev = uri.split('#', 2)
88
- project[:name] = Pathname.new(repo).basename('.git').to_s
89
- project[:path] = repo
90
- project[:rev] = rev || 'HEAD'
91
- return project
92
- end
93
-
94
- # Takes an array of package info hashes (like that returned from
95
- # {#extract_repo_info_from}) and sorts the `puppet`, `facter`, `hiera`
96
- # packages so that puppet's dependencies will be installed first.
97
- #
98
- # @!visibility private
99
- def order_packages packages_array
100
- puppet = packages_array.select {|e| e[:name] == 'puppet' }
101
- puppet_depends_on = packages_array.select do |e|
102
- e[:name] == 'hiera' or e[:name] == 'facter'
103
- end
104
- depends_on_puppet = (packages_array - puppet) - puppet_depends_on
105
- [puppet_depends_on, puppet, depends_on_puppet].flatten
106
- end
107
-
108
- # @param [Host] host An object implementing {Beaker::Hosts}'s
109
- # interface.
110
- # @param [String] path The path on the remote [host] to the repository
111
- # @param [Hash{Symbol=>String}] repository A hash representing repo
112
- # info like that emitted by
113
- # {#extract_repo_info_from}
114
- #
115
- # @example Getting multiple project versions
116
- # versions = [puppet_repo, facter_repo, hiera_repo].inject({}) do |vers, repo_info|
117
- # vers.merge(find_git_repo_versions(host, '/opt/git-puppet-repos', repo_info) )
118
- # end
119
- # @return [Hash] Executes git describe on [host] and returns a Hash
120
- # with the key of [repository[:name]] and value of
121
- # the output from git describe.
122
- #
123
- # @note This requires the helper methods:
124
- # * {Beaker::DSL::Helpers#on}
125
- #
126
- def find_git_repo_versions host, path, repository
127
- logger.notify("\n * Grab version for #{repository[:name]}")
128
-
129
- version = {}
130
- on host, "cd #{path}/#{repository[:name]} && " +
131
- "git describe || true" do
132
- version[repository[:name]] = stdout.chomp
133
- end
134
-
135
- version
136
- end
137
-
138
- # @param [Host] host An object implementing {Beaker::Hosts}'s
139
- # interface.
140
- # @param [String] path The path on the remote [host] to the repository
141
- # @param [Hash{Symbol=>String}] repository A hash representing repo
142
- # info like that emitted by
143
- # {#extract_repo_info_from}
144
- #
145
- # @note This requires the helper methods:
146
- # * {Beaker::DSL::Helpers#on}
147
- #
148
- def clone_git_repo_on host, path, repository, opts = {}
149
- opts = {:accept_all_exit_codes => true}.merge(opts)
150
- name = repository[:name]
151
- repo = repository[:path]
152
- rev = repository[:rev]
153
- depth = repository[:depth]
154
- depth_branch = repository[:depth_branch]
155
- target = "#{path}/#{name}"
156
-
157
- if (depth_branch.nil?)
158
- depth_branch = rev
159
- end
160
-
161
- clone_cmd = "git clone #{repo} #{target}"
162
- if (depth)
163
- clone_cmd = "git clone --branch #{depth_branch} --depth #{depth} #{repo} #{target}"
164
- end
165
-
166
- logger.notify("\n * Clone #{repo} if needed")
167
-
168
- on host, "test -d #{path} || mkdir -p #{path}", opts
169
- on host, "test -d #{target} || #{clone_cmd}", opts
170
-
171
- logger.notify("\n * Update #{name} and check out revision #{rev}")
172
- commands = ["cd #{target}",
173
- "remote rm origin",
174
- "remote add origin #{repo}",
175
- "fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*",
176
- "clean -fdx",
177
- "checkout -f #{rev}"]
178
- on host, commands.join(" && git "), opts
179
- end
180
-
181
- # @see #find_git_repo_versions
182
- # @note This assumes the target repository application
183
- # can be installed via an install.rb ruby script.
184
- def install_from_git_on host, path, repository, opts = {}
185
- opts = {:accept_all_exit_codes => true}.merge(opts)
186
- clone_git_repo_on host, path, repository, opts
187
- name = repository[:name]
188
- logger.notify("\n * Install #{name} on the system")
189
- # The solaris ruby IPS package has bindir set to /usr/ruby/1.8/bin.
190
- # However, this is not the path to which we want to deliver our
191
- # binaries. So if we are using solaris, we have to pass the bin and
192
- # sbin directories to the install.rb
193
- target = "#{path}/#{name}"
194
- install_opts = ''
195
- install_opts = '--bindir=/usr/bin --sbindir=/usr/sbin' if host['platform'].include? 'solaris'
196
-
197
- on host, "cd #{target} && " +
198
- "if [ -f install.rb ]; then " +
199
- "ruby ./install.rb #{install_opts}; " +
200
- "else true; fi", opts
201
- end
202
- alias_method :install_from_git, :install_from_git_on
203
-
204
- # @deprecated Use {#install_puppet_on} instead.
205
- def install_puppet(opts = {})
206
- #send in the global hosts!
207
- install_puppet_on(hosts, opts)
208
- end
209
-
210
- #Install FOSS based on specified hosts using provided options
211
- # @example will install puppet 3.6.1 from native puppetlabs provided packages wherever possible and will fail over to gem installation when impossible
212
- # install_puppet_on(hosts, {
213
- # :version => '3.6.1',
214
- # :facter_version => '2.0.1',
215
- # :hiera_version => '1.3.3',
216
- # :default_action => 'gem_install',
217
- # })
218
- #
219
- # @example will install puppet 4 from native puppetlabs provided puppet-agent 1.x package wherever possible and will fail over to gem installation when impossible
220
- # install_puppet({
221
- # :version => '4',
222
- # :default_action => 'gem_install'
223
- # })
224
- #
225
- # @example will install puppet 4.1.0 from native puppetlabs provided puppet-agent 1.1.0 package wherever possible and will fail over to gem installation when impossible
226
- # install_puppet({
227
- # :version => '4.1.0',
228
- # :puppet_agent_version => '1.1.0',
229
- # :default_action => 'gem_install'
230
- # })
231
- #
232
- #
233
- #
234
- # @example Will install latest packages on Enterprise Linux and Debian based distros and fail hard on all othere platforms.
235
- # install_puppet_on(hosts)
236
- #
237
- # @note This will attempt to add a repository for apt.puppetlabs.com on
238
- # Debian, Ubuntu, or Cumulus machines, or yum.puppetlabs.com on EL or Fedora
239
- # machines, then install the package 'puppet' or 'puppet-agent'.
240
- #
241
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
242
- # or a role (String or Symbol) that identifies one or more hosts.
243
- # @param [Hash{Symbol=>String}] opts
244
- # @option opts [String] :version Version of puppet to download
245
- # @option opts [String] :puppet_agent_version Version of puppet agent to download
246
- # @option opts [String] :mac_download_url Url to download msi pattern of %url%/puppet-%version%.msi
247
- # @option opts [String] :win_download_url Url to download dmg pattern of %url%/(puppet|hiera|facter)-%version%.msi
248
- # @option opts [Boolean] :run_in_parallel Whether to install on all hosts in parallel. Defaults to false.
249
- #
250
- # @return nil
251
- # @raise [StandardError] When encountering an unsupported platform by default, or if gem cannot be found when default_action => 'gem_install'
252
- # @raise [FailTest] When error occurs during the actual installation process
253
- def install_puppet_on(hosts, opts={})
254
- opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
255
-
256
- # If version isn't specified assume the latest in the 3.x series
257
- if opts[:version] and not version_is_less(opts[:version], '4.0.0')
258
- # backwards compatability
259
- opts[:puppet_agent_version] ||= opts[:version]
260
- install_puppet_agent_on(hosts, opts)
261
- else
262
- # Use option specified in the method call, otherwise check whether the global
263
- # run_in_parallel option includes install
264
- run_in_parallel = run_in_parallel? opts, @options, 'install'
265
- block_on hosts, { :run_in_parallel => run_in_parallel } do |host|
266
- if host['platform'] =~ /el-(5|6|7)/
267
- relver = $1
268
- install_puppet_from_rpm_on(host, opts.merge(:release => relver, :family => 'el'))
269
- elsif host['platform'] =~ /fedora-(\d+)/
270
- relver = $1
271
- install_puppet_from_rpm_on(host, opts.merge(:release => relver, :family => 'fedora'))
272
- elsif host['platform'] =~ /(ubuntu|debian|cumulus|huaweios)/
273
- install_puppet_from_deb_on(host, opts)
274
- elsif host['platform'] =~ /windows/
275
- relver = opts[:version]
276
- install_puppet_from_msi_on(host, opts)
277
- elsif host['platform'] =~ /osx/
278
- install_puppet_from_dmg_on(host, opts)
279
- elsif host['platform'] =~ /openbsd/
280
- install_puppet_from_openbsd_packages_on(host, opts)
281
- elsif host['platform'] =~ /freebsd/
282
- install_puppet_from_freebsd_ports_on(host, opts)
283
- elsif host['platform'] =~ /archlinux/
284
- install_puppet_from_pacman_on(host, opts)
285
- else
286
- if opts[:default_action] == 'gem_install'
287
- opts[:version] ||= '~> 3.x'
288
- install_puppet_from_gem_on(host, opts)
289
- else
290
- raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'"
291
- end
292
- end
293
-
294
- host[:version] = opts[:version]
295
-
296
- # Certain install paths may not create the config dirs/files needed
297
- host.mkdir_p host['puppetpath'] unless host[:type] =~ /aio/
298
-
299
- if ((host['platform'] =~ /windows/) and not host.is_cygwin?)
300
- # Do nothing
301
- else
302
- on host, "echo '' >> #{host.puppet['hiera_config']}"
303
- end
304
- end
305
- end
306
-
307
- nil
308
- end
309
-
310
- #Install Puppet Agent based on specified hosts using provided options
311
- # @example will install puppet-agent 1.1.0 from native puppetlabs provided packages wherever possible and will fail over to gem installing latest puppet
312
- # install_puppet_agent_on(hosts, {
313
- # :puppet_agent_version => '1.1.0',
314
- # :default_action => 'gem_install',
315
- # })
316
- #
317
- #
318
- # @example Will install latest packages on Enterprise Linux, Debian based distros, Windows, OSX and fail hard on all othere platforms.
319
- # install_puppet_agent_on(hosts)
320
- #
321
- # @note This will attempt to add a repository for apt.puppetlabs.com on
322
- # Debian, Ubuntu, or Cumulus machines, or yum.puppetlabs.com on EL or Fedora
323
- # machines, then install the package 'puppet-agent'.
324
- #
325
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
326
- # or a role (String or Symbol) that identifies one or more hosts.
327
- # @param [Hash{Symbol=>String}] opts
328
- # @option opts [String] :puppet_agent_version Version of puppet to download
329
- # @option opts [String] :puppet_gem_version Version of puppet to install via gem if no puppet-agent package is available
330
- # @option opts [String] :mac_download_url Url to download msi pattern of %url%/puppet-agent-%version%.msi
331
- # @option opts [String] :win_download_url Url to download dmg pattern of %url%/puppet-agent-%version%.msi
332
- # @option opts [String] :puppet_collection Defaults to 'pc1'
333
- # @option opts [Boolean] :run_in_parallel Whether to run on each host in parallel.
334
- #
335
- # @return nil
336
- # @raise [StandardError] When encountering an unsupported platform by default, or if gem cannot be found when default_action => 'gem_install'
337
- # @raise [FailTest] When error occurs during the actual installation process
338
- def install_puppet_agent_on(hosts, opts = {})
339
- opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
340
- opts[:puppet_collection] ||= 'pc1' #hi! i'm case sensitive! be careful!
341
- opts[:puppet_agent_version] ||= opts[:version] #backwards compatability with old parameter name
342
-
343
- run_in_parallel = run_in_parallel? opts, @options, 'install'
344
- block_on hosts, { :run_in_parallel => run_in_parallel } do |host|
345
- add_role(host, 'aio') #we are installing agent, so we want aio role
346
- package_name = nil
347
- case host['platform']
348
- when /el-|fedora|sles|centos|cisco_/
349
- package_name = 'puppet-agent'
350
- package_name << "-#{opts[:puppet_agent_version]}" if opts[:puppet_agent_version]
351
- when /debian|ubuntu|cumulus|huaweios/
352
- package_name = 'puppet-agent'
353
- package_name << "=#{opts[:puppet_agent_version]}-1#{host['platform'].codename}" if opts[:puppet_agent_version]
354
- when /windows/
355
- install_puppet_agent_from_msi_on(host, opts)
356
- when /osx/
357
- install_puppet_agent_from_dmg_on(host, opts)
358
- else
359
- if opts[:default_action] == 'gem_install'
360
- opts[:version] = opts[:puppet_gem_version]
361
- install_puppet_from_gem_on(host, opts)
362
- on host, "echo '' >> #{host.puppet['hiera_config']}"
363
- else
364
- raise "install_puppet_agent_on() called for unsupported " +
365
- "platform '#{host['platform']}' on '#{host.name}'"
366
- end
367
- end
368
-
369
- if package_name
370
- install_puppetlabs_release_repo( host, opts[:puppet_collection] )
371
- host.install_package( package_name )
372
- end
373
- end
374
- end
375
-
376
- # @deprecated Use {#configure_puppet_on} instead.
377
- def configure_puppet(opts={})
378
- hosts.each do |host|
379
- configure_puppet_on(host,opts)
380
- end
381
- end
382
-
383
- # Configure puppet.conf on the given host(s) based upon a provided hash
384
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
385
- # or a role (String or Symbol) that identifies one or more hosts.
386
- # @param [Hash{Symbol=>String}] opts
387
- # @option opts [Hash{String=>String}] :main configure the main section of puppet.conf
388
- # @option opts [Hash{String=>String}] :agent configure the agent section of puppet.conf
389
- # @option opts [Boolean] :run_in_parallel Whether to run on each host in parallel.
390
- #
391
- # @example will configure /etc/puppet.conf on the puppet master.
392
- # config = {
393
- # 'main' => {
394
- # 'server' => 'testbox.test.local',
395
- # 'certname' => 'testbox.test.local',
396
- # 'logdir' => '/var/log/puppet',
397
- # 'vardir' => '/var/lib/puppet',
398
- # 'ssldir' => '/var/lib/puppet/ssl',
399
- # 'rundir' => '/var/run/puppet'
400
- # },
401
- # 'agent' => {
402
- # 'environment' => 'dev'
403
- # }
404
- # }
405
- # configure_puppet_on(master, config)
406
- #
407
- # @return nil
408
- def configure_puppet_on(hosts, opts = {})
409
- puppet_conf_text = ''
410
- opts.each do |section,options|
411
- puppet_conf_text << "[#{section}]\n"
412
- options.each do |option,value|
413
- puppet_conf_text << "#{option}=#{value}\n"
414
- end
415
- puppet_conf_text << "\n"
416
- end
417
- logger.debug( "setting config '#{puppet_conf_text}' on hosts #{hosts}" )
418
- block_on hosts, opts do |host|
419
- puppet_conf_path = host.puppet['config']
420
- create_remote_file(host, puppet_conf_path, puppet_conf_text)
421
- end
422
- end
423
-
424
- # Installs Puppet and dependencies using rpm on provided host(s).
425
- #
426
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
427
- # or a role (String or Symbol) that identifies one or more hosts.
428
- # @param [Hash{Symbol=>String}] opts An options hash
429
- # @option opts [String] :version The version of Puppet to install, if nil installs latest version
430
- # @option opts [String] :facter_version The version of Facter to install, if nil installs latest version
431
- # @option opts [String] :hiera_version The version of Hiera to install, if nil installs latest version
432
- # @option opts [String] :release The major release of the OS
433
- # @option opts [String] :family The OS family (one of 'el' or 'fedora')
434
- #
435
- # @return nil
436
- # @api private
437
- def install_puppet_from_rpm_on( hosts, opts )
438
- block_on hosts do |host|
439
- if host[:type] == 'aio'
440
- install_puppetlabs_release_repo(host,'pc1',opts)
441
- else
442
- install_puppetlabs_release_repo(host,nil,opts)
443
- end
444
-
445
- if opts[:facter_version]
446
- host.install_package("facter-#{opts[:facter_version]}")
447
- end
448
-
449
- if opts[:hiera_version]
450
- host.install_package("hiera-#{opts[:hiera_version]}")
451
- end
452
-
453
- puppet_pkg = opts[:version] ? "puppet-#{opts[:version]}" : 'puppet'
454
- host.install_package("#{puppet_pkg}")
455
- configure_type_defaults_on( host )
456
- end
457
- end
458
- alias_method :install_puppet_from_rpm, :install_puppet_from_rpm_on
459
-
460
- # Installs Puppet and dependencies from deb on provided host(s).
461
- #
462
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
463
- # or a role (String or Symbol) that identifies one or more hosts.
464
- # @param [Hash{Symbol=>String}] opts An options hash
465
- # @option opts [String] :version The version of Puppet to install, if nil installs latest version
466
- # @option opts [String] :facter_version The version of Facter to install, if nil installs latest version
467
- # @option opts [String] :hiera_version The version of Hiera to install, if nil installs latest version
468
- #
469
- # @return nil
470
- # @api private
471
- def install_puppet_from_deb_on( hosts, opts )
472
- block_on hosts do |host|
473
- install_puppetlabs_release_repo(host)
474
-
475
- if opts[:facter_version]
476
- host.install_package("facter=#{opts[:facter_version]}-1puppetlabs1")
477
- end
478
-
479
- if opts[:hiera_version]
480
- host.install_package("hiera=#{opts[:hiera_version]}-1puppetlabs1")
481
- end
482
-
483
- if opts[:version]
484
- host.install_package("puppet-common=#{opts[:version]}-1puppetlabs1")
485
- host.install_package("puppet=#{opts[:version]}-1puppetlabs1")
486
- else
487
- host.install_package('puppet')
488
- end
489
- configure_type_defaults_on( host )
490
- end
491
- end
492
- alias_method :install_puppet_from_deb, :install_puppet_from_deb_on
493
-
494
- # Installs Puppet and dependencies from msi on provided host(s).
495
- #
496
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
497
- # or a role (String or Symbol) that identifies one or more hosts.
498
- # @param [Hash{Symbol=>String}] opts An options hash
499
- # @option opts [String] :version The version of Puppet to install
500
- # @option opts [String] :puppet_agent_version The version of the
501
- # puppet-agent package to install, required if version is 4.0.0 or greater
502
- # @option opts [String] :win_download_url The url to download puppet from
503
- #
504
- # @note on windows, the +:ruby_arch+ host parameter can determine in addition
505
- # to other settings whether the 32 or 64bit install is used
506
- def install_puppet_from_msi_on( hosts, opts )
507
- block_on hosts do |host|
508
- version = opts[:version]
509
-
510
- if version && !version_is_less(version, '4.0.0')
511
- if opts[:puppet_agent_version].nil?
512
- raise "You must specify the version of puppet agent you " +
513
- "want to install if you want to install Puppet 4.0 " +
514
- "or greater on Windows"
515
- end
516
-
517
- opts[:version] = opts[:puppet_agent_version]
518
- install_puppet_agent_from_msi_on(host, opts)
519
-
520
- else
521
- compute_puppet_msi_name(host, opts)
522
- install_a_puppet_msi_on(host, opts)
523
-
524
- end
525
- configure_type_defaults_on( host )
526
- end
527
- end
528
- alias_method :install_puppet_from_msi, :install_puppet_from_msi_on
529
-
530
- # @api private
531
- def compute_puppet_msi_name(host, opts)
532
- version = opts[:version]
533
- install_32 = host['install_32'] || opts['install_32']
534
- less_than_3_dot_7 = version && version_is_less(version, '3.7')
535
-
536
- # If there's no version declared, install the latest in the 3.x series
537
- if not version
538
- if !host.is_x86_64? || install_32
539
- host['dist'] = 'puppet-latest'
540
- else
541
- host['dist'] = 'puppet-x64-latest'
542
- end
543
-
544
- # Install Puppet 3.x with the x86 installer if:
545
- # - we are on puppet < 3.7, or
546
- # - we are less than puppet 4.0 and on an x86 host, or
547
- # - we have install_32 set on host or globally
548
- # Install Puppet 3.x with the x64 installer if:
549
- # - we are otherwise trying to install Puppet 3.x on a x64 host
550
- elsif less_than_3_dot_7 or not host.is_x86_64? or install_32
551
- host['dist'] = "puppet-#{version}"
552
-
553
- elsif host.is_x86_64?
554
- host['dist'] = "puppet-#{version}-x64"
555
-
556
- else
557
- raise "I don't understand how to install Puppet version: #{version}"
558
- end
559
- end
560
-
561
- # Installs Puppet Agent and dependencies from msi on provided host(s).
562
- #
563
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
564
- # or a role (String or Symbol) that identifies one or more hosts.
565
- # @param [Hash{Symbol=>String}] opts An options hash
566
- # @option opts [String] :puppet_agent_version The version of Puppet Agent to install
567
- # @option opts [String] :win_download_url The url to download puppet from
568
- #
569
- # @note on windows, the +:ruby_arch+ host parameter can determine in addition
570
- # to other settings whether the 32 or 64bit install is used
571
- def install_puppet_agent_from_msi_on(hosts, opts)
572
- block_on hosts do |host|
573
-
574
- add_role(host, 'aio') #we are installing agent, so we want aio role
575
- is_config_32 = true == (host['ruby_arch'] == 'x86') || host['install_32'] || opts['install_32']
576
- should_install_64bit = host.is_x86_64? && !is_config_32
577
- arch = should_install_64bit ? 'x64' : 'x86'
578
-
579
- # If we don't specify a version install the latest MSI for puppet-agent
580
- if opts[:puppet_agent_version]
581
- host['dist'] = "puppet-agent-#{opts[:puppet_agent_version]}-#{arch}"
582
- else
583
- host['dist'] = "puppet-agent-#{arch}-latest"
584
- end
585
-
586
- install_a_puppet_msi_on(host, opts)
587
- end
588
- end
589
-
590
- # @api private
591
- def install_a_puppet_msi_on(hosts, opts)
592
- block_on hosts do |host|
593
- link = "#{opts[:win_download_url]}/#{host['dist']}.msi"
594
- if not link_exists?( link )
595
- raise "Puppet MSI at #{link} does not exist!"
596
- end
597
-
598
-
599
- msi_download_path = "#{host.system_temp_path}\\#{host['dist']}.msi"
600
-
601
- if host.is_cygwin?
602
- # NOTE: it is critical that -o be before -O on Windows
603
- on host, "curl -o \"#{msi_download_path}\" -O #{link}"
604
-
605
- #Because the msi installer doesn't add Puppet to the environment path
606
- #Add both potential paths for simplicity
607
- #NOTE - this is unnecessary if the host has been correctly identified as 'foss' during set up
608
- puppetbin_path = "\"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin\":\"/cygdrive/c/Program Files/Puppet Labs/Puppet/bin\""
609
- on host, %Q{ echo 'export PATH=$PATH:#{puppetbin_path}' > /etc/bash.bashrc }
610
- else
611
- on host, powershell("$webclient = New-Object System.Net.WebClient; $webclient.DownloadFile('#{link}','#{msi_download_path}')")
612
- end
613
-
614
- opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
615
- install_msi_on(host, msi_download_path, {}, opts)
616
-
617
- configure_type_defaults_on( host )
618
- if not host.is_cygwin?
619
- host.mkdir_p host['distmoduledir']
620
- end
621
- end
622
- end
623
-
624
- # Installs Puppet and dependencies from FreeBSD ports
625
- #
626
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
627
- # or a role (String or Symbol) that identifies one or more hosts.
628
- # @param [Hash{Symbol=>String}] opts An options hash
629
- # @option opts [String] :version The version of Puppet to install (shows warning)
630
- #
631
- # @return nil
632
- # @api private
633
- def install_puppet_from_freebsd_ports_on( hosts, opts )
634
- if (opts[:version])
635
- logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
636
- end
637
-
638
- block_on hosts do |host|
639
- if host['platform'] =~ /freebsd-9/
640
- host.install_package("puppet")
641
- else
642
- host.install_package("sysutils/puppet")
643
- end
644
- end
645
-
646
- end
647
- alias_method :install_puppet_from_freebsd_ports, :install_puppet_from_freebsd_ports_on
648
-
649
- # Installs Puppet and dependencies from dmg on provided host(s).
650
- #
651
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
652
- # or a role (String or Symbol) that identifies one or more hosts.
653
- # @param [Hash{Symbol=>String}] opts An options hash
654
- # @option opts [String] :version The version of Puppet to install
655
- # @option opts [String] :puppet_version The version of puppet-agent to install
656
- # @option opts [String] :facter_version The version of Facter to install
657
- # @option opts [String] :hiera_version The version of Hiera to install
658
- # @option opts [String] :mac_download_url Url to download msi pattern of %url%/puppet-%version%.msi
659
- #
660
- # @return nil
661
- # @api private
662
- def install_puppet_from_dmg_on( hosts, opts )
663
- block_on hosts do |host|
664
- # install puppet-agent if puppet version > 4.0 OR not puppet version is provided
665
- if (opts[:version] && !version_is_less(opts[:version], '4.0.0')) || !opts[:version]
666
- if opts[:puppet_agent_version].nil?
667
- raise "You must specify the version of puppet-agent you " +
668
- "want to install if you want to install Puppet 4.0 " +
669
- "or greater on OSX"
670
- end
671
-
672
- install_puppet_agent_from_dmg_on(host, opts)
673
-
674
- else
675
- puppet_ver = opts[:version] || 'latest'
676
- facter_ver = opts[:facter_version] || 'latest'
677
- hiera_ver = opts[:hiera_version] || 'latest'
678
-
679
- if [puppet_ver, facter_ver, hiera_ver].include?(nil)
680
- 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',})"
681
- end
682
-
683
- on host, "curl -O #{opts[:mac_download_url]}/puppet-#{puppet_ver}.dmg"
684
- on host, "curl -O #{opts[:mac_download_url]}/facter-#{facter_ver}.dmg"
685
- on host, "curl -O #{opts[:mac_download_url]}/hiera-#{hiera_ver}.dmg"
686
-
687
- host.install_package("puppet-#{puppet_ver}")
688
- host.install_package("facter-#{facter_ver}")
689
- host.install_package("hiera-#{hiera_ver}")
690
-
691
- configure_type_defaults_on( host )
692
- end
693
- end
694
- end
695
- alias_method :install_puppet_from_dmg, :install_puppet_from_dmg_on
696
-
697
- # Installs puppet-agent and dependencies from dmg on provided host(s).
698
- #
699
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
700
- # or a role (String or Symbol) that identifies one or more hosts.
701
- # @param [Hash{Symbol=>String}] opts An options hash
702
- # @option opts [String] :puppet_agent_version The version of Puppet Agent to install, defaults to latest
703
- # @option opts [String] :mac_download_url Url to download msi pattern of %url%/puppet-%version%.dmg
704
- # @option opts [String] :puppet_collection Defaults to 'PC1'
705
- #
706
- # @return nil
707
- # @api private
708
- def install_puppet_agent_from_dmg_on(hosts, opts)
709
- opts[:puppet_collection] ||= 'PC1'
710
- opts[:puppet_collection] = opts[:puppet_collection].upcase #needs to be upcase, more lovely consistency
711
- block_on hosts do |host|
712
-
713
- add_role(host, 'aio') #we are installing agent, so we want aio role
714
-
715
- variant, version, arch, codename = host['platform'].to_array
716
-
717
- download_url = "#{opts[:mac_download_url]}/#{version}/#{opts[:puppet_collection]}/#{arch}"
718
-
719
- latest = get_latest_puppet_agent_build_from_url(download_url)
720
-
721
- agent_version = opts[:puppet_agent_version] || latest
722
- unless agent_version.length > 0
723
- raise "no puppet-agent version specified or found on at #{download_url}"
724
- end
725
-
726
- pkg_name = "puppet-agent-#{agent_version}*"
727
- dmg_name = "puppet-agent-#{agent_version}-1.osx#{version}.dmg"
728
- on host, "curl -O #{download_url}/#{dmg_name}"
729
-
730
- host.install_package(pkg_name)
731
-
732
- configure_type_defaults_on( host )
733
- end
734
- end
735
-
736
- # Returns the latest puppet-agent version number from a given url.
737
- #
738
- # @param [String] url URL containing list of puppet-agent packages.
739
- # Example: https://downloads.puppetlabs.com/mac/10.11/PC1/x86_64
740
- #
741
- # @return [String] version puppet-agent version number (e.g. 1.4.1)
742
- # Empty string if none found.
743
- # @api private
744
- def get_latest_puppet_agent_build_from_url(url)
745
- require 'nokogiri'
746
- require 'open-uri'
747
- page = Nokogiri::HTML(open("#{url}/?C=M;O=A"))
748
- agents = page.css('a').children.select{ |link| link.to_s.include? 'puppet-agent' }
749
- re = /puppet-agent-(.*)-1/
750
- latest_match = agents[-1].to_s.match re
751
- if latest_match
752
- latest = latest_match[1]
753
- else
754
- latest = ''
755
- end
756
- end
757
-
758
- # Installs Puppet and dependencies from OpenBSD packages
759
- #
760
- # @param [Host, Array<Host>, String, Symbol] hosts The host to install packages on
761
- # @param [Hash{Symbol=>String}] opts An options hash
762
- # @option opts [String] :version The version of Puppet to install (shows warning)
763
- #
764
- # @return nil
765
- # @api private
766
- def install_puppet_from_openbsd_packages_on(hosts, opts)
767
- if (opts[:version])
768
- logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
769
- end
770
-
771
- block_on hosts do |host|
772
- host.install_package('puppet')
773
-
774
- configure_type_defaults_on(host)
775
- end
776
- end
777
-
778
- # Installs Puppet and dependencies from Arch Linux Pacman
779
- #
780
- # @param [Host, Array<Host>, String, Symbol] hosts The host to install packages on
781
- # @param [Hash{Symbol=>String}] opts An options hash
782
- # @option opts [String] :version The version of Puppet to install (shows warning)
783
- #
784
- # @return nil
785
- # @api private
786
- def install_puppet_from_pacman_on(hosts, opts)
787
- if (opts[:version])
788
- # Arch is rolling release, only the latest package versions are supported
789
- logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
790
- end
791
-
792
- block_on hosts do |host|
793
- host.install_package('puppet')
794
-
795
- configure_type_defaults_on(host)
796
- end
797
- end
798
-
799
- # Installs Puppet and dependencies from gem on provided host(s)
800
- #
801
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
802
- # or a role (String or Symbol) that identifies one or more hosts.
803
- # @param [Hash{Symbol=>String}] opts An options hash
804
- # @option opts [String] :version The version of Puppet to install, if nil installs latest
805
- # @option opts [String] :facter_version The version of Facter to install, if nil installs latest
806
- # @option opts [String] :hiera_version The version of Hiera to install, if nil installs latest
807
- #
808
- # @return nil
809
- # @raise [StandardError] if gem does not exist on target host
810
- # @api private
811
- def install_puppet_from_gem_on( hosts, opts )
812
- block_on hosts do |host|
813
- # There are a lot of special things to do for Solaris and Solaris 10.
814
- # This is easier than checking host['platform'] every time.
815
- is_solaris10 = host['platform'] =~ /solaris-10/
816
- is_solaris = host['platform'] =~ /solaris/
817
-
818
- # Hosts may be provisioned with csw but pkgutil won't be in the
819
- # PATH by default to avoid changing the behavior for Puppet's tests
820
- if is_solaris10
821
- on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil'
822
- end
823
-
824
- # Solaris doesn't necessarily have this, but gem needs it
825
- if is_solaris
826
- on host, 'mkdir -p /var/lib'
827
- end
828
-
829
- unless host.check_for_command( 'gem' )
830
- gempkg = case host['platform']
831
- when /solaris-11/ then 'ruby-18'
832
- when /ubuntu-14/ then 'ruby'
833
- when /solaris-10|ubuntu|debian|el-|cumulus|huaweios/ then 'rubygems'
834
- when /openbsd/ then 'ruby'
835
- else
836
- raise "install_puppet() called with default_action " +
837
- "'gem_install' but program `gem' is " +
838
- "not installed on #{host.name}"
839
- end
840
-
841
- host.install_package gempkg
842
- end
843
-
844
- # Link 'gem' to /usr/bin instead of adding /opt/csw/bin to PATH.
845
- if is_solaris10
846
- on host, 'ln -s /opt/csw/bin/gem /usr/bin/gem'
847
- end
848
-
849
- if host['platform'] =~ /debian|ubuntu|solaris|cumulus|huaweios/
850
- gem_env = YAML.load( on( host, 'gem environment' ).stdout )
851
- gem_paths_array = gem_env['RubyGems Environment'].find {|h| h['GEM PATHS'] != nil }['GEM PATHS']
852
- path_with_gem = 'export PATH=' + gem_paths_array.join(':') + ':${PATH}'
853
- on host, "echo '#{path_with_gem}' >> ~/.bashrc"
854
- end
855
-
856
- gemflags = '--no-ri --no-rdoc --no-format-executable'
857
-
858
- if opts[:facter_version]
859
- on host, "gem install facter -v'#{opts[:facter_version]}' #{gemflags}"
860
- end
861
-
862
- if opts[:hiera_version]
863
- on host, "gem install hiera -v'#{opts[:hiera_version]}' #{gemflags}"
864
- end
865
-
866
- ver_cmd = opts[:version] ? "-v '#{opts[:version]}'" : ''
867
- on host, "gem install puppet #{ver_cmd} #{gemflags}"
868
-
869
- # Similar to the treatment of 'gem' above.
870
- # This avoids adding /opt/csw/bin to PATH.
871
- if is_solaris
872
- gem_env = YAML.load( on( host, 'gem environment' ).stdout )
873
- # This is the section we want - this has the dir where gem executables go.
874
- env_sect = 'EXECUTABLE DIRECTORY'
875
- # Get the directory where 'gem' installs executables.
876
- # On Solaris 10 this is usually /opt/csw/bin
877
- gem_exec_dir = gem_env['RubyGems Environment'].find {|h| h[env_sect] != nil }[env_sect]
878
-
879
- on host, "ln -s #{gem_exec_dir}/hiera /usr/bin/hiera"
880
- on host, "ln -s #{gem_exec_dir}/facter /usr/bin/facter"
881
- on host, "ln -s #{gem_exec_dir}/puppet /usr/bin/puppet"
882
- end
883
-
884
- # A gem install might not necessarily create these
885
- ['confdir', 'logdir', 'codedir'].each do |key|
886
- host.mkdir_p host.puppet[key] if host.puppet.has_key?(key)
887
- end
888
-
889
- configure_type_defaults_on( host )
890
- end
891
- end
892
- alias_method :install_puppet_from_gem, :install_puppet_from_gem_on
893
- alias_method :install_puppet_agent_from_gem_on, :install_puppet_from_gem_on
894
-
895
- # Install official puppetlabs release repository configuration on host(s).
896
- #
897
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
898
- # or a role (String or Symbol) that identifies one or more hosts.
899
- #
900
- # @note This method only works on redhat-like and debian-like hosts.
901
- #
902
- def install_puppetlabs_release_repo_on( hosts, repo = nil, opts = options )
903
- block_on hosts do |host|
904
- variant, version, arch, codename = host['platform'].to_array
905
- repo_name = repo.nil? ? '' : '-' + repo
906
- opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
907
-
908
- case variant
909
- when /^(fedora|el|centos|sles|cisco_nexus|cisco_ios_xr)$/
910
- variant_url_value = (($1 == 'centos') ? 'el' : $1)
911
- if variant == 'cisco_nexus'
912
- variant_url_value = 'cisco-wrlinux'
913
- version = '5'
914
- end
915
- if variant == 'cisco_ios_xr'
916
- variant_url_value = 'cisco-wrlinux'
917
- version = '7'
918
- end
919
- remote = "%s/puppetlabs-release%s-%s-%s.noarch.rpm" %
920
- [opts[:release_yum_repo_url], repo_name, variant_url_value, version]
921
-
922
- if variant == 'cisco_nexus'
923
- # cisco nexus requires using yum to install the repo
924
- host.install_package( remote )
925
- elsif variant == 'cisco_ios_xr'
926
- # cisco ios xr requires using yum to localinstall the repo
927
- on host, "yum -y localinstall #{remote}"
928
- else
929
- opts[:package_proxy] ||= false
930
- host.install_package_with_rpm( remote, '--replacepkgs',
931
- { :package_proxy => opts[:package_proxy] } )
932
- end
933
-
934
- when /^(debian|ubuntu|cumulus|huaweios)$/
935
- deb = "puppetlabs-release%s-%s.deb" % [repo_name, codename]
936
-
937
- remote = URI.join( opts[:release_apt_repo_url], deb )
938
-
939
- on host, "wget -O /tmp/puppet.deb #{remote}"
940
- on host, "dpkg -i --force-all /tmp/puppet.deb"
941
- on host, "apt-get update"
942
- else
943
- raise "No repository installation step for #{variant} yet..."
944
- end
945
- configure_type_defaults_on( host )
946
- end
947
- end
948
- alias_method :install_puppetlabs_release_repo, :install_puppetlabs_release_repo_on
949
-
950
- # Installs the repo configs on a given host
951
- #
952
- # @param [Beaker::Host] host Host to install configs on
953
- # @param [String] buildserver_url URL of the buildserver
954
- # @param [String] package_name Name of the package
955
- # @param [String] build_version Version of the package
956
- # @param [String] copy_dir Local directory to fetch files into & SCP out of
957
- #
958
- # @return nil
959
- def install_repo_configs(host, buildserver_url, package_name, build_version, copy_dir)
960
- repo_filename = host.repo_filename( package_name, build_version )
961
- repo_config_folder_url = "%s/%s/%s/repo_configs/%s/" %
962
- [ buildserver_url, package_name, build_version, host.repo_type ]
963
-
964
- repo = fetch_http_file( repo_config_folder_url,
965
- repo_filename,
966
- copy_dir )
967
-
968
- if host[:platform] =~ /cisco_nexus/
969
- to_path = "#{host.package_config_dir}/#{File.basename(repo)}"
970
- else
971
- to_path = host.package_config_dir
972
- end
973
- scp_to( host, repo, to_path )
974
-
975
- on( host, 'apt-get update' ) if host['platform'] =~ /ubuntu-|debian-|cumulus-|huaweios-/
976
- nil
977
- end
978
-
979
- # Install development repository on the given host. This method pushes all
980
- # repository information including package files for the specified
981
- # package_name to the host and modifies the repository configuration file
982
- # to point at the new repository. This is particularly useful for
983
- # installing development packages on hosts that can't access the builds
984
- # server.
985
- #
986
- # @param [Host] host An object implementing {Beaker::Hosts}'s
987
- # interface.
988
- # @param [String] package_name The name of the package whose repository is
989
- # being installed.
990
- # @param [String] build_version A string identifying the output of a
991
- # packaging job for use in looking up
992
- # repository directory information
993
- # @param [String] repo_configs_dir A local directory where repository files will be
994
- # stored as an intermediate step before
995
- # pushing them to the given host.
996
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
997
- # @option opts [String] :dev_builds_url The URL to look for dev builds.
998
- # @option opts [String, Array<String>] :dev_builds_repos The repo(s)
999
- # to check for dev builds in.
1000
- #
1001
- # @note puppet-agent requires :dev_builds_repos to be set to the
1002
- # puppet collection(s) to set the build server URL appropriately.
1003
- #
1004
- # @note This method only works on redhat-like and debian-like hosts.
1005
- #
1006
- def install_puppetlabs_dev_repo ( host, package_name, build_version,
1007
- repo_configs_dir = nil,
1008
- opts = options )
1009
- variant, version, arch, codename = host['platform'].to_array
1010
- if variant !~ /^(fedora|el|centos|debian|ubuntu|cumulus|huaweios|cisco_nexus|cisco_ios_xr|sles)$/
1011
- raise "No repository installation step for #{variant} yet..."
1012
- end
1013
- repo_configs_dir ||= 'tmp/repo_configs'
1014
-
1015
- platform_configs_dir = File.join(repo_configs_dir, variant)
1016
- opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
1017
-
1018
- # some of the uses of dev_builds_url below can't include protocol info,
1019
- # plus this opens up possibility of switching the behavior on provided
1020
- # url type
1021
- _, protocol, hostname = opts[:dev_builds_url].partition /.*:\/\//
1022
- dev_builds_url = protocol + hostname
1023
- dev_builds_url = opts[:dev_builds_url] if variant =~ /^(fedora|el|centos)$/
1024
-
1025
- install_repo_configs( host, dev_builds_url, package_name,
1026
- build_version, platform_configs_dir )
1027
-
1028
- configure_type_defaults_on( host )
1029
- end
1030
-
1031
- # Installs packages from the local development repository on the given host
1032
- #
1033
- # @param [Host] host An object implementing {Beaker::Hosts}'s
1034
- # interface.
1035
- # @param [Regexp] package_name The name of the package whose repository is
1036
- # being installed.
1037
- #
1038
- # @note This method only works on redhat-like and debian-like hosts.
1039
- # @note This method is paired to be run directly after {#install_puppetlabs_dev_repo}
1040
- #
1041
- def install_packages_from_local_dev_repo( host, package_name )
1042
- if host['platform'] =~ /debian|ubuntu|cumulus|huaweios/
1043
- find_filename = '*.deb'
1044
- find_command = 'dpkg -i'
1045
- elsif host['platform'] =~ /fedora|el|centos/
1046
- find_filename = '*.rpm'
1047
- find_command = 'rpm -ivh'
1048
- else
1049
- raise "No repository installation step for #{host['platform']} yet..."
1050
- end
1051
- find_command = "find /root/#{package_name} -type f -name '#{find_filename}' -exec #{find_command} {} \\;"
1052
- on host, find_command
1053
- configure_type_defaults_on( host )
1054
- end
1055
-
1056
- # Install development repo of the puppet-agent on the given host(s). Downloaded from
1057
- # location of the form DEV_BUILDS_URL/puppet-agent/AGENT_VERSION/repos
1058
- #
1059
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
1060
- # or a role (String or Symbol) that identifies one or more hosts.
1061
- # @param [Hash{Symbol=>String}] opts An options hash
1062
- # @option opts [String] :puppet_agent_version The version of puppet-agent to install. This
1063
- # parameter is used by puppet with the +SUITE_VERSION+ environment
1064
- # variable to provide a `git describe` value to beaker to create a
1065
- # build server URL. Note that +puppet_agent_sha+ will still be used
1066
- # instead of this if a value is provided for that option
1067
- # @option opts [String] :puppet_agent_sha The sha of puppet-agent to install, defaults to provided
1068
- # puppet_agent_version
1069
- # @option opts [String] :copy_base_local Directory where puppet-agent artifact
1070
- # will be stored locally
1071
- # (default: 'tmp/repo_configs')
1072
- # @option opts [String] :copy_dir_external Directory where puppet-agent
1073
- # artifact will be pushed to on the external machine
1074
- # (default: '/root')
1075
- # @option opts [String] :puppet_collection Defaults to 'PC1'
1076
- # @option opts [String] :dev_builds_url Base URL to pull artifacts from
1077
- # @option opts [String] :copy_base_local Directory where puppet-agent artifact
1078
- # will be stored locally
1079
- # (default: 'tmp/repo_configs')
1080
- # @option opts [String] :copy_dir_external Directory where puppet-agent
1081
- # artifact will be pushed to on the external machine
1082
- # (default: '/root')
1083
- #
1084
- # @note on windows, the +:ruby_arch+ host parameter can determine in addition
1085
- # to other settings whether the 32 or 64bit install is used
1086
- #
1087
- # @example
1088
- # install_puppet_agent_dev_repo_on(host, { :puppet_agent_sha => 'd3377feaeac173aada3a2c2cedd141eb610960a7', :puppet_agent_version => '1.1.1.225.gd3377fe' })
1089
- #
1090
- # @return nil
1091
- def install_puppet_agent_dev_repo_on( hosts, opts )
1092
-
1093
- opts[:puppet_agent_version] ||= opts[:version] #backward compatability
1094
- if not opts[:puppet_agent_version]
1095
- raise "must provide :puppet_agent_version (puppet-agent version) for install_puppet_agent_dev_repo_on"
1096
- end
1097
- # TODO consolidate these values as they serve no purpose from beaker's side
1098
- # you could provide any values you could to one to the other
1099
- puppet_agent_version = opts[:puppet_agent_sha] || opts[:puppet_agent_version]
1100
-
1101
- opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
1102
- opts[:download_url] = "#{opts[:dev_builds_url]}/puppet-agent/#{ puppet_agent_version }/repos/"
1103
- opts[:copy_base_local] ||= File.join('tmp', 'repo_configs')
1104
- opts[:puppet_collection] ||= 'PC1'
1105
- release_path = opts[:download_url]
1106
-
1107
- block_on hosts do |host|
1108
- variant, version, arch, codename = host['platform'].to_array
1109
- add_role(host, 'aio') #we are installing agent, so we want aio role
1110
- copy_dir_local = File.join(opts[:copy_base_local], variant)
1111
- onhost_copy_base = opts[:copy_dir_external] || host.external_copy_base
1112
-
1113
- case variant
1114
- when /^(fedora|el|centos|debian|ubuntu|cumulus|huaweios|cisco_nexus|cisco_ios_xr)$/
1115
- if arch == 's390x'
1116
- logger.trace("#install_puppet_agent_dev_repo_on: s390x arch detected for host #{host}. using dev package")
1117
- else
1118
- opts[:dev_builds_repos] ||= [ opts[:puppet_collection] ]
1119
- install_puppetlabs_dev_repo( host, 'puppet-agent', puppet_agent_version, nil, opts )
1120
- host.install_package('puppet-agent')
1121
- logger.trace("#install_puppet_agent_dev_repo_on: install_puppetlabs_dev_repo finished")
1122
- next
1123
- end
1124
- when /^(eos|osx|windows|solaris|sles|aix)$/
1125
- # Download installer package file & run install manually.
1126
- # Done below, so that el hosts with s390x arch can use this
1127
- # workflow as well
1128
- else
1129
- raise "No repository installation step for #{variant} yet..."
1130
- end
1131
-
1132
- release_path_end, release_file = host.puppet_agent_dev_package_info(
1133
- opts[:puppet_collection], opts[:puppet_agent_version], opts )
1134
- release_path << release_path_end
1135
- logger.trace("#install_puppet_agent_dev_repo_on: dev_package_info, continuing...")
1136
-
1137
- if variant =~ /eos/
1138
- host.get_remote_file( "#{release_path}/#{release_file}" )
1139
- else
1140
- onhost_copied_file = File.join(onhost_copy_base, release_file)
1141
- fetch_http_file( release_path, release_file, copy_dir_local)
1142
- scp_to host, File.join(copy_dir_local, release_file), onhost_copy_base
1143
- end
1144
-
1145
- case variant
1146
- when /^eos/
1147
- host.install_from_file( release_file )
1148
- when /^(sles|aix|el)$/
1149
- # NOTE: AIX does not support repo management. This block assumes
1150
- # that the desired rpm has been mirrored to the 'repos' location.
1151
- # NOTE: the AIX 7.1 package will only install on 7.2 with
1152
- # --ignoreos. This is a bug in package building on AIX 7.1's RPM
1153
- if variant == "aix" and version == "7.2"
1154
- aix_72_ignoreos_hack = "--ignoreos"
1155
- end
1156
- on host, "rpm -ivh #{aix_72_ignoreos_hack} #{onhost_copied_file}"
1157
- when /^windows$/
1158
- result = on host, "echo #{onhost_copied_file}"
1159
- onhost_copied_file = result.raw_output.chomp
1160
- msi_opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
1161
- install_msi_on(host, onhost_copied_file, {}, msi_opts)
1162
- when /^osx$/
1163
- host.install_package("puppet-agent-#{opts[:puppet_agent_version]}*")
1164
- when /^solaris$/
1165
- host.solaris_install_local_package( release_file, onhost_copy_base )
1166
- end
1167
- configure_type_defaults_on( host )
1168
- end
1169
- end
1170
- alias_method :install_puppetagent_dev_repo, :install_puppet_agent_dev_repo_on
1171
-
1172
- # Install shared repo of the puppet-agent on the given host(s). Downloaded from
1173
- # location of the form PE_PROMOTED_BUILDS_URL/PE_VER/puppet-agent/AGENT_VERSION/repo
1174
- #
1175
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
1176
- # or a role (String or Symbol) that identifies one or more hosts.
1177
- # @param [Hash{Symbol=>String}] opts An options hash
1178
- # @option opts [String] :puppet_agent_version The version of puppet-agent to install, defaults to 'latest'
1179
- # @option opts [String] :pe_ver The version of PE (will also use host['pe_ver']), defaults to '4.0'
1180
- # @option opts [String] :copy_base_local Directory where puppet-agent artifact
1181
- # will be stored locally
1182
- # (default: 'tmp/repo_configs')
1183
- # @option opts [String] :copy_dir_external Directory where puppet-agent
1184
- # artifact will be pushed to on the external machine
1185
- # (default: '/root')
1186
- # @option opts [String] :puppet_collection Defaults to 'PC1'
1187
- # @option opts [String] :pe_promoted_builds_url Base URL to pull artifacts from
1188
- #
1189
- # @note on windows, the +:ruby_arch+ host parameter can determine in addition
1190
- # to other settings whether the 32 or 64bit install is used
1191
- #
1192
- # @example
1193
- # install_puppet_agent_pe_promoted_repo_on(host, { :puppet_agent_version => '1.1.0.227', :pe_ver => '4.0.0-rc1'})
1194
- #
1195
- # @return nil
1196
- def install_puppet_agent_pe_promoted_repo_on( hosts, opts )
1197
- opts[:puppet_agent_version] ||= 'latest'
1198
-
1199
- block_on hosts do |host|
1200
- pe_ver = host[:pe_ver] || opts[:pe_ver] || '4.0.0-rc1'
1201
- opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
1202
- opts[:download_url] = "#{opts[:pe_promoted_builds_url]}/puppet-agent/#{ pe_ver }/#{ opts[:puppet_agent_version] }/repos"
1203
- opts[:copy_base_local] ||= File.join('tmp', 'repo_configs')
1204
- opts[:copy_dir_external] ||= host.external_copy_base
1205
- opts[:puppet_collection] ||= 'PC1'
1206
- add_role(host, 'aio') #we are installing agent, so we want aio role
1207
- release_path = opts[:download_url]
1208
- variant, version, arch, codename = host['platform'].to_array
1209
- copy_dir_local = File.join(opts[:copy_base_local], variant)
1210
- onhost_copy_base = opts[:copy_dir_external]
1211
-
1212
- release_path_end, release_file, download_file =
1213
- host.pe_puppet_agent_promoted_package_info(
1214
- opts[:puppet_collection], opts
1215
- )
1216
- release_path << release_path_end
1217
-
1218
- onhost_copied_download = File.join(onhost_copy_base, download_file)
1219
- onhost_copied_file = File.join(onhost_copy_base, release_file)
1220
- fetch_http_file( release_path, download_file, copy_dir_local)
1221
- scp_to host, File.join(copy_dir_local, download_file), onhost_copy_base
1222
-
1223
- if variant == 'windows'
1224
- result = on host, "echo #{onhost_copied_file}"
1225
- onhost_copied_file = result.raw_output.chomp
1226
- opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
1227
- # couldn't pull this out, because it's relying on
1228
- # {Beaker::DSL::InstallUtils::WindowsUtils} methods,
1229
- # which I didn't want to attack right now. TODO
1230
- install_msi_on(host, onhost_copied_file, {}, opts)
1231
- else
1232
- host.pe_puppet_agent_promoted_package_install(
1233
- onhost_copy_base, onhost_copied_download,
1234
- onhost_copied_file, download_file, opts
1235
- )
1236
- end
1237
- configure_type_defaults_on( host )
1238
- end
1239
- end
1240
-
1241
- # This method will install a pem file certificate on a windows host
1242
- #
1243
- # @param [Host] host A host object
1244
- # @param [String] cert_name The name of the pem file
1245
- # @param [String] cert The contents of the certificate
1246
- #
1247
- def install_cert_on_windows(host, cert_name, cert)
1248
- create_remote_file(host, "C:\\Windows\\Temp\\#{cert_name}.pem", cert)
1249
- on host, "certutil -v -addstore Root C:\\Windows\\Temp\\#{cert_name}.pem"
1250
- end
1251
-
1252
- # Ensures Puppet and dependencies are no longer installed on host(s).
1253
- #
1254
- # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
1255
- # or a role (String or Symbol) that identifies one or more hosts.
1256
- #
1257
- # @return nil
1258
- # @api public
1259
- def remove_puppet_on( hosts )
1260
- block_on hosts do |host|
1261
- cmdline_args = ''
1262
- # query packages
1263
- case host[:platform]
1264
- when /cumulus|huaweios/
1265
- pkgs = on(host, "dpkg-query -l | awk '{print $2}' | grep -E '(^pe-|puppet)'", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1266
- when /aix|sles|el|redhat|centos|oracle|scientific/
1267
- pkgs = on(host, "rpm -qa | grep -E '(^pe-|puppet)'", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1268
- when /solaris-10/
1269
- cmdline_args = '-a noask'
1270
- pkgs = on(host, "pkginfo | egrep '(^pe-|puppet)' | cut -f2 -d ' '", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1271
- when /solaris-11/
1272
- pkgs = on(host, "pkg list | egrep '(^pe-|puppet)' | awk '{print $1}'", :acceptable_exit_codes => [0,1]).stdout.chomp.split(/\n+/)
1273
- else
1274
- raise "remove_puppet_on() called for unsupported " +
1275
- "platform '#{host['platform']}' on '#{host.name}'"
1276
- end
1277
-
1278
- # uninstall packages
1279
- host.uninstall_package(pkgs.join(' '), cmdline_args) if pkgs.length > 0
1280
-
1281
- if host[:platform] =~ /solaris-11/ then
1282
- # FIXME: This leaves things in a state where Puppet Enterprise (3.x) cannot be cleanly installed
1283
- # but is required to put things in a state that puppet-agent can be installed
1284
- # extra magic for expunging left over publisher
1285
- publishers = ['puppetlabs.com', 'com.puppetlabs']
1286
- publishers.each do |publisher|
1287
- if on(host, "pkg publisher #{publisher}", :acceptable_exit_codes => [0,1]).exit_code == 0 then
1288
- # First, try to remove the publisher altogether
1289
- if on(host, "pkg unset-publisher #{publisher}", :acceptable_exit_codes => [0,1]).exit_code == 1 then
1290
- # If that doesn't work, we're in a non-global zone and the
1291
- # publisher is from a global zone. As such, just remove any
1292
- # references to the non-global zone uri.
1293
- on(host, "pkg set-publisher -G '*' #{publisher}", :acceptable_exit_codes => [0,1])
1294
- end
1295
- end
1296
- end
1297
- end
1298
-
1299
- # delete any residual files
1300
- on(host, 'find / -name "*puppet*" -print | xargs rm -rf')
1301
-
1302
- end
1303
- end
1304
- end
1305
- end
1306
- end
1307
- end