lib/beaker-pe/install/pe_utils.rb in beaker-pe-1.23.0 vs lib/beaker-pe/install/pe_utils.rb in beaker-pe-1.24.0
- old
+ new
@@ -99,10 +99,34 @@
scp_to(host, local_cert_copy, agent_ca_pem_dir)
end
end
end
+ # Return agent nodes with 'lb_connect' role that are not loadbalancers
+ def loadbalancer_connecting_agents
+ lb_connect_nodes = select_hosts(roles: ['lb_connect'])
+ lb_connect_agents = lb_connect_nodes.reject { |h| h['roles'].include?('loadbalancer')}
+ end
+
+ # Returns true if loadbalncer exists and is configured with 'lb_connect' role
+ def lb_connect_loadbalancer_exists?
+ if (any_hosts_as?('loadbalancer'))
+ lb_node = select_hosts(roles: ['loadbalancer'])
+ lb_node.first['roles'].include?('lb_connect')
+ end
+ end
+
+ #Returns loadbalancer if host is an agent and loadbalancer has lb_connect role
+ #@param [Host] agent host with lb_connect role
+ def get_lb_downloadhost(host)
+ downloadhost = master
+ if( ! host['roles'].include?('loadbalancer') && lb_connect_loadbalancer_exists?)
+ downloadhost = loadbalancer
+ end
+ downloadhost
+ end
+
# Generate the command line string needed to from a frictionless puppet-agent
# install on this host in a PE environment.
#
# @param [Host] host The host to install puppet-agent onto
# @param [Hash] opts The full beaker options
@@ -122,10 +146,18 @@
frictionless_install_opts << "#{section}:#{key}=#{value}"
end
end
end
+ # If this is an agent node configured to connect to the loadbalancer
+ # using 'lb_connect' role, then use loadbalancer in the download url
+ # instead of master (PE-22051)
+ downloadhost = master
+ if( host['roles'].include?('lb_connect'))
+ downloadhost = get_lb_downloadhost(host)
+ end
+
pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -x' : ''
use_puppet_ca_cert = host[:use_puppet_ca_cert] || opts[:use_puppet_ca_cert]
if host['platform'] =~ /windows/ then
if use_puppet_ca_cert
@@ -133,20 +165,20 @@
cert_validator = %Q{\\$callback = {param(\\$sender,[System.Security.Cryptography.X509Certificates.X509Certificate]\\$certificate,[System.Security.Cryptography.X509Certificates.X509Chain]\\$chain,[System.Net.Security.SslPolicyErrors]\\$sslPolicyErrors);\\$CertificateType=[System.Security.Cryptography.X509Certificates.X509Certificate2];\\$CACert=\\$CertificateType::CreateFromCertFile('#{host['puppetpath']}/ssl/certs/ca.pem') -as \\$CertificateType;\\$chain.ChainPolicy.ExtraStore.Add(\\$CACert);return \\$chain.Build(\\$certificate)};[Net.ServicePointManager]::ServerCertificateValidationCallback = \\$callback}
else
cert_validator = '[Net.ServicePointManager]::ServerCertificateValidationCallback = {\\$true}'
end
- cmd = %Q{powershell -c "cd #{host['working_dir']};#{cert_validator};\\$webClient = New-Object System.Net.WebClient;\\$webClient.DownloadFile('https://#{master}:8140/packages/current/install.ps1', '#{host['working_dir']}/install.ps1');#{host['working_dir']}/install.ps1 -verbose #{frictionless_install_opts.join(' ')}"}
+ cmd = %Q{powershell -c "cd #{host['working_dir']};#{cert_validator};\\$webClient = New-Object System.Net.WebClient;\\$webClient.DownloadFile('https://#{downloadhost}:8140/packages/current/install.ps1', '#{host['working_dir']}/install.ps1');#{host['working_dir']}/install.ps1 -verbose #{frictionless_install_opts.join(' ')}"}
else
curl_opts = %w{--tlsv1 -O}
if use_puppet_ca_cert
curl_opts << '--cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem'
elsif host['platform'] !~ /aix/
curl_opts << '-k'
end
- cmd = "FRICTIONLESS_TRACE='true'; export FRICTIONLESS_TRACE; cd #{host['working_dir']} && curl #{curl_opts.join(' ')} https://#{master}:8140/packages/current/install.bash && bash#{pe_debug} install.bash #{frictionless_install_opts.join(' ')}".strip
+ cmd = "FRICTIONLESS_TRACE='true'; export FRICTIONLESS_TRACE; cd #{host['working_dir']} && curl #{curl_opts.join(' ')} https://#{downloadhost}:8140/packages/current/install.bash && bash#{pe_debug} install.bash #{frictionless_install_opts.join(' ')}".strip
end
return cmd
end
@@ -374,37 +406,45 @@
on dashboard, "cd /opt/puppet/share/puppet-dashboard && /opt/puppet/bin/bundle exec /opt/puppet/bin/rake node:addclass[#{master},#{klass}]"
on master, puppet("agent -t"), :acceptable_exit_codes => [0,2]
else
_console_dispatcher = get_console_dispatcher_for_beaker_pe!
- # Check if we've already created a frictionless agent node group
- # to avoid errors creating the same node group when the beaker hosts file contains
- # multiple hosts with the same platform
- node_group = _console_dispatcher.get_node_group_by_name('Beaker Frictionless Agent')
- if node_group.nil? || node_group.empty?
- node_group = {}
- node_group['name'] = "Beaker Frictionless Agent"
- # Pin the master to the node
- node_group['rule'] = [ "and", [ '=', 'name', master.to_s ]]
- node_group['classes'] ||= {}
- end
+ # Add pe_repo packages to 'PE Master' group
+ # This change will alow us to test the standard workflow where we add pe_repo packages
+ # to PE Master group itself. This will also make it easy to download the packages to
+ # compilemasters(PE-22051)
+ # Previosuly, we were creating a new node group 'Beaker Frictionless Agent' and adding
+ # pe_repo packages to that group
+ #
+ node_group = _console_dispatcher.get_node_group_by_name('PE Master')
# add the pe_repo platform class if it's not already present
- if ! node_group['classes'].include?(klass)
- node_group['classes'][klass] = {}
+ if (node_group)
+ if( ! node_group['classes'].include?(klass))
+ node_group['classes'][klass] = {}
+ _console_dispatcher.create_new_node_group_model(node_group)
- _console_dispatcher.create_new_node_group_model(node_group)
- # The puppet agent run that will download the agent tarballs to the master can sometimes fail with
- # curl errors if there is a network hiccup. Use beakers `retry_on` method to retry up to
- # three times to avoid failing the entire test pipeline due to a network blip
- retry_opts = {
- :desired_exit_codes => [0,2],
- :max_retries => 3,
- # Beakers retry_on method wants the verbose value to be a string, not a bool.
- :verbose => 'true'
- }
- retry_on(master, puppet("agent -t"), retry_opts)
+ # The puppet agent run that will download the agent tarballs to the master can sometimes fail with
+ # curl errors if there is a network hiccup. Use beakers `retry_on` method to retry up to
+ # three times to avoid failing the entire test pipeline due to a network blip
+ retry_opts = {
+ :desired_exit_codes => [0,2],
+ :max_retries => 3,
+ # Beakers retry_on method wants the verbose value to be a string, not a bool.
+ :verbose => 'true'
+ }
+ retry_on(master, puppet("agent -t"), retry_opts)
+
+ # Download the agent tarballs to compile masters
+ hosts.each do |h|
+ if h['roles'].include?('compile_master')
+ retry_on(h, puppet("agent -t"), retry_opts)
+ end
+ end
+ end
+ else
+ raise "Failed to add pe_repo packages, PE Master node group is not available"
end
end
end
#Perform a Puppet Enterprise upgrade or install
@@ -596,20 +636,28 @@
install_hosts.each do |host|
if agent_only_check_needed && hosts_agent_only.include?(host) || install_via_msi?(host)
host['type'] = 'aio'
- install_puppet_agent_pe_promoted_repo_on(host, {
+ install_params = {
: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]
- })
+ :puppet_collection => host[:puppet_collection] || opts[:puppet_collection],
+ :pe_promoted_builds_url => host[:pe_promoted_builds_url] || opts[:pe_promoted_builds_url]
+ }
+ install_params.delete(:pe_promoted_builds_url) if install_params[:pe_promoted_builds_url].nil?
+ install_puppet_agent_pe_promoted_repo_on(host, install_params)
# 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)
+ if masterless
+ configure_type_defaults_on(host)
+ on host, puppet_agent('-t'), :acceptable_exit_codes => acceptable_exit_codes
+ else
+ setup_defaults_and_config_helper_on(host, master, acceptable_exit_codes)
+ end
#Windows allows frictionless installs starting with PE Davis, if frictionless we need to skip this step
elsif (host['platform'] =~ /windows/ && !(host['roles'].include?('frictionless')) || install_via_msi?(host))
opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
msi_path = "#{host['working_dir']}\\#{host['dist']}.msi"
install_msi_on(host, msi_path, {}, opts)
@@ -1539,9 +1587,37 @@
# scp conf.d over from master
scp_from(host, "#{MEEP_DATA_DIR}/conf.d", BEAKER_MEEP_TMP)
end
end
end
+
+ # Method to install just the agent nodes
+ # This method can be called only after installing PE on all other nodes
+ # including infrastructure nodes, loadbalancer, hubs and spokes
+ # PE-22051
+ # @param [Array] agent only nodes from Beaker hosts
+ # @param [Hash] opts The Beaker options hash
+ #
+ def install_agents_only_on(agentnodes, opts)
+ if( ! agentnodes.empty?)
+ configure_type_defaults_on(agentnodes)
+ agentnodes.each do |host|
+ if host['platform'] != master['platform']
+ deploy_frictionless_to_master(host)
+ end
+ install_ca_cert_on(host, opts)
+ on(host, installer_cmd(host, opts))
+ end
+ sign_certificate_for(agentnodes)
+ stop_agent_on(agentnodes, :run_in_parallel => true)
+ on agentnodes, puppet_agent('-t'), :acceptable_exit_codes => [0,2], :run_in_parallel => true
+ agentnodes.select {|agent| agent['platform'] =~ /windows/}.each do |agent|
+ client_datadir = agent.puppet['client_datadir']
+ on(agent, puppet("resource file \"#{client_datadir}\" ensure=absent force=true"))
+ end
+ end
+ end
+
end
end
end
end