module Puppet::Acceptance::InstallUtils

Constants

PLATFORM_PATTERNS

Public Instance Methods

configure_gem_mirror(hosts) click to toggle source

Configures gem sources on hosts to use a mirror, if specified This is a duplicate of the Gemfile logic.

    # File acceptance/lib/puppet/acceptance/install_utils.rb
165       def configure_gem_mirror(hosts)
166         hosts = [hosts] unless hosts.kind_of?(Array)
167         gem_source = ENV['GEM_SOURCE'] || 'https://rubygems.org'
168 
169         hosts.each do |host|
170           gem = Puppet::Acceptance::CommandUtils.gem_command(host)
171           gem_version = on(host, "#{gem} --version").stdout.chomp
172           if host['platform'] =~ /win/ && gem_version < '2.6.8' then
173             # The vendored gem command does not have an updated
174             # TLS cert on Windows.
175             # http://guides.rubygems.org/ssl-certificate-update
176             geotrust_ca = <<-EOS
177 -----BEGIN CERTIFICATE-----
178 MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG
179 A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
180 b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw
181 MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i
182 YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT
183 aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ
184 jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp
185 xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp
186 1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG
187 snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ
188 U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8
189 9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E
190 BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B
191 AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz
192 yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE
193 38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP
194 AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad
195 DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME
196 HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==
197 -----END CERTIFICATE-----
198 EOS
199             p = on(host, "#{gem} which rubygems").stdout.chomp.sub('rubygems.rb', 'rubygems/ssl_certs')
200             create_remote_file(host, "#{p}/geotrustglobal.pem", geotrust_ca)
201           end
202           on host, "#{gem} source --clear-all"
203           on host, "#{gem} source --add #{gem_source}"
204         end
205       end
fetch(base_url, file_name, dst_dir) click to toggle source
   # File acceptance/lib/puppet/acceptance/install_utils.rb
58 def fetch(base_url, file_name, dst_dir)
59   FileUtils.makedirs(dst_dir)
60   src = "#{base_url}/#{file_name}"
61   dst = File.join(dst_dir, file_name)
62   if File.exists?(dst)
63     logger.notify "Already fetched #{dst}"
64   else
65     logger.notify "Fetching: #{src}"
66     logger.notify "  and saving to #{dst}"
67     open(src) do |remote|
68       File.open(dst, "w") do |file|
69         FileUtils.copy_stream(remote, file)
70       end
71     end
72   end
73   return dst
74 end
fetch_remote_dir(url, dst_dir) click to toggle source
    # File acceptance/lib/puppet/acceptance/install_utils.rb
 76 def fetch_remote_dir(url, dst_dir)
 77   logger.notify "fetch_remote_dir (url: #{url}, dst_dir #{dst_dir})"
 78   if url[-1, 1] !~ /\//
 79     url += '/'
 80   end
 81   url = URI.parse(url)
 82   chunks = url.path.split('/')
 83   dst = File.join(dst_dir, chunks.last)
 84   #determine directory structure to cut
 85   #only want to keep the last directory, thus cut total number of dirs - 2 (hostname + last dir name)
 86   cut = chunks.length - 2
 87   wget_command = "wget -nv -P #{dst_dir} --reject \"index.html*\",\"*.gif\" --cut-dirs=#{cut} -np -nH --no-check-certificate -r #{url}"
 88 
 89   logger.notify "Fetching remote directory: #{url}"
 90   logger.notify "  and saving to #{dst}"
 91   logger.notify "  using command: #{wget_command}"
 92 
 93   #in ruby 1.9+ we can upgrade this to popen3 to gain access to the subprocess pid
 94   result = `#{wget_command} 2>&1`
 95   result.each_line do |line|
 96     logger.debug(line)
 97   end
 98   if $?.to_i != 0
 99     raise "Failed to fetch_remote_dir '#{url}' (exit code #{$?}"
100   end
101   dst
102 end
install_packages_on(hosts, package_hash, options = {}) click to toggle source

Installs packages on the hosts.

@param hosts [Array<Host>] Array of hosts to install packages to. @param package_hash [Hash{Symbol=>Array<String,Array<String,String>>}]

Keys should be a symbol for a platform in PLATFORM_PATTERNS.  Values
should be an array of package names to install, or of two element
arrays where a[0] is the command we expect to find on the platform
and a[1] is the package name (when they are different).

@param options [Hash{Symbol=>Boolean}] @option options [Boolean] :check_if_exists First check to see if

command is present before installing package.  (Default false)

@return true

   # File acceptance/lib/puppet/acceptance/install_utils.rb
30 def install_packages_on(hosts, package_hash, options = {})
31   check_if_exists = options[:check_if_exists]
32   hosts = [hosts] unless hosts.kind_of?(Array)
33   hosts.each do |host|
34     package_hash.each do |platform_key,package_list|
35       if pattern = PLATFORM_PATTERNS[platform_key]
36         if pattern.match(host['platform'])
37           package_list.each do |cmd_pkg|
38             if cmd_pkg.kind_of?(Array)
39               command, package = cmd_pkg
40             else
41               command = package = cmd_pkg
42             end
43             if !check_if_exists || !host.check_for_package(command)
44               host.logger.notify("Installing #{package}")
45               additional_switches = '--allow-unauthenticated' if platform_key == :debian
46               host.install_package(package, additional_switches)
47             end
48           end
49         end
50       else
51         raise("Unknown platform '#{platform_key}' in package_hash")
52       end
53     end
54   end
55   return true
56 end
install_puppet_from_msi( host, opts ) click to toggle source
    # File acceptance/lib/puppet/acceptance/install_utils.rb
207 def install_puppet_from_msi( host, opts )
208   if not link_exists?(opts[:url])
209     raise "Puppet does not exist at #{opts[:url]}!"
210   end
211 
212   # `start /w` blocks until installation is complete, but needs to be wrapped in `cmd.exe /c`
213   on host, "cmd.exe /c start /w msiexec /qn /i #{opts[:url]} /L*V C:\\\\Windows\\\\Temp\\\\Puppet-Install.log"
214 
215   # make sure the background service isn't running while the test executes
216   on host, "net stop puppet"
217 
218   # make sure install is sane, beaker has already added puppet and ruby
219   # to PATH in ~/.ssh/environment
220   on host, puppet('--version')
221   ruby = Puppet::Acceptance::CommandUtils.ruby_command(host)
222   on host, "#{ruby} --version"
223 end
install_repos_on(host, project, sha, repo_configs_dir) click to toggle source
    # File acceptance/lib/puppet/acceptance/install_utils.rb
119 def install_repos_on(host, project, sha, repo_configs_dir)
120   platform = host['platform'].with_version_codename
121   platform_configs_dir = File.join(repo_configs_dir,platform)
122   tld     = sha == 'nightly' ? 'ravi.puppetlabs.com' : 'builds.puppetlabs.lan'
123   project = sha == 'nightly' ? project + '-latest'        :  project
124   sha     = sha == 'nightly' ? nil                        :  sha
125 
126   case platform
127   when /^(fedora|el|centos)-(\d+)-(.+)$/
128     variant = (($1 == 'centos') ? 'el' : $1)
129     fedora_prefix = ((variant == 'fedora') ? 'f' : '')
130     version = $2
131     arch = $3
132 
133     repo_filename = "pl-%s%s-%s-%s%s-%s.repo" % [
134       project,
135       sha ? '-' + sha : '',
136       variant,
137       fedora_prefix,
138       version,
139       arch
140     ]
141     repo_url = "http://%s/%s/%s/repo_configs/rpm/%s" % [tld, project, sha, repo_filename]
142 
143     on host, "curl -o /etc/yum.repos.d/#{repo_filename} #{repo_url}"
144   when /^(debian|ubuntu)-([^-]+)-(.+)$/
145     variant = $1
146     version = $2
147     arch = $3
148 
149     list_filename = "pl-%s%s-%s.list" % [
150       project,
151       sha ? '-' + sha : '',
152       version
153     ]
154     list_url = "http://%s/%s/%s/repo_configs/deb/%s" % [tld, project, sha, list_filename]
155 
156     on host, "curl -o /etc/apt/sources.list.d/#{list_filename} #{list_url}"
157     on host, "apt-get update"
158   else
159     host.logger.notify("No repository installation step for #{platform} yet...")
160   end
161 end
stop_firewall_on(host) click to toggle source
    # File acceptance/lib/puppet/acceptance/install_utils.rb
104 def stop_firewall_on(host)
105   case host['platform']
106   when /debian/
107     on host, 'iptables -F'
108   when /fedora|el-7/
109     on host, puppet('resource', 'service', 'firewalld', 'ensure=stopped')
110   when /el|centos/
111     on host, puppet('resource', 'service', 'iptables', 'ensure=stopped')
112   when /ubuntu/
113     on host, puppet('resource', 'service', 'ufw', 'ensure=stopped')
114   else
115     logger.notify("Not sure how to clear firewall on #{host['platform']}")
116   end
117 end