lib/beaker-pe/install/pe_utils.rb in beaker-pe-1.6.1 vs lib/beaker-pe/install/pe_utils.rb in beaker-pe-1.7.0

- old
+ new

@@ -384,43 +384,11 @@ # expired. Add a temporary, extended key to the host first so that it # can still install those old PE tarballs. add_extended_gpg_key_to_hosts(hosts, opts) # Set PE distribution for all the hosts, create working dir - use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true' - hosts.each do |host| - next if agent_only_check_needed && hosts_agent_only.include?(host) - host['pe_installer'] ||= 'puppet-enterprise-installer' - if host['platform'] !~ /windows|osx/ - platform = use_all_tar ? 'all' : host['platform'] - version = host['pe_ver'] || opts[:pe_ver] - host['dist'] = "puppet-enterprise-#{version}-#{platform}" - elsif host['platform'] =~ /osx/ - version = host['pe_ver'] || opts[:pe_ver] - host['dist'] = "puppet-enterprise-#{version}-#{host['platform']}" - elsif host['platform'] =~ /windows/ - version = host[:pe_ver] || opts['pe_ver_win'] - is_config_32 = true == (host['ruby_arch'] == 'x86') || host['install_32'] || opts['install_32'] - should_install_64bit = !(version_is_less(version, '3.4')) && host.is_x86_64? && !is_config_32 - #only install 64bit builds if - # - we are on pe version 3.4+ - # - we do not have install_32 set on host - # - we do not have install_32 set globally - if !(version_is_less(version, '3.99')) - if should_install_64bit - host['dist'] = "puppet-agent-#{version}-x64" - else - host['dist'] = "puppet-agent-#{version}-x86" - end - elsif should_install_64bit - host['dist'] = "puppet-enterprise-#{version}-x64" - else - host['dist'] = "puppet-enterprise-#{version}" - end - end - host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S")) - end + prepare_hosts(hosts_not_agent_only, opts) fetch_pe(hosts_not_agent_only, opts) install_hosts = hosts.dup unless masterless @@ -432,14 +400,16 @@ #windows agents from 4.0 -> 2016.1.2 were only installable via the aio method is_windows_msi_and_aio = (host['platform'] =~ /windows/ && (version_is_less(host['pe_ver'], '2016.3.0') && !version_is_less(host['pe_ver'], '3.99'))) if agent_only_check_needed && hosts_agent_only.include?(host) || is_windows_msi_and_aio host['type'] = 'aio' - install_puppet_agent_pe_promoted_repo_on(host, { :puppet_agent_version => host[:puppet_agent_version] || opts[:puppet_agent_version], - :puppet_agent_sha => host[:puppet_agent_sha] || opts[:puppet_agent_sha], - :pe_ver => host[:pe_ver] || opts[:pe_ver], - :puppet_collection => host[:puppet_collection] || opts[:puppet_collection] }) + install_puppet_agent_pe_promoted_repo_on(host, { + :puppet_agent_version => get_puppet_agent_version(host, opts), + :puppet_agent_sha => host[:puppet_agent_sha] || opts[:puppet_agent_sha], + :pe_ver => host[:pe_ver] || opts[:pe_ver], + :puppet_collection => host[:puppet_collection] || opts[:puppet_collection] + }) # 1 since no certificate found and waitforcert disabled acceptable_exit_codes = [0, 1] acceptable_exit_codes << 2 if opts[:type] == :upgrade setup_defaults_and_config_helper_on(host, master, acceptable_exit_codes) #Windows allows frictionless installs starting with PE Davis, if frictionless we need to skip this step @@ -556,10 +526,92 @@ end end end end + # Prepares hosts for rest of {#do_install} operations. + # This includes doing these tasks: + # - setting 'pe_installer' property on hosts + # - setting 'dist' property on hosts + # - creating and setting 'working_dir' property on hosts + # + # @note that these steps aren't necessary for all hosts. Specifically, + # 'agent_only' hosts do not require these steps to be executed. + # + # @param [Array<Host>] hosts Hosts to prepare + # @param [Hash{Symbol=>String}] local_options Local options, used to + # pass misc configuration required for the prep steps + # + # @return nil + def prepare_hosts(hosts, local_options={}) + use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true' + hosts.each do |host| + host['pe_installer'] ||= 'puppet-enterprise-installer' + if host['platform'] !~ /windows|osx/ + platform = use_all_tar ? 'all' : host['platform'] + version = host['pe_ver'] || local_options[:pe_ver] + host['dist'] = "puppet-enterprise-#{version}-#{platform}" + elsif host['platform'] =~ /osx/ + version = host['pe_ver'] || local_options[:pe_ver] + host['dist'] = "puppet-enterprise-#{version}-#{host['platform']}" + elsif host['platform'] =~ /windows/ + version = host[:pe_ver] || local_options['pe_ver_win'] + is_config_32 = true == (host['ruby_arch'] == 'x86') || host['install_32'] || local_options['install_32'] + should_install_64bit = !(version_is_less(version, '3.4')) && host.is_x86_64? && !is_config_32 + #only install 64bit builds if + # - we are on pe version 3.4+ + # - we do not have install_32 set on host + # - we do not have install_32 set globally + if !(version_is_less(version, '3.99')) + if should_install_64bit + host['dist'] = "puppet-agent-#{version}-x64" + else + host['dist'] = "puppet-agent-#{version}-x86" + end + elsif should_install_64bit + host['dist'] = "puppet-enterprise-#{version}-x64" + else + host['dist'] = "puppet-enterprise-#{version}" + end + end + host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S")) + end + end + + # Gets the puppet-agent version, hopefully from the host or local options. + # Will fall back to reading the `aio_agent_build` property on the master + # if neither of those two options are passed + # + # @note This method does have a side-effect: if it reads the + # `aio_agent_build` property from master, it will store it in the local + # options hash so that it won't have to do this more than once. + # + # @param [Beaker::Host] host Host to get puppet-agent for + # @param [Hash{Symbol=>String}] local_options local method options hash + # + # @return [String] puppet-agent version to install + def get_puppet_agent_version(host, local_options={}) + puppet_agent_version = host[:puppet_agent_version] || local_options[:puppet_agent_version] + return puppet_agent_version if puppet_agent_version + log_prefix = "No :puppet_agent_version in host #{host} or local options." + fail_message = "#{log_prefix} Could not read facts from master to determine puppet_agent_version" + # we can query the master because do_install is called passing + # the {#sorted_hosts}, so we know the master will be installed + # before the agents + facts_result = on(master, 'puppet facts') + raise ArgumentError, fail_message if facts_result.exit_code != 0 + facts_hash = JSON.parse(facts_result.stdout.chomp) + puppet_agent_version = facts_hash['values']['aio_agent_build'] + # released masters don't have _build fact, fallback to _version + puppet_agent_version ||= facts_hash['values']['aio_agent_version'] + raise ArgumentError, fail_message if puppet_agent_version.nil? + logger.warn("#{log_prefix} Read puppet-agent version #{puppet_agent_version} from master") + # saving so that we don't have to query the master more than once + local_options[:puppet_agent_version] = puppet_agent_version + puppet_agent_version + end + # True if version is greater than or equal to MEEP_CUTOVER_VERSION (2016.2.0) def use_meep?(version) !version_is_less(version, MEEP_CUTOVER_VERSION) end @@ -901,10 +953,10 @@ prepare_host_installer_options(host) 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 - if version_is_less(options[:pe_ver] || host['pe_ver'], '2016.3') + if version_is_less(opts[:pe_ver] || host['pe_ver'], '2016.3') higgs_re = /Please\s+go\s+to\s+https:\/\/.*\s+in\s+your\s+browser\s+to\s+continue\s+installation/m else higgs_re = /o\s+to\s+https:\/\/.*\s+in\s+your\s+browser\s+to\s+continue\s+installation/m end res = Result.new(host, 'tmp cmd')