lib/beaker/dsl/install_utils.rb in beaker-1.16.0 vs lib/beaker/dsl/install_utils.rb in beaker-1.17.0
- old
+ new
@@ -170,10 +170,21 @@
pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -D' : ''
"cd #{host['working_dir']}/#{host['dist']} && ./#{host['pe_installer']}#{pe_debug} -a #{host['working_dir']}/answers"
end
end
+ #Create the Higgs install command string based upon the host and options settings. Installation command will be run as a
+ #background process. The output of the command will be stored in the provided host['higgs_file'].
+ # @param [Host] host The host that Higgs is to be installed on
+ # The host object must have the 'working_dir', 'dist' and 'pe_installer' field set correctly.
+ # @api private
+ def higgs_installer_cmd host
+
+ "cd #{host['working_dir']}/#{host['dist']} ; nohup ./#{host['pe_installer']} <<<Y > #{host['higgs_file']} 2>&1 &"
+
+ end
+
#Determine is a given URL is accessible
#@param [String] link The URL to examine
#@return [Boolean] true if the URL has a '200' HTTP response code, false otherwise
#@example
# extension = link_exists?("#{URL}.tar.gz") ? ".tar.gz" : ".tar"
@@ -418,12 +429,11 @@
host['dist'] = "puppet-enterprise-#{version}-#{platform}"
elsif host['platform'] =~ /osx/
version = host['pe_ver'] || opts[:pe_ver]
host['dist'] = "puppet-enterprise-#{version}-#{host['platform']}"
end
- host['working_dir'] = "/tmp/" + Time.new.strftime("%Y-%m-%d_%H.%M.%S") #unique working dirs make me happy
- on host, "mkdir #{host['working_dir']}"
+ host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S"))
end
fetch_puppet(hosts, opts)
# If we're installing a database version less than 3.0, ignore the database host
@@ -491,10 +501,61 @@
# Now that all hosts are in the dashbaord, run puppet one more
# time to configure mcollective
on install_hosts, puppet_agent('-t'), :acceptable_exit_codes => [0,2]
end
+ #Perform a Puppet Enterprise Higgs install up until web browser interaction is required, runs on linux hosts only.
+ # @param [Host] host The host to install higgs on
+ # @param [Hash{Symbol=>Symbol, String}] opts The options
+ # @option opts [String] :pe_dir Default directory or URL to pull PE package from
+ # (Otherwise uses individual hosts pe_dir)
+ # @option opts [String] :pe_ver Default PE version to install
+ # (Otherwise uses individual hosts pe_ver)
+ # @raise [StandardError] When installation times out
+ #
+ # @example
+ # do_higgs_install(master, {:pe_dir => path, :pe_ver => version})
+ #
+ # @api private
+ #
+ def do_higgs_install host, opts
+ use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true'
+ platform = use_all_tar ? 'all' : host['platform']
+ version = host['pe_ver'] || opts[:pe_ver]
+ host['dist'] = "puppet-enterprise-#{version}-#{platform}"
+
+ use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true'
+ host['pe_installer'] ||= 'puppet-enterprise-installer'
+ host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S"))
+
+ fetch_puppet([host], opts)
+
+ host['higgs_file'] = "higgs_#{File.basename(host['working_dir'])}.log"
+ on host, higgs_installer_cmd(host), opts
+
+ #wait for output to host['higgs_file']
+ #we're all done when we find this line in the PE installation log
+ higgs_re = /Please\s+go\s+to\s+https:\/\/.*\s+in\s+your\s+browser\s+to\s+continue\s+installation/m
+ res = Result.new(host, 'tmp cmd')
+ tries = 10
+ attempts = 0
+ prev_sleep = 0
+ cur_sleep = 1
+ while (res.stdout !~ higgs_re) and (attempts < tries)
+ res = on host, "cd #{host['working_dir']}/#{host['dist']} && cat #{host['higgs_file']}", :acceptable_exit_codes => (0..255)
+ attempts += 1
+ sleep( cur_sleep )
+ prev_sleep = cur_sleep
+ cur_sleep = cur_sleep + prev_sleep
+ end
+
+ if attempts >= tries
+ raise "Failed to kick off PE (Higgs) web installation"
+ end
+
+ end
+
#Sort array of hosts so that it has the correct order for PE installation based upon each host's role
# @example
# h = sorted_hosts
#
# @note Order for installation should be
@@ -549,10 +610,14 @@
install_puppet_from_gem host, opts
else
raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'"
end
end
+
+ # Certain install paths may not create the config dirs/files needed
+ on host, "mkdir -p #{host['puppetpath']}"
+ on host, "echo '' >> #{host['hieraconf']}"
end
nil
end
# Installs Puppet and dependencies using rpm
@@ -686,24 +751,55 @@
#
# @return nil
# @raise [StandardError] if gem does not exist on target host
# @api private
def install_puppet_from_gem( host, opts )
- if host.check_for_command( 'gem' )
- if opts[:facter_version]
- on host, "gem install facter -v#{opts[:facter_version]}"
- end
- if opts[:hiera_version]
- on host, "gem install hiera -v#{opts[:hiera_version]}"
- end
- ver_cmd = opts[:version] ? "-v#{opts[:version]}" : ''
- on host, "gem install puppet #{ver_cmd}"
- else
- raise "install_puppet() called with default_action 'gem_install' but program `gem' not installed on #{host.name}"
+ # Hosts may be provisioned with csw but pkgutil won't be in the
+ # PATH by default to avoid changing the behavior for Puppet's tests
+ if host['platform'] =~ /solaris-10/
+ on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil'
end
+
+ # Solaris doesn't necessarily have this, but gem needs it
+ if host['platform'] =~ /solaris/
+ on host, 'mkdir -p /var/lib'
+ end
+
+ unless host.check_for_command( 'gem' )
+ gempkg = case host['platform']
+ when /solaris-11/ then 'ruby-18'
+ when /ubuntu-14/ then 'ruby'
+ when /solaris-10|ubuntu|debian|el-/ then 'rubygems'
+ else
+ raise "install_puppet() called with default_action " +
+ "'gem_install' but program `gem' is " +
+ "not installed on #{host.name}"
+ end
+
+ host.install_package gempkg
+ end
+
+ if host['platform'] =~ /debian|ubuntu|solaris/
+ gem_env = YAML.load( on( host, 'gem environment' ).stdout )
+ gem_paths_array = gem_env['RubyGems Environment'].find {|h| h['GEM PATHS'] != nil }['GEM PATHS']
+ path_with_gem = 'export PATH=' + gem_paths_array.join(':') + ':${PATH}'
+ on host, "echo '#{path_with_gem}' >> ~/.bashrc"
+ end
+
+ if opts[:facter_version]
+ on host, "gem install facter -v#{opts[:facter_version]} --no-ri --no-rdoc"
+ end
+
+ if opts[:hiera_version]
+ on host, "gem install hiera -v#{opts[:hiera_version]} --no-ri --no-rdoc"
+ end
+
+ ver_cmd = opts[:version] ? "-v#{opts[:version]}" : ''
+ on host, "gem install puppet #{ver_cmd} --no-ri --no-rdoc"
end
+
#Install PE based upon host configuration and options
# @example
# install_pe
#
# @note Either pe_ver and pe_dir should be set in the ENV or each host should have pe_ver and pe_dir set individually.
@@ -775,11 +871,11 @@
"/puppetlabs-release-%s-%s.noarch.rpm" % [variant, version]
on host, "rpm -ivh --force #{rpm}"
when /^(debian|ubuntu)$/
- deb = options[:release_apt_repo_url] + "puppetlabs-release-%s.deb" % codename
+ deb = URI.join(options[:release_apt_repo_url], "puppetlabs-release-%s.deb" % codename)
on host, "wget -O /tmp/puppet.deb #{deb}"
on host, "dpkg -i --force-all /tmp/puppet.deb"
on host, "apt-get update"
else
@@ -886,20 +982,43 @@
config_dir = '/etc/apt/sources.list.d'
scp_to host, list, config_dir
scp_to host, repo_dir, "/root/#{package_name}"
- search = "'deb\\s\\+http:\\/\\/#{hostname}.*$"
- replace = "'deb file:\\/\\/\\/root\\/#{package_name}\\/#{codename} #{codename} main'"
+ search = "deb\\s\\+http:\\/\\/#{hostname}.*$"
+ replace = "deb file:\\/\\/\\/root\\/#{package_name}\\/#{codename} #{codename} main"
sed_command = "sed -i 's/#{search}/#{replace}/'"
find_and_sed = "find #{config_dir} -name \"*.list\" -exec #{sed_command} {} \\;"
on host, find_and_sed
on host, "apt-get update"
else
raise "No repository installation step for #{variant} yet..."
end
end
+
+ #Install Higgs up till the point where you need to continue installation in a web browser, defaults to execution
+ #on the master node.
+ #@param [Host] higgs_host The host to install Higgs on (supported on linux platform only)
+ # @example
+ # install_higgs
+ #
+ # @note Either pe_ver and pe_dir should be set in the ENV or each host should have pe_ver and pe_dir set individually.
+ # Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz).
+ #
+ # @api dsl
+ def install_higgs( higgs_host = master )
+ #process the version files if necessary
+ master['pe_dir'] ||= options[:pe_dir]
+ master['pe_ver'] = master['pe_ver'] || options['pe_ver'] ||
+ Beaker::Options::PEVersionScraper.load_pe_version(master[:pe_dir] || options[:pe_dir], options[:pe_version_file])
+ if higgs_host['platform'] =~ /osx|windows/
+ raise "Attempting higgs installation on host #{higgs_host.name} with unsupported platform #{higgs_host['platform']}"
+ end
+ #send in the global options hash
+ do_higgs_install higgs_host, options
+ end
+
end
end
end